aboutsummaryrefslogtreecommitdiff
path: root/libbb/procps.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/procps.c')
-rw-r--r--libbb/procps.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/libbb/procps.c b/libbb/procps.c
index 8413ce8a1..1987e98fd 100644
--- a/libbb/procps.c
+++ b/libbb/procps.c
@@ -102,7 +102,7 @@ procps_status_t *alloc_procps_scan(int flags)
102void free_procps_scan(procps_status_t* sp) 102void free_procps_scan(procps_status_t* sp)
103{ 103{
104 closedir(sp->dir); 104 closedir(sp->dir);
105 free(sp->cmd); 105 free(sp->argv0);
106 USE_SELINUX(free(sp->context);) 106 USE_SELINUX(free(sp->context);)
107 free(sp); 107 free(sp);
108} 108}
@@ -266,6 +266,7 @@ procps_status_t *procps_scan(procps_status_t* sp, int flags)
266 266
267 } 267 }
268 268
269#if 0 /* PSSCAN_CMD is not used */
269 if (flags & (PSSCAN_CMD|PSSCAN_ARGV0)) { 270 if (flags & (PSSCAN_CMD|PSSCAN_ARGV0)) {
270 if (sp->argv0) { 271 if (sp->argv0) {
271 free(sp->argv0); 272 free(sp->argv0);
@@ -292,10 +293,42 @@ procps_status_t *procps_scan(procps_status_t* sp, int flags)
292 sp->cmd = xstrdup(buf); 293 sp->cmd = xstrdup(buf);
293 } 294 }
294 } 295 }
296#else
297 if (flags & PSSCAN_ARGV0) {
298 if (sp->argv0) {
299 free(sp->argv0);
300 sp->argv0 = NULL;
301 }
302 strcpy(filename_tail, "/cmdline");
303 n = read_to_buf(filename, buf);
304 if (n <= 0)
305 break;
306 if (flags & PSSCAN_ARGV0)
307 sp->argv0 = xstrdup(buf);
308 }
309#endif
295 break; 310 break;
296 } 311 }
297 return sp; 312 return sp;
298} 313}
314
315void read_cmdline(char *buf, int col, unsigned pid, const char *comm)
316{
317 ssize_t sz;
318 char filename[sizeof("/proc//cmdline") + sizeof(int)*3];
319
320 sprintf(filename, "/proc/%u/cmdline", pid);
321 sz = open_read_close(filename, buf, col);
322 if (sz > 0) {
323 buf[sz] = '\0';
324 while (--sz >= 0)
325 if ((unsigned char)(buf[sz]) < ' ')
326 buf[sz] = ' ';
327 } else {
328 snprintf(buf, col, "[%s]", comm);
329 }
330}
331
299/* from kernel: 332/* from kernel:
300 // pid comm S ppid pgid sid tty_nr tty_pgrp flg 333 // pid comm S ppid pgid sid tty_nr tty_pgrp flg
301 sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \ 334 sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \