aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-09-19 22:29:42 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-09-19 22:29:42 +0200
commitb410d4ada73e9ebb30b2b50266a13c30479f5f21 (patch)
tree0d842b9c0885d1cf06fa6aa67a720b31b89cca55 /libbb
parentf00cfdfae53d8ef623238ecb1001969b5f649cbd (diff)
downloadbusybox-w32-b410d4ada73e9ebb30b2b50266a13c30479f5f21.tar.gz
busybox-w32-b410d4ada73e9ebb30b2b50266a13c30479f5f21.tar.bz2
busybox-w32-b410d4ada73e9ebb30b2b50266a13c30479f5f21.zip
ps,top: add an option to show threads. +260 bytes of code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/procps.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/libbb/procps.c b/libbb/procps.c
index 974661785..845a2141b 100644
--- a/libbb/procps.c
+++ b/libbb/procps.c
@@ -110,6 +110,10 @@ static procps_status_t* FAST_FUNC alloc_procps_scan(void)
110void FAST_FUNC free_procps_scan(procps_status_t* sp) 110void FAST_FUNC free_procps_scan(procps_status_t* sp)
111{ 111{
112 closedir(sp->dir); 112 closedir(sp->dir);
113#if ENABLE_FEATURE_SHOW_THREADS
114 if (sp->task_dir)
115 closedir(sp->task_dir);
116#endif
113 free(sp->argv0); 117 free(sp->argv0);
114 free(sp->exe); 118 free(sp->exe);
115 IF_SELINUX(free(sp->context);) 119 IF_SELINUX(free(sp->context);)
@@ -189,14 +193,35 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
189 sp = alloc_procps_scan(); 193 sp = alloc_procps_scan();
190 194
191 for (;;) { 195 for (;;) {
196#if ENABLE_FEATURE_SHOW_THREADS
197 if ((flags & PSSCAN_TASKS) && sp->task_dir) {
198 entry = readdir(sp->task_dir);
199 if (entry)
200 goto got_entry;
201 closedir(sp->task_dir);
202 sp->task_dir = NULL;
203 }
204#endif
192 entry = readdir(sp->dir); 205 entry = readdir(sp->dir);
193 if (entry == NULL) { 206 if (entry == NULL) {
194 free_procps_scan(sp); 207 free_procps_scan(sp);
195 return NULL; 208 return NULL;
196 } 209 }
210 IF_FEATURE_SHOW_THREADS(got_entry:)
197 pid = bb_strtou(entry->d_name, NULL, 10); 211 pid = bb_strtou(entry->d_name, NULL, 10);
198 if (errno) 212 if (errno)
199 continue; 213 continue;
214#if ENABLE_FEATURE_SHOW_THREADS
215 if ((flags & PSSCAN_TASKS) && !sp->task_dir) {
216 /* We found another /proc/PID. Do not use it,
217 * there will be /proc/PID/task/PID (same PID!),
218 * so just go ahead and dive into /proc/PID/task. */
219 char task_dir[sizeof("/proc/%u/task") + sizeof(int)*3];
220 sprintf(task_dir, "/proc/%u/task", pid);
221 sp->task_dir = xopendir(task_dir);
222 continue;
223 }
224#endif
200 225
201 /* After this point we have to break, not continue 226 /* After this point we have to break, not continue
202 * ("continue" would mean that current /proc/NNN 227 * ("continue" would mean that current /proc/NNN