From: Craig Small Date: Sun, 18 Nov 2007 21:47:36 +0000 (+0000) Subject: pstree patch from Marcus X-Git-Tag: v22.11~42 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=706509d6608f3b7616320a10e8b6d815d36460e8;p=psmisc pstree patch from Marcus --- diff --git a/ChangeLog b/ChangeLog index 699198e..3525d2f 100644 --- 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 diff --git a/src/pstree.c b/src/pstree.c index a85c7bc..9484b05 100644 --- a/src/pstree.c +++ b/src/pstree.c @@ -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) {