| @@ -1,17 +1,20 @@ | | | @@ -1,17 +1,20 @@ |
1 | $NetBSD: patch-af,v 1.6 2014/09/23 22:18:21 jperkin Exp $ | | 1 | $NetBSD: patch-af,v 1.7 2020/10/06 00:19:05 mcf Exp $ |
2 | | | 2 | |
3 | Need limits.h for PATH_MAX | | 3 | Need limits.h for PATH_MAX |
4 | | | 4 | |
| | | 5 | Fix sscanf usage bug on musl libc and uclibc (upstream commit |
| | | 6 | https://gitlab.com/psmisc/psmisc/-/commit/ca2b176889729a7347bd95b832b9a5bb39fec229) |
| | | 7 | |
5 | --- src/pstree.c.orig 2000-12-18 05:59:23.000000000 +0000 | | 8 | --- src/pstree.c.orig 2000-12-18 05:59:23.000000000 +0000 |
6 | +++ src/pstree.c | | 9 | +++ src/pstree.c |
7 | @@ -15,19 +15,22 @@ | | 10 | @@ -15,19 +15,22 @@ |
8 | #include <getopt.h> | | 11 | #include <getopt.h> |
9 | #include <pwd.h> | | 12 | #include <pwd.h> |
10 | #include <dirent.h> | | 13 | #include <dirent.h> |
11 | +#include <limits.h> | | 14 | +#include <limits.h> |
12 | #include <termios.h> | | 15 | #include <termios.h> |
13 | +#ifdef HAVE_TERMCAP_H | | 16 | +#ifdef HAVE_TERMCAP_H |
14 | #include <termcap.h> | | 17 | #include <termcap.h> |
15 | +#endif | | 18 | +#endif |
16 | #include <sys/types.h> | | 19 | #include <sys/types.h> |
17 | #include <sys/stat.h> | | 20 | #include <sys/stat.h> |
| @@ -55,50 +58,61 @@ Need limits.h for PATH_MAX | | | @@ -55,50 +58,61 @@ Need limits.h for PATH_MAX |
55 | + if (current->highlight && (tmp = tgetstr ("me", &pbuf))) | | 58 | + if (current->highlight && (tmp = tgetstr ("me", &pbuf))) |
56 | tputs (tmp, 1, putchar); | | 59 | tputs (tmp, 1, putchar); |
57 | if (print_args) | | 60 | if (print_args) |
58 | { | | 61 | { |
59 | @@ -504,7 +510,7 @@ read_proc (void) | | 62 | @@ -504,7 +510,7 @@ read_proc (void) |
60 | while ((de = readdir (dir)) != NULL) | | 63 | while ((de = readdir (dir)) != NULL) |
61 | if ((pid = atoi (de->d_name)) != 0) | | 64 | if ((pid = atoi (de->d_name)) != 0) |
62 | { | | 65 | { |
63 | - sprintf (path, "%s/%d/stat", PROC_BASE, pid); | | 66 | - sprintf (path, "%s/%d/stat", PROC_BASE, pid); |
64 | + sprintf (path, "%s/%d/%s", PROC_BASE, pid, STATUS_FILE); | | 67 | + sprintf (path, "%s/%d/%s", PROC_BASE, pid, STATUS_FILE); |
65 | if ((file = fopen (path, "r")) != NULL) | | 68 | if ((file = fopen (path, "r")) != NULL) |
66 | { | | 69 | { |
67 | empty = 0; | | 70 | empty = 0; |
68 | @@ -513,6 +519,10 @@ read_proc (void) | | 71 | @@ -513,16 +519,19 @@ read_proc (void) |
69 | perror (path); | | 72 | perror (path); |
70 | exit (1); | | 73 | exit (1); |
71 | } | | 74 | } |
72 | +#ifdef BSD_44_PROCFS | | 75 | +#ifdef BSD_44_PROCFS |
73 | + if (fscanf(file, "%s %*d %d", comm, &ppid) == 2) | | 76 | + if (fscanf(file, "%s %*d %d", comm, &ppid) == 2) |
74 | + { { { | | 77 | + { { { |
75 | +#else | | 78 | +#else |
76 | fread(readbuf, BUFSIZ, 1, file) ; | | 79 | fread(readbuf, BUFSIZ, 1, file) ; |
77 | if (ferror(file) == 0) | | 80 | if (ferror(file) == 0) |
78 | { | | 81 | { |
79 | @@ -532,11 +542,12 @@ read_proc (void) | | 82 | memset(comm, '\0', COMM_LEN+1); |
| | | 83 | tmpptr = strrchr(readbuf, ')'); /* find last ) */ |
| | | 84 | - *tmpptr = '\0'; |
| | | 85 | /* We now have readbuf with pid and cmd, and tmpptr+2 |
| | | 86 | * with the rest */ |
| | | 87 | /*printf("readbuf: %s\n", readbuf);*/ |
| | | 88 | - if (sscanf(readbuf, "%*d (%15c", comm) == 1) |
| | | 89 | + if (sscanf(readbuf, "%*d (%15[^)]", comm) == 1) |
| | | 90 | { |
| | | 91 | /*printf("tmpptr: %s\n", tmpptr+2);*/ |
| | | 92 | if (sscanf(tmpptr+2, "%*c %d", &ppid) == 1) |
| | | 93 | @@ -532,11 +541,12 @@ read_proc (void) |
80 | (file, "%d (%s) %c %d", &dummy, comm, (char *) &dummy, | | 94 | (file, "%d (%s) %c %d", &dummy, comm, (char *) &dummy, |
81 | &ppid) == 4) | | 95 | &ppid) == 4) |
82 | */ | | 96 | */ |
83 | +#endif | | 97 | +#endif |
84 | if (!print_args) | | 98 | if (!print_args) |
85 | add_proc (comm, pid, ppid, st.st_uid, NULL, 0); | | 99 | add_proc (comm, pid, ppid, st.st_uid, NULL, 0); |
86 | else | | 100 | else |
87 | { | | 101 | { |
88 | - sprintf (path, "%s/%d/cmdline", PROC_BASE, pid); | | 102 | - sprintf (path, "%s/%d/cmdline", PROC_BASE, pid); |
89 | + sprintf (path, "%s/%d/%s", PROC_BASE, pid, CMDLINE_FILE); | | 103 | + sprintf (path, "%s/%d/%s", PROC_BASE, pid, CMDLINE_FILE); |
90 | if ((fd = open (path, O_RDONLY)) < 0) | | 104 | if ((fd = open (path, O_RDONLY)) < 0) |
91 | { | | 105 | { |
92 | perror (path); | | 106 | perror (path); |
93 | @@ -641,7 +652,11 @@ main (int argc, char **argv) | | 107 | @@ -641,7 +651,11 @@ main (int argc, char **argv) |
94 | switch (c) | | 108 | switch (c) |
95 | { | | 109 | { |
96 | case 'a': | | 110 | case 'a': |
97 | +#if defined(BSD_44_PROCFS) && !defined(BSD_PROCFS_CMDLINE) | | 111 | +#if defined(BSD_44_PROCFS) && !defined(BSD_PROCFS_CMDLINE) |
98 | + print_args = 0; | | 112 | + print_args = 0; |
99 | +#else | | 113 | +#else |
100 | print_args = 1; | | 114 | print_args = 1; |
101 | +#endif | | 115 | +#endif |
102 | break; | | 116 | break; |
103 | case 'c': | | 117 | case 'c': |
104 | compact = 0; | | 118 | compact = 0; |