1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
--- src/pstree.c.orig Fri Nov 25 23:14:48 2005
+++ src/pstree.c Thu Jan 5 23:34:36 2006
@@ -590,7 +590,7 @@
{
if (!(path = malloc (strlen (PROC_BASE) + strlen (de->d_name) + 10)))
exit (2);
- sprintf (path, "%s/%d/stat", PROC_BASE, pid);
+ sprintf (path, "%s/%d/status", PROC_BASE, pid);
if ((file = fopen (path, "r")) != NULL)
{
empty = 0;
@@ -608,95 +608,8 @@
perror (path);
exit (1);
}
- fread(readbuf, BUFSIZ, 1, file) ;
- if (ferror(file) == 0)
- {
- memset(comm, '\0', COMM_LEN+1);
- tmpptr = strrchr(readbuf, ')'); /* find last ) */
- /* We now have readbuf with pid and cmd, and tmpptr+2
- * with the rest */
- /*printf("readbuf: %s\n", readbuf);*/
- if (sscanf(readbuf, "%*d (%15[^)]", comm) == 1)
- {
- /*printf("tmpptr: %s\n", tmpptr+2);*/
- if (sscanf(tmpptr+2, "%*c %d", &ppid) == 1)
- {
-/*
- if (fscanf
- (file, "%d (%s) %c %d", &dummy, comm, (char *) &dummy,
- &ppid) == 4)
- */
- {
- DIR *taskdir;
- struct dirent *dt;
- char *taskpath;
- char *threadname;
- int thread;
-
- if (!(taskpath = malloc(strlen(path) + 10))) {
- exit (2);
- }
- sprintf (taskpath, "%s/task", path);
-
- if ((taskdir=opendir(taskpath))!=0) {
- /* if we have this dir, we're on 2.6 */
- if (!(threadname = malloc(strlen(comm) + 3))) {
- exit (2);
- }
- sprintf(threadname,"{%s}",comm);
- while ((dt = readdir(taskdir)) != NULL) {
- if ((thread=atoi(dt->d_name)) !=0) {
- if (thread != pid) {
-#ifdef WITH_SELINUX
- if (print_args)
- add_proc(threadname, thread, pid, st.st_uid, threadname, strlen(threadname)+1, scontext);
- else
- add_proc(threadname, thread, pid, st.st_uid, NULL, 0, scontext);
-#else /*WITH_SELINUX*/
- if (print_args)
- add_proc(threadname, thread, pid, st.st_uid, threadname, strlen(threadname)+1);
- else
- add_proc(threadname, thread, pid, st.st_uid, NULL, 0);
-#endif /*WITH_SELINUX*/
- }
- }
- }
- free(threadname);
- (void) closedir(taskdir);
- }
- free(taskpath);
- }
-
- if (!print_args)
-#ifdef WITH_SELINUX
- add_proc(comm, pid, ppid, st.st_uid, NULL, 0, scontext);
-#else /*WITH_SELINUX*/
- add_proc (comm, pid, ppid, st.st_uid, NULL, 0);
-#endif /*WITH_SELINUX*/
- else
- {
- sprintf (path, "%s/%d/cmdline", PROC_BASE, pid);
- if ((fd = open (path, O_RDONLY)) < 0)
- {
- perror (path);
- exit (1);
- }
- if ((size = read (fd, buffer, (size_t) output_width)) < 0)
- {
- perror (path);
- exit (1);
- }
- (void) close (fd);
- if (size)
- buffer[size++] = 0;
-#ifdef WITH_SELINUX
- add_proc(comm, pid, ppid, st.st_uid, buffer, size, scontext);
-#else /*WITH_SELINUX*/
- add_proc (comm, pid, ppid, st.st_uid, buffer, size);
-#endif /*WITH_SELINUX*/
- }
- }
- }
+ if (fscanf(file, "%s %*d %d", comm, &ppid) == 2) {
+ add_proc(comm,pid,ppid,st.st_uid,NULL,0);
}
(void) fclose (file);
}
|