---
 toys/posix/ps.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
From 7b3f113f4c172c30f4905793be64791b2a8e3a1e Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Mon, 29 Feb 2016 10:34:07 -0800
Subject: [PATCH] Fix trailing spaces on ps -o cmdline.

---
 toys/posix/ps.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index f99a216..d2ef9fc 100644
--- a/toys/posix/ps.c
+++ b/toys/posix/ps.c
@@ -673,7 +673,7 @@ static int get_ps(struct dirtree *new)
     len = sizeof(toybuf)-(buf-toybuf)-260-256*(ARRAY_LEN(fetch)-j);
     sprintf(buf, "%lld/%s", *slot, fetch[j].name);
 
-    // For cmdline we readlink instead of read contents
+    // For exe we readlink instead of read contents
     if (j==3) {
       if ((len = readlinkat(fd, buf, buf, len))>0) buf[len] = 0;
       else *buf = 0;
@@ -735,7 +735,8 @@ static int get_ps(struct dirtree *new)
         if (buf[len-1]=='\n') buf[--len] = 0;
 
         // Turn NUL to space, other low ascii to ? (in non-tty mode)
-        for (i=0; i<len; i++) {
+        // cmdline has a trailing NUL that we don't want to turn to space.
+        for (i=0; i<len-1; i++) {
           char c = buf[i];
 
           if (!c) {
-- 
2.7.0.rc3.207.g0ac5344

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

Reply via email to