1 diff -up lsof_4.81-rh/dialects/linux/dproc.c.kzak lsof_4.81-rh/dialects/linux/dproc.c
2 --- lsof_4.81-rh/dialects/linux/dproc.c.kzak 2008-10-21 18:17:25.000000000 +0200
3 +++ lsof_4.81-rh/dialects/linux/dproc.c 2008-12-02 10:54:54.000000000 +0100
4 @@ -89,7 +89,8 @@ _PROTOTYPE(static void process_proc_map,
5 _PROTOTYPE(static int process_id,(char *idp, int idpl, char *cmd, UID_ARG uid,
6 int pid, int ppid, int pgid));
7 _PROTOTYPE(static int statEx,(char *p, struct stat *s, int *ss));
9 +_PROTOTYPE(static int get_other_thread,(int pid, char **tid));
12 #if defined(HASSELINUX)
13 _PROTOTYPE(static int cmp_cntx_eq,(char *pcntx, char *ucntx));
14 @@ -159,6 +160,7 @@ gather_proc_info()
17 int lwp, n, nl, pgid, pid, ppid, rv, tx;
19 static char *lwppath = (char *)NULL;
20 static int lwppathl = 0;
21 static char *path = (char *)NULL;
22 @@ -252,6 +254,13 @@ gather_proc_info()
23 while ((dp = readdir(ps))) {
24 if (nm2id(dp->d_name, &pid, &n))
28 + if (get_other_thread(pid, &tid) < 0)
31 + n += sizeof("task/") + strlen(tid);
34 * Build path to PID's directory.
36 @@ -265,7 +274,14 @@ gather_proc_info()
40 - (void) snpf(pidpath + pidx, pidpathl - pidx, "%s/", dp->d_name);
42 + /* /proc/<pid> is useless (zombie), we have to use /proc/<pid>/task/<tid>
43 + * where is still running thread
45 + (void) snpf(pidpath + pidx, pidpathl - pidx, "%s/task/%s/", dp->d_name, tid);
48 + (void) snpf(pidpath + pidx, pidpathl - pidx, "%s/", dp->d_name);
51 * Process the PID's stat info.
52 @@ -1007,6 +1023,64 @@ process_id(idp, idpl, cmd, uid, pid, ppi
56 +/* fill tid if the initial thread is zombie,
57 + * but other thread still alive
59 + * returns -1=error, 0=nothing, 1=ok
62 +get_other_thread(pid, tid)
66 + char path[MAXPATHLEN];
74 + snpf(path, sizeof(path), "%s/%d/stat", PROCFS, pid);
75 + if (!(f = fopen(path, "r")))
77 + x = fscanf(f, "%d %*s %c", &_pid, &pstate);
82 + return -1; /* corrupted /proc? */
84 + return 0; /* ignore normal proceses */
86 + snpf(path, sizeof(path), "%s/%d/task", PROCFS, pid);
88 + /* open /proc/<pid>/task */
89 + if (!(tdp = opendir(path)))
90 + return 0; /* kernel < 2.6.x */
92 + /* look for first alive thread */
93 + while ((td = readdir(tdp))) {
94 + if (strcmp(td->d_name, ".")==0 || strcmp(td->d_name, "..")==0)
97 + /* /proc/<pid>/task/<tid>/stat */
98 + snpf(path, sizeof(path), "%s/%d/task/%s/stat", PROCFS, pid, td->d_name);
99 + if (!(f = fopen(path, "r")))
101 + x = fscanf(f, "%*d %*s %c", &pstate);
107 + *tid = strdup(td->d_name);
116 * process_proc_map() - process the memory map of a process
117 @@ -1250,12 +1324,6 @@ read_id_stat(ty, p, id, cmd, ppid, pgid)
121 - * Convert the first field to an integer; its conversion must match the
124 - if (!fp[0] || (atoi(fp[0]) != id))
127 * Get the command name from the second field. Strip a starting '(' and
128 * an ending ')'. Allocate space to hold the result and return the space