aboutsummaryrefslogtreecommitdiff
path: root/libbb/procps.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2012-03-23 11:13:23 +0000
committerRon Yorston <rmy@pobox.com>2012-03-23 11:13:23 +0000
commit40514a0309939f2446f0d4ed9600cad5de396e7f (patch)
tree0f5f4a57d4bb7893418b5bb11d482858eb17ba8b /libbb/procps.c
parent9db164d6e39050d09f38288c6045cd2a2cbf6d63 (diff)
parentc0cae52662ccced9df19f19ec94238d1b1e3bd71 (diff)
downloadbusybox-w32-40514a0309939f2446f0d4ed9600cad5de396e7f.tar.gz
busybox-w32-40514a0309939f2446f0d4ed9600cad5de396e7f.tar.bz2
busybox-w32-40514a0309939f2446f0d4ed9600cad5de396e7f.zip
Merge commit 'c0cae52662ccced9df19f19ec94238d1b1e3bd71' into merge
Conflicts: Makefile.flags scripts/basic/fixdep.c
Diffstat (limited to 'libbb/procps.c')
-rw-r--r--libbb/procps.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/libbb/procps.c b/libbb/procps.c
index b5582edfa..39ddd2c12 100644
--- a/libbb/procps.c
+++ b/libbb/procps.c
@@ -285,27 +285,25 @@ int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total,
285void BUG_comm_size(void); 285void BUG_comm_size(void);
286procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) 286procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
287{ 287{
288 struct dirent *entry;
289 char buf[PROCPS_BUFSIZE];
290 char filename[sizeof("/proc//cmdline") + sizeof(int)*3];
291 char *filename_tail;
292 long tasknice;
293 unsigned pid;
294 int n;
295 struct stat sb;
296
297 if (!sp) 288 if (!sp)
298 sp = alloc_procps_scan(); 289 sp = alloc_procps_scan();
299 290
300 for (;;) { 291 for (;;) {
292 struct dirent *entry;
293 char buf[PROCPS_BUFSIZE];
294 long tasknice;
295 unsigned pid;
296 int n;
297 char filename[sizeof("/proc/%u/task/%u/cmdline") + sizeof(int)*3 * 2];
298 char *filename_tail;
299
301#if ENABLE_FEATURE_SHOW_THREADS 300#if ENABLE_FEATURE_SHOW_THREADS
302 if ((flags & PSSCAN_TASKS) && sp->task_dir) { 301 if (sp->task_dir) {
303 entry = readdir(sp->task_dir); 302 entry = readdir(sp->task_dir);
304 if (entry) 303 if (entry)
305 goto got_entry; 304 goto got_entry;
306 closedir(sp->task_dir); 305 closedir(sp->task_dir);
307 sp->task_dir = NULL; 306 sp->task_dir = NULL;
308 sp->main_thread_pid = 0;
309 } 307 }
310#endif 308#endif
311 entry = readdir(sp->dir); 309 entry = readdir(sp->dir);
@@ -322,9 +320,9 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
322 /* We found another /proc/PID. Do not use it, 320 /* We found another /proc/PID. Do not use it,
323 * there will be /proc/PID/task/PID (same PID!), 321 * there will be /proc/PID/task/PID (same PID!),
324 * so just go ahead and dive into /proc/PID/task. */ 322 * so just go ahead and dive into /proc/PID/task. */
325 char task_dir[sizeof("/proc/%u/task") + sizeof(int)*3]; 323 sprintf(filename, "/proc/%u/task", pid);
326 sprintf(task_dir, "/proc/%u/task", pid); 324 /* Note: if opendir fails, we just go to next /proc/XXX */
327 sp->task_dir = xopendir(task_dir); 325 sp->task_dir = opendir(filename);
328 sp->main_thread_pid = pid; 326 sp->main_thread_pid = pid;
329 continue; 327 continue;
330 } 328 }
@@ -348,9 +346,15 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
348 } 346 }
349#endif 347#endif
350 348
351 filename_tail = filename + sprintf(filename, "/proc/%u/", pid); 349#if ENABLE_FEATURE_SHOW_THREADS
350 if (sp->task_dir)
351 filename_tail = filename + sprintf(filename, "/proc/%u/task/%u/", sp->main_thread_pid, pid);
352 else
353#endif
354 filename_tail = filename + sprintf(filename, "/proc/%u/", pid);
352 355
353 if (flags & PSSCAN_UIDGID) { 356 if (flags & PSSCAN_UIDGID) {
357 struct stat sb;
354 if (stat(filename, &sb)) 358 if (stat(filename, &sb))
355 continue; /* process probably exited */ 359 continue; /* process probably exited */
356 /* Effective UID/GID, not real */ 360 /* Effective UID/GID, not real */