Lines 1-14
Link Here
|
1 |
--- src/pstree.c.orig 2009-12-27 15:46:47.000000000 +0900 |
1 |
--- src/pstree.c.orig 2010-04-08 05:20:10.000000000 -0700 |
2 |
+++ src/pstree.c 2010-01-03 00:52:21.437862505 +0900 |
2 |
+++ src/pstree.c 2010-05-18 07:20:57.583839746 -0700 |
3 |
@@ -37,6 +37,7 @@ |
3 |
@@ -37,6 +37,10 @@ |
4 |
#include <term.h> |
4 |
#include <term.h> |
5 |
#include <termios.h> |
5 |
#include <termios.h> |
6 |
#include <langinfo.h> |
6 |
#include <langinfo.h> |
|
|
7 |
+#ifdef __FreeBSD__ |
8 |
+#include <locale.h> |
7 |
+#include <limits.h> |
9 |
+#include <limits.h> |
|
|
10 |
+#endif |
8 |
#include <assert.h> |
11 |
#include <assert.h> |
9 |
#include <sys/types.h> |
12 |
#include <sys/types.h> |
10 |
#include <sys/stat.h> |
13 |
#include <sys/stat.h> |
11 |
@@ -590,7 +591,11 @@ |
14 |
@@ -590,7 +594,11 @@ |
12 |
struct dirent *de; |
15 |
struct dirent *de; |
13 |
FILE *file; |
16 |
FILE *file; |
14 |
struct stat st; |
17 |
struct stat st; |
Lines 20-50
Link Here
|
20 |
char *buffer; |
23 |
char *buffer; |
21 |
size_t buffer_size; |
24 |
size_t buffer_size; |
22 |
char readbuf[BUFSIZ + 1]; |
25 |
char readbuf[BUFSIZ + 1]; |
23 |
@@ -623,7 +628,7 @@ |
26 |
@@ -623,7 +631,11 @@ |
24 |
if ((pid = (pid_t) atoi(de->d_name)) != 0) { |
27 |
if ((pid = (pid_t) atoi(de->d_name)) != 0) { |
25 |
if (! (path = malloc(strlen(PROC_BASE) + strlen(de->d_name) + 10))) |
28 |
if (! (path = malloc(strlen(PROC_BASE) + strlen(de->d_name) + 10))) |
26 |
exit(2); |
29 |
exit(2); |
27 |
- sprintf(path, "%s/%d/stat", PROC_BASE, pid); |
30 |
+#ifdef __FreeBSD__ |
28 |
+ sprintf (path, "%s/%d/status", PROC_BASE, pid); |
31 |
+ sprintf(path, "%s/%d/status", PROC_BASE, pid); |
|
|
32 |
+#else |
33 |
sprintf(path, "%s/%d/stat", PROC_BASE, pid); |
34 |
+#endif |
29 |
if ((file = fopen(path, "r")) != NULL) { |
35 |
if ((file = fopen(path, "r")) != NULL) { |
30 |
empty = 0; |
36 |
empty = 0; |
31 |
sprintf(path, "%s/%d", PROC_BASE, pid); |
37 |
sprintf(path, "%s/%d", PROC_BASE, pid); |
32 |
@@ -638,6 +643,10 @@ |
38 |
@@ -638,6 +650,29 @@ |
33 |
perror(path); |
39 |
perror(path); |
34 |
exit(1); |
40 |
exit(1); |
35 |
} |
41 |
} |
36 |
+#ifdef __FreeBSD__ |
42 |
+#ifdef __FreeBSD__ |
37 |
+ if (fscanf(file, "%s %*d %d", comm, &ppid) == 2) |
43 |
+ /* Read comm and ppid */ |
38 |
+ add_proc(comm, pid, ppid, st.st_uid, NULL, 0, 0); |
44 |
+ if (fscanf(file, "%s %*d %d", readbuf, &ppid) == 2) { |
|
|
45 |
+ tmpptr = readbuf; |
46 |
+ size = 0; |
47 |
+ /* Unescape comm */ |
48 |
+ do { |
49 |
+ if (*tmpptr == '\\') |
50 |
+ { |
51 |
+ char tmp = tmpptr[4]; |
52 |
+ tmpptr[4] = 0; |
53 |
+ comm[size++] = strtol(++tmpptr, NULL, 8); |
54 |
+ tmpptr += 2; |
55 |
+ tmpptr[1] = tmp; |
56 |
+ } |
57 |
+ else |
58 |
+ comm[size++] = *tmpptr; |
59 |
+ } while (*++tmpptr); |
60 |
+ comm[size] = 0; |
61 |
+ /* Balance braces */ |
62 |
+ { |
63 |
+ { |
39 |
+#else |
64 |
+#else |
40 |
size = fread(readbuf, 1, BUFSIZ, file); |
65 |
size = fread(readbuf, 1, BUFSIZ, file); |
41 |
if (ferror(file) == 0) { |
66 |
if (ferror(file) == 0) { |
42 |
readbuf[size] = 0; |
67 |
readbuf[size] = 0; |
43 |
@@ -725,6 +734,7 @@ |
68 |
@@ -692,6 +727,7 @@ |
44 |
} |
69 |
(void) closedir(taskdir); |
45 |
} |
70 |
} |
46 |
} |
71 |
free(taskpath); |
47 |
+#endif /*__FreeBSD__*/ |
72 |
+#endif /*__FreeBSD__*/ |
48 |
(void) fclose(file); |
73 |
if (!print_args) |
49 |
} |
74 |
#ifdef WITH_SELINUX |
50 |
free(path); |
75 |
add_proc(comm, pid, ppid, st.st_uid, NULL, 0, 0, scontext); |
|
|
76 |
@@ -860,6 +896,10 @@ |
77 |
* command-line options, if given. |
78 |
*/ |
79 |
|
80 |
+#ifdef __FreeBSD__ |
81 |
+ /* Actually set the locale because nl_langinfo won't do it. */ |
82 |
+ setlocale(LC_CTYPE, ""); |
83 |
+#endif |
84 |
if (isatty(1) && !strcmp(nl_langinfo(CODESET), "UTF-8")) { |
85 |
/* Use UTF-8 symbols if the locale's character set is UTF-8. */ |
86 |
sym = &sym_utf; |