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 |
|
|
@@ -37,6 +37,10 @@ |
4 |
douglas |
279 |
#include <term.h> |
5 |
|
|
#include <termios.h> |
6 |
|
|
#include <langinfo.h> |
7 |
douglas |
280 |
+#ifdef __FreeBSD__ |
8 |
|
|
+#include <locale.h> |
9 |
douglas |
279 |
+#include <limits.h> |
10 |
douglas |
280 |
+#endif |
11 |
douglas |
279 |
#include <assert.h> |
12 |
|
|
#include <sys/types.h> |
13 |
|
|
#include <sys/stat.h> |
14 |
douglas |
280 |
@@ -590,7 +594,11 @@ |
15 |
douglas |
279 |
struct dirent *de; |
16 |
|
|
FILE *file; |
17 |
|
|
struct stat st; |
18 |
|
|
+#ifdef __FreeBSD__ |
19 |
|
|
+ char *path, comm[COMM_LEN + 1]; |
20 |
|
|
+#else |
21 |
|
|
char *path, *comm; |
22 |
|
|
+#endif |
23 |
|
|
char *buffer; |
24 |
|
|
size_t buffer_size; |
25 |
|
|
char readbuf[BUFSIZ + 1]; |
26 |
douglas |
280 |
@@ -623,7 +631,11 @@ |
27 |
douglas |
279 |
if ((pid = (pid_t) atoi(de->d_name)) != 0) { |
28 |
|
|
if (! (path = malloc(strlen(PROC_BASE) + strlen(de->d_name) + 10))) |
29 |
|
|
exit(2); |
30 |
douglas |
280 |
+#ifdef __FreeBSD__ |
31 |
|
|
+ sprintf(path, "%s/%d/status", PROC_BASE, pid); |
32 |
|
|
+#else |
33 |
|
|
sprintf(path, "%s/%d/stat", PROC_BASE, pid); |
34 |
|
|
+#endif |
35 |
douglas |
279 |
if ((file = fopen(path, "r")) != NULL) { |
36 |
|
|
empty = 0; |
37 |
|
|
sprintf(path, "%s/%d", PROC_BASE, pid); |
38 |
douglas |
280 |
@@ -638,6 +650,29 @@ |
39 |
douglas |
279 |
perror(path); |
40 |
|
|
exit(1); |
41 |
|
|
} |
42 |
|
|
+#ifdef __FreeBSD__ |
43 |
douglas |
280 |
+ /* Read comm and ppid */ |
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 |
|
|
+ { |
64 |
douglas |
279 |
+#else |
65 |
|
|
size = fread(readbuf, 1, BUFSIZ, file); |
66 |
|
|
if (ferror(file) == 0) { |
67 |
|
|
readbuf[size] = 0; |
68 |
douglas |
280 |
@@ -692,6 +727,7 @@ |
69 |
|
|
(void) closedir(taskdir); |
70 |
|
|
} |
71 |
|
|
free(taskpath); |
72 |
douglas |
279 |
+#endif /*__FreeBSD__*/ |
73 |
douglas |
280 |
if (!print_args) |
74 |
|
|
#ifdef WITH_SELINUX |
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; |