]> granicus.if.org Git - procps-ng/commitdiff
library: once again properly ignore a final empty cgroup
authorJim Warner <james.warner@comcast.net>
Sun, 11 Dec 2011 18:00:50 +0000 (12:00 -0600)
committerCraig Small <csmall@enc.com.au>
Wed, 14 Dec 2011 12:02:51 +0000 (23:02 +1100)
Commit a5881b5a4e5056d13906ce6128f6aa180d67d60e, addressing
command lines with a trailing space, produced an undesirable
side effect in the fill_cgroup_cvt() function.

This patch restores correct cgroup behavior while still
producing command lines with no trailing space.

proc/readproc.c

index 57870ef3ce19f804f98fc3919164c2d9447fc800..bbfd6292b3ea59d3b8df6bfc2592a9b82c635ac2 100644 (file)
@@ -611,9 +611,10 @@ static int read_unvectored(char *restrict const dst, unsigned sz, const char* wh
     }
     close(fd);
     if(n){
-        int i=n-1;
+        int i=n;
         while(i--)
             if(dst[i]=='\n' || dst[i]=='\0') dst[i]=sep;
+        if(dst[n-1]==' ') dst[n-1]='\0';
     }
     dst[n] = '\0';
     return n;