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/main] Cygwin: ps -f: output command line
Date: Thu,  1 Feb 2024 11:39:50 +0000 (GMT)	[thread overview]
Message-ID: <20240201113950.C39D538582A5@sourceware.org> (raw)

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

commit 1ce9756ee61e8dff5e3319851e14ebf310a0bdd8
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Tue Jan 30 20:49:20 2024 +0100
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Wed Jan 31 20:11:58 2024 +0100

    Cygwin: ps -f: output command line
    
    So far ps(1) always prints the full path of the executable under
    the COMMAND heading.
    
    With -f, print the command line instead.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/release/3.6.0 |  3 +++
 winsup/utils/ps.cc          | 17 +++++++++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/winsup/cygwin/release/3.6.0 b/winsup/cygwin/release/3.6.0
index f7754bd19417..5536d39a3eff 100644
--- a/winsup/cygwin/release/3.6.0
+++ b/winsup/cygwin/release/3.6.0
@@ -8,3 +8,6 @@ What's new:
 
 What changed:
 -------------
+
+- ps -f now prints the commandline rather than the full path to the
+  executable.
diff --git a/winsup/utils/ps.cc b/winsup/utils/ps.cc
index 982183c5d0f2..3bc8afed4062 100644
--- a/winsup/utils/ps.cc
+++ b/winsup/utils/ps.cc
@@ -357,6 +357,7 @@ main (int argc, char *argv[])
 
       char uname[128];
       char ttyname[9];
+      char *cmdline = NULL;
 
       if (fflag)
 	{
@@ -369,13 +370,25 @@ main (int argc, char *argv[])
 	    sprintf (uname, "%u", (unsigned)
 		     (p->version >= EXTERNAL_PINFO_VERSION_32_BIT ?
 		      p->uid32 : p->uid));
+
+	  cmdline = (char *) cygwin_internal (CW_CMDLINE_ALLOC, p->pid);
+	  if (cmdline) /* Replace \0 with spaces */
+	    {
+	      char *p = cmdline;
+	      while (p && *p)
+		if ((p = strchr (p, '\0')))
+		  *p++ = ' ';
+	    }
 	}
 
       if (sflag)
 	printf (dfmt, p->pid, ttynam (p->ctty, ttyname), start_time (p), pname);
       else if (fflag)
-	printf (ffmt, uname, p->pid, p->ppid, ttynam (p->ctty, ttyname),
-		start_time (p), pname);
+	{
+	  printf (ffmt, uname, p->pid, p->ppid, ttynam (p->ctty, ttyname),
+		  start_time (p), cmdline ?: pname);
+	  free (cmdline);
+	}
       else if (lflag)
 	printf (lfmt, status, p->pid, p->ppid, p->pgid,
 		p->dwProcessId, ttynam (p->ctty, ttyname),

                 reply	other threads:[~2024-02-01 11:39 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=20240201113950.C39D538582A5@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).