Better for _me_ would be to change the current code that rewrites
characters < ' ' to leave '\0' alone if we're not supposed to be
outputting the arguments, but then toybox would match the Android
behavior (modulo the fact that we called this field NAME) rather than
the usual GNU behavior. Does anyone actually want the GNU truncating
behavior? cmd/comm/command seems such a mess that although I wouldn't
normally suggest adding new stuff, maybe just ignoring all this and
adding a NAME field isn't such a bad idea after all...
From c58a028d868c34a23070c6fcebfe0bb0abb60eff Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Sat, 31 Oct 2015 13:42:34 -0700
Subject: [PATCH] Fix the ps -o CMD vs COMM distinction.

"comm" is the command name without arguments, and "cmd" the command
line including arguments. Confusingly, "command" is a synonym for
the *latter*, not the former.

This implementation of "comm" matches the GNU ps behavior where the
names are truncated, but Android historically used the full name
from /proc/pid/cmdline instead, so this patch isn't sufficient to
let us match the Android behavior.
---
 toys/posix/ps.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index d0975de..4f39382 100644
--- a/toys/posix/ps.c
+++ b/toys/posix/ps.c
@@ -70,7 +70,8 @@ config PS
     Available -o FIELDs:
 
       ADDR   Instruction pointer
-      CMD    Command line
+      CMD    Command line (including args)
+      COMM   Command name (no args)
       ETIME  Elapsed time since process start
       F      Process flags (PF_*) from linux source file include/sched.h
              (in octal rather than hex because posix)
@@ -349,11 +350,11 @@ static int do_ps(struct dirtree *new)
         unit /= j ? 60 : 24;
       }
 
-    // COMMAND CMD
+    // COMM - command line including arguments
     // Command line limited to 2k displayable. We could dynamically malloc, but
     // it'd almost never get used, querying length of a proc file is awkward,
     // fixed buffer is nommu friendly... Wait for somebody to complain. :)
-    } else if (i==14 || i==15) {
+    } else if (i==14) {
       int fd;
 
       len = 0;
@@ -370,6 +371,11 @@ static int do_ps(struct dirtree *new)
       }
 
       if (len<1) sprintf(out, "[%.*s]", nlen, name);
+
+    // CMD - command name (without arguments)
+    } else if (i==15) {
+      sprintf(out, "%.*s", nlen, name);
+
     // %CPU
     } else if (i==18) {
       ll = (get_uptime()*sysconf(_SC_CLK_TCK)-slot[19]);
-- 
2.6.0.rc2.230.g3dd15c0

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to