]> granicus.if.org Git - psmisc/commitdiff
pstree patch from Marcus
authorCraig Small <csmall@users.sourceforge.net>
Sun, 18 Nov 2007 21:47:36 +0000 (21:47 +0000)
committerCraig Small <csmall@users.sourceforge.net>
Sun, 18 Nov 2007 21:47:36 +0000 (21:47 +0000)
ChangeLog
src/pstree.c

index 699198ee988d2ce8ea08213cf83afc6236c60d9e..3525d2f05758d99d84631db134ea3205530459c1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 Changes in ??
 ==============
+2007-11-19 Craig Small
+       * Patch from Marcus Watts for better comm handling in pstree
+
 2007-11-13 Craig Small
        * Updated French and German po files
        * Fuser -m detects more open sockets SF patch #1728412 Thnks marienz
index a85c7bc6373c52c497bcdcee306b85c204877968..9484b05c404566adf5a294403fc70751e4c60b51 100644 (file)
@@ -560,7 +560,7 @@ read_proc (void)
   struct dirent *de;
   FILE *file;
   struct stat st;
-  char *path, comm[COMM_LEN + 1];
+  char *path, *comm;
   char *buffer;
   char readbuf[BUFSIZ+1];
   char *tmpptr;
@@ -608,16 +608,18 @@ read_proc (void)
                perror (path);
                exit (1);
              }
-            fread(readbuf, BUFSIZ, 1, file) ;
+            size = fread(readbuf, 1, BUFSIZ, file) ;
             if (ferror(file) == 0) 
             {
-              memset(comm, '\0', COMM_LEN+1);
-              tmpptr = strrchr(readbuf, ')'); /* find last ) */
+             readbuf[size] = 0;
+              /*printf("readbuf: %s\n", readbuf);*/
+               /* commands may have spaces or ) in them.
+                * so don't trust anything from the ( to the last ) */
+             if ((comm = strchr(readbuf, '('))
+               && (tmpptr = strrchr(comm, ')'))) {
+               ++comm; *tmpptr = 0;
               /* We now have readbuf with pid and cmd, and tmpptr+2
                * with the rest */
-              /*printf("readbuf: %s\n", readbuf);*/
-              if (sscanf(readbuf, "%*d (%15[^)]", comm) == 1)
-              {
                 /*printf("tmpptr: %s\n", tmpptr+2);*/
                 if (sscanf(tmpptr+2, "%*c %d", &ppid) == 1)
                 {