| @@ -1,102 +1,104 @@ | | | @@ -1,102 +1,104 @@ |
1 | $NetBSD: patch-af,v 1.5 2013/12/13 09:58:58 jperkin Exp $ | | 1 | $NetBSD: patch-af,v 1.6 2014/09/23 22:18:21 jperkin Exp $ |
2 | | | 2 | |
3 | Need limits.h for PATH_MAX | | 3 | Need limits.h for PATH_MAX |
4 | | | 4 | |
5 | --- src/pstree.c.orig 2000-12-18 05:59:23.000000000 +0000 | | 5 | --- src/pstree.c.orig 2000-12-18 05:59:23.000000000 +0000 |
6 | +++ src/pstree.c | | 6 | +++ src/pstree.c |
7 | @@ -15,6 +15,7 @@ | | 7 | @@ -15,19 +15,22 @@ |
8 | #include <getopt.h> | | 8 | #include <getopt.h> |
9 | #include <pwd.h> | | 9 | #include <pwd.h> |
10 | #include <dirent.h> | | 10 | #include <dirent.h> |
11 | +#include <limits.h> | | 11 | +#include <limits.h> |
12 | #include <termios.h> | | 12 | #include <termios.h> |
| | | 13 | +#ifdef HAVE_TERMCAP_H |
13 | #include <termcap.h> | | 14 | #include <termcap.h> |
| | | 15 | +#endif |
14 | #include <sys/types.h> | | 16 | #include <sys/types.h> |
15 | @@ -22,12 +23,12 @@ | | 17 | #include <sys/stat.h> |
16 | #include <sys/ioctl.h> | | 18 | #include <sys/ioctl.h> |
17 | | | 19 | |
18 | #include "comm.h" | | 20 | #include "comm.h" |
19 | +#include "procfs.h" | | 21 | +#include "procfs.h" |
20 | | | 22 | |
21 | | | 23 | |
22 | #ifndef MAX_DEPTH | | 24 | #ifndef MAX_DEPTH |
23 | #define MAX_DEPTH 100 | | 25 | #define MAX_DEPTH 100 |
24 | #endif | | 26 | #endif |
25 | -#define PROC_BASE "/proc" | | 27 | -#define PROC_BASE "/proc" |
26 | | | 28 | |
27 | /* UTF-8 defines by Johan Myreen */ | | 29 | /* UTF-8 defines by Johan Myreen */ |
28 | #define UTF_V "\342\224\202\277" /* Vertical line drawing char */ | | 30 | #define UTF_V "\342\224\202\277" /* Vertical line drawing char */ |
29 | @@ -303,6 +304,7 @@ dump_tree (PROC * current, int level, in | | 31 | @@ -303,6 +306,7 @@ dump_tree (PROC * current, int level, in |
30 | const struct passwd *pw; | | 32 | const struct passwd *pw; |
31 | int lvl, i, add, offset, len, swapped, info, count, comm_len, first; | | 33 | int lvl, i, add, offset, len, swapped, info, count, comm_len, first; |
32 | const char *tmp, *here; | | 34 | const char *tmp, *here; |
33 | + char tbuf[1024], *pbuf; | | 35 | + char tbuf[1024], *pbuf; |
34 | char comm_tmp[5]; | | 36 | char comm_tmp[5]; |
35 | | | 37 | |
36 | if (!current) | | 38 | if (!current) |
37 | @@ -327,7 +329,8 @@ dump_tree (PROC * current, int level, in | | 39 | @@ -327,7 +331,8 @@ dump_tree (PROC * current, int level, in |
38 | add = out_int (rep) + 2; | | 40 | add = out_int (rep) + 2; |
39 | out_string ("*["); | | 41 | out_string ("*["); |
40 | } | | 42 | } |
41 | - if (current->highlight && (tmp = tgetstr ("md", NULL))) | | 43 | - if (current->highlight && (tmp = tgetstr ("md", NULL))) |
42 | + pbuf = tbuf; | | 44 | + pbuf = tbuf; |
43 | + if (current->highlight && (tmp = tgetstr ("md", &pbuf))) | | 45 | + if (current->highlight && (tmp = tgetstr ("md", &pbuf))) |
44 | tputs (tmp, 1, putchar); | | 46 | tputs (tmp, 1, putchar); |
45 | if ((swapped = print_args) && current->argc < 0) | | 47 | if ((swapped = print_args) && current->argc < 0) |
46 | out_char ('('); | | 48 | out_char ('('); |
47 | @@ -366,7 +369,8 @@ dump_tree (PROC * current, int level, in | | 49 | @@ -366,7 +371,8 @@ dump_tree (PROC * current, int level, in |
48 | } | | 50 | } |
49 | if (info || swapped) | | 51 | if (info || swapped) |
50 | out_char (')'); | | 52 | out_char (')'); |
51 | - if (current->highlight && (tmp = tgetstr ("me", NULL))) | | 53 | - if (current->highlight && (tmp = tgetstr ("me", NULL))) |
52 | + pbuf = tbuf; | | 54 | + pbuf = tbuf; |
53 | + if (current->highlight && (tmp = tgetstr ("me", &pbuf))) | | 55 | + if (current->highlight && (tmp = tgetstr ("me", &pbuf))) |
54 | tputs (tmp, 1, putchar); | | 56 | tputs (tmp, 1, putchar); |
55 | if (print_args) | | 57 | if (print_args) |
56 | { | | 58 | { |
57 | @@ -504,7 +508,7 @@ read_proc (void) | | 59 | @@ -504,7 +510,7 @@ read_proc (void) |
58 | while ((de = readdir (dir)) != NULL) | | 60 | while ((de = readdir (dir)) != NULL) |
59 | if ((pid = atoi (de->d_name)) != 0) | | 61 | if ((pid = atoi (de->d_name)) != 0) |
60 | { | | 62 | { |
61 | - sprintf (path, "%s/%d/stat", PROC_BASE, pid); | | 63 | - sprintf (path, "%s/%d/stat", PROC_BASE, pid); |
62 | + sprintf (path, "%s/%d/%s", PROC_BASE, pid, STATUS_FILE); | | 64 | + sprintf (path, "%s/%d/%s", PROC_BASE, pid, STATUS_FILE); |
63 | if ((file = fopen (path, "r")) != NULL) | | 65 | if ((file = fopen (path, "r")) != NULL) |
64 | { | | 66 | { |
65 | empty = 0; | | 67 | empty = 0; |
66 | @@ -513,6 +517,10 @@ read_proc (void) | | 68 | @@ -513,6 +519,10 @@ read_proc (void) |
67 | perror (path); | | 69 | perror (path); |
68 | exit (1); | | 70 | exit (1); |
69 | } | | 71 | } |
70 | +#ifdef BSD_44_PROCFS | | 72 | +#ifdef BSD_44_PROCFS |
71 | + if (fscanf(file, "%s %*d %d", comm, &ppid) == 2) | | 73 | + if (fscanf(file, "%s %*d %d", comm, &ppid) == 2) |
72 | + { { { | | 74 | + { { { |
73 | +#else | | 75 | +#else |
74 | fread(readbuf, BUFSIZ, 1, file) ; | | 76 | fread(readbuf, BUFSIZ, 1, file) ; |
75 | if (ferror(file) == 0) | | 77 | if (ferror(file) == 0) |
76 | { | | 78 | { |
77 | @@ -532,11 +540,12 @@ read_proc (void) | | 79 | @@ -532,11 +542,12 @@ read_proc (void) |
78 | (file, "%d (%s) %c %d", &dummy, comm, (char *) &dummy, | | 80 | (file, "%d (%s) %c %d", &dummy, comm, (char *) &dummy, |
79 | &ppid) == 4) | | 81 | &ppid) == 4) |
80 | */ | | 82 | */ |
81 | +#endif | | 83 | +#endif |
82 | if (!print_args) | | 84 | if (!print_args) |
83 | add_proc (comm, pid, ppid, st.st_uid, NULL, 0); | | 85 | add_proc (comm, pid, ppid, st.st_uid, NULL, 0); |
84 | else | | 86 | else |
85 | { | | 87 | { |
86 | - sprintf (path, "%s/%d/cmdline", PROC_BASE, pid); | | 88 | - sprintf (path, "%s/%d/cmdline", PROC_BASE, pid); |
87 | + sprintf (path, "%s/%d/%s", PROC_BASE, pid, CMDLINE_FILE); | | 89 | + sprintf (path, "%s/%d/%s", PROC_BASE, pid, CMDLINE_FILE); |
88 | if ((fd = open (path, O_RDONLY)) < 0) | | 90 | if ((fd = open (path, O_RDONLY)) < 0) |
89 | { | | 91 | { |
90 | perror (path); | | 92 | perror (path); |
91 | @@ -641,7 +650,11 @@ main (int argc, char **argv) | | 93 | @@ -641,7 +652,11 @@ main (int argc, char **argv) |
92 | switch (c) | | 94 | switch (c) |
93 | { | | 95 | { |
94 | case 'a': | | 96 | case 'a': |
95 | +#if defined(BSD_44_PROCFS) && !defined(BSD_PROCFS_CMDLINE) | | 97 | +#if defined(BSD_44_PROCFS) && !defined(BSD_PROCFS_CMDLINE) |
96 | + print_args = 0; | | 98 | + print_args = 0; |
97 | +#else | | 99 | +#else |
98 | print_args = 1; | | 100 | print_args = 1; |
99 | +#endif | | 101 | +#endif |
100 | break; | | 102 | break; |
101 | case 'c': | | 103 | case 'c': |
102 | compact = 0; | | 104 | compact = 0; |