diff options
Diffstat (limited to 'libbb/procps.c')
-rw-r--r-- | libbb/procps.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/libbb/procps.c b/libbb/procps.c index 6e122c4d5..307d8d622 100644 --- a/libbb/procps.c +++ b/libbb/procps.c | |||
@@ -111,6 +111,7 @@ void FAST_FUNC free_procps_scan(procps_status_t* sp) | |||
111 | { | 111 | { |
112 | closedir(sp->dir); | 112 | closedir(sp->dir); |
113 | free(sp->argv0); | 113 | free(sp->argv0); |
114 | free(sp->exe); | ||
114 | IF_SELINUX(free(sp->context);) | 115 | IF_SELINUX(free(sp->context);) |
115 | free(sp); | 116 | free(sp); |
116 | } | 117 | } |
@@ -213,7 +214,7 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) | |||
213 | } | 214 | } |
214 | #endif | 215 | #endif |
215 | 216 | ||
216 | filename_tail = filename + sprintf(filename, "/proc/%d", pid); | 217 | filename_tail = filename + sprintf(filename, "/proc/%u/", pid); |
217 | 218 | ||
218 | if (flags & PSSCAN_UIDGID) { | 219 | if (flags & PSSCAN_UIDGID) { |
219 | if (stat(filename, &sb)) | 220 | if (stat(filename, &sb)) |
@@ -230,7 +231,7 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) | |||
230 | unsigned long vsz, rss; | 231 | unsigned long vsz, rss; |
231 | #endif | 232 | #endif |
232 | /* see proc(5) for some details on this */ | 233 | /* see proc(5) for some details on this */ |
233 | strcpy(filename_tail, "/stat"); | 234 | strcpy(filename_tail, "stat"); |
234 | n = read_to_buf(filename, buf); | 235 | n = read_to_buf(filename, buf); |
235 | if (n < 0) | 236 | if (n < 0) |
236 | break; | 237 | break; |
@@ -340,7 +341,7 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) | |||
340 | if (flags & (PSSCAN_SMAPS)) { | 341 | if (flags & (PSSCAN_SMAPS)) { |
341 | FILE *file; | 342 | FILE *file; |
342 | 343 | ||
343 | strcpy(filename_tail, "/smaps"); | 344 | strcpy(filename_tail, "smaps"); |
344 | file = fopen_for_read(filename); | 345 | file = fopen_for_read(filename); |
345 | if (!file) | 346 | if (!file) |
346 | break; | 347 | break; |
@@ -390,7 +391,7 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) | |||
390 | if (flags & PSSCAN_RUIDGID) { | 391 | if (flags & PSSCAN_RUIDGID) { |
391 | FILE *file; | 392 | FILE *file; |
392 | 393 | ||
393 | strcpy(filename_tail, "/status"); | 394 | strcpy(filename_tail, "status"); |
394 | file = fopen_for_read(filename); | 395 | file = fopen_for_read(filename); |
395 | if (!file) | 396 | if (!file) |
396 | break; | 397 | break; |
@@ -415,7 +416,7 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) | |||
415 | sp->argv0 = NULL; | 416 | sp->argv0 = NULL; |
416 | free(sp->cmd); | 417 | free(sp->cmd); |
417 | sp->cmd = NULL; | 418 | sp->cmd = NULL; |
418 | strcpy(filename_tail, "/cmdline"); | 419 | strcpy(filename_tail, "cmdline"); |
419 | /* TODO: to get rid of size limits, read into malloc buf, | 420 | /* TODO: to get rid of size limits, read into malloc buf, |
420 | * then realloc it down to real size. */ | 421 | * then realloc it down to real size. */ |
421 | n = read_to_buf(filename, buf); | 422 | n = read_to_buf(filename, buf); |
@@ -436,7 +437,7 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) | |||
436 | if (flags & (PSSCAN_ARGV0|PSSCAN_ARGVN)) { | 437 | if (flags & (PSSCAN_ARGV0|PSSCAN_ARGVN)) { |
437 | free(sp->argv0); | 438 | free(sp->argv0); |
438 | sp->argv0 = NULL; | 439 | sp->argv0 = NULL; |
439 | strcpy(filename_tail, "/cmdline"); | 440 | strcpy(filename_tail, "cmdline"); |
440 | n = read_to_buf(filename, buf); | 441 | n = read_to_buf(filename, buf); |
441 | if (n <= 0) | 442 | if (n <= 0) |
442 | break; | 443 | break; |
@@ -451,6 +452,11 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) | |||
451 | } | 452 | } |
452 | } | 453 | } |
453 | #endif | 454 | #endif |
455 | if (flags & PSSCAN_EXE) { | ||
456 | strcpy(filename_tail, "exe"); | ||
457 | free(sp->exe); | ||
458 | sp->exe = xmalloc_readlink(filename); | ||
459 | } | ||
454 | break; | 460 | break; |
455 | } | 461 | } |
456 | return sp; | 462 | return sp; |