public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: Correct /proc/*/stat for processes without ctty
Date: Thu, 10 Nov 2022 09:09:14 +0000 (GMT)	[thread overview]
Message-ID: <20221110090914.3B67C3858D20@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=59b8ee7d7066b9a3f39e1c765d0cecb5d9bc07fd

commit 59b8ee7d7066b9a3f39e1c765d0cecb5d9bc07fd
Author: Andy Koppe <andy.koppe@gmail.com>
Date:   Wed Nov 9 20:34:30 2022 +0000

    Cygwin: Correct /proc/*/stat for processes without ctty
    
    Report 0 instead of 268435455 (i.e. 0xFFFFFFF) in the tty field of
    /proc/*/stat for processes without a controlling terminal. This is what
    the procps utility expects when selecting or excluding such processes.

Diff:
---
 winsup/cygwin/fhandler/process.cc | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/winsup/cygwin/fhandler/process.cc b/winsup/cygwin/fhandler/process.cc
index a8c17f1b0..b0aef2ebe 100644
--- a/winsup/cygwin/fhandler/process.cc
+++ b/winsup/cygwin/fhandler/process.cc
@@ -1092,9 +1092,11 @@ format_process_stat (void *data, char *&destbuf)
   int nice = 0;
 /* ctty maj is 31:16, min is 15:0; tty_nr s/b maj 15:8, min 31:20, 7:0;
    maj is 31:16 >> 16 & fff << 8; min is 15:0 >> 8 & ff << 20 | & ff */
-  int tty_nr =    (((p->ctty >>  8) & 0xff)  << 20)
-		| (((p->ctty >> 16) & 0xfff) <<  8)
-		|   (p->ctty        & 0xff);
+  int tty_nr = 0;
+  if (p->ctty > 0)
+    tty_nr =   (((p->ctty >>  8) & 0xff)  << 20)
+	     | (((p->ctty >> 16) & 0xfff) <<  8)
+	     |   (p->ctty        & 0xff);
 
   if (p->process_state & PID_EXITED)
     strcpy (cmd, "<defunct>");

                 reply	other threads:[~2022-11-10  9:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221110090914.3B67C3858D20@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).