ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/pack/freebsd/sysutils/psmisc/files/patch-src-pstree.c
Revision: 282
Committed: 2010-05-18T22:41:26-07:00 (15 years, 1 month ago) by douglas
Content type: text/x-diff
File size: 2074 byte(s)
Log Message:
This should be more correct/better!

File Contents

# User Rev Content
1 douglas 280 --- src/pstree.c.orig 2010-04-08 05:20:10.000000000 -0700
2     +++ src/pstree.c 2010-05-18 07:20:57.583839746 -0700
3 douglas 282 @@ -37,6 +37,9 @@
4 douglas 279 #include <term.h>
5     #include <termios.h>
6     #include <langinfo.h>
7 douglas 280 +#ifdef __FreeBSD__
8 douglas 279 +#include <limits.h>
9 douglas 280 +#endif
10 douglas 279 #include <assert.h>
11     #include <sys/types.h>
12     #include <sys/stat.h>
13 douglas 280 @@ -590,7 +594,11 @@
14 douglas 279 struct dirent *de;
15     FILE *file;
16     struct stat st;
17     +#ifdef __FreeBSD__
18     + char *path, comm[COMM_LEN + 1];
19     +#else
20     char *path, *comm;
21     +#endif
22     char *buffer;
23     size_t buffer_size;
24     char readbuf[BUFSIZ + 1];
25 douglas 280 @@ -623,7 +631,11 @@
26 douglas 279 if ((pid = (pid_t) atoi(de->d_name)) != 0) {
27     if (! (path = malloc(strlen(PROC_BASE) + strlen(de->d_name) + 10)))
28     exit(2);
29 douglas 280 +#ifdef __FreeBSD__
30     + sprintf(path, "%s/%d/status", PROC_BASE, pid);
31     +#else
32     sprintf(path, "%s/%d/stat", PROC_BASE, pid);
33     +#endif
34 douglas 279 if ((file = fopen(path, "r")) != NULL) {
35     empty = 0;
36     sprintf(path, "%s/%d", PROC_BASE, pid);
37 douglas 280 @@ -638,6 +650,29 @@
38 douglas 279 perror(path);
39     exit(1);
40     }
41     +#ifdef __FreeBSD__
42 douglas 280 + /* Read comm and ppid */
43     + if (fscanf(file, "%s %*d %d", readbuf, &ppid) == 2) {
44     + tmpptr = readbuf;
45     + size = 0;
46     + /* Unescape comm */
47     + do {
48     + if (*tmpptr == '\\')
49     + {
50     + char tmp = tmpptr[4];
51     + tmpptr[4] = 0;
52     + comm[size++] = strtol(++tmpptr, NULL, 8);
53     + tmpptr += 2;
54     + tmpptr[1] = tmp;
55     + }
56     + else
57     + comm[size++] = *tmpptr;
58     + } while (*++tmpptr);
59     + comm[size] = 0;
60     + /* Balance braces */
61     + {
62     + {
63 douglas 279 +#else
64     size = fread(readbuf, 1, BUFSIZ, file);
65     if (ferror(file) == 0) {
66     readbuf[size] = 0;
67 douglas 280 @@ -692,6 +727,7 @@
68     (void) closedir(taskdir);
69     }
70     free(taskpath);
71 douglas 279 +#endif /*__FreeBSD__*/
72 douglas 280 if (!print_args)
73     #ifdef WITH_SELINUX
74     add_proc(comm, pid, ppid, st.st_uid, NULL, 0, 0, scontext);

Properties

Name Value
svn:mime-type text/x-diff