public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin/main] Cygwin: ps -f: output command line
@ 2024-02-01 11:39 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2024-02-01 11:39 UTC (permalink / raw)
  To: cygwin-cvs

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),

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-01 11:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-01 11:39 [newlib-cygwin/main] Cygwin: ps -f: output command line Corinna Vinschen

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).