diff options
Diffstat (limited to 'libbb/procps.c')
-rw-r--r-- | libbb/procps.c | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/libbb/procps.c b/libbb/procps.c index 5924d60a8..8413ce8a1 100644 --- a/libbb/procps.c +++ b/libbb/procps.c | |||
@@ -92,7 +92,7 @@ static int read_to_buf(const char *filename, void *buf) | |||
92 | return ret; | 92 | return ret; |
93 | } | 93 | } |
94 | 94 | ||
95 | procps_status_t* alloc_procps_scan(int flags) | 95 | procps_status_t *alloc_procps_scan(int flags) |
96 | { | 96 | { |
97 | procps_status_t* sp = xzalloc(sizeof(procps_status_t)); | 97 | procps_status_t* sp = xzalloc(sizeof(procps_status_t)); |
98 | sp->dir = xopendir("/proc"); | 98 | sp->dir = xopendir("/proc"); |
@@ -133,7 +133,7 @@ static char *skip_fields(char *str, int count) | |||
133 | #endif | 133 | #endif |
134 | 134 | ||
135 | void BUG_comm_size(void); | 135 | void BUG_comm_size(void); |
136 | procps_status_t* procps_scan(procps_status_t* sp, int flags) | 136 | procps_status_t *procps_scan(procps_status_t* sp, int flags) |
137 | { | 137 | { |
138 | struct dirent *entry; | 138 | struct dirent *entry; |
139 | char buf[PROCPS_BUFSIZE]; | 139 | char buf[PROCPS_BUFSIZE]; |
@@ -266,24 +266,31 @@ procps_status_t* procps_scan(procps_status_t* sp, int flags) | |||
266 | 266 | ||
267 | } | 267 | } |
268 | 268 | ||
269 | if (flags & PSSCAN_CMD) { | 269 | if (flags & (PSSCAN_CMD|PSSCAN_ARGV0)) { |
270 | free(sp->cmd); | 270 | if (sp->argv0) { |
271 | sp->cmd = NULL; | 271 | free(sp->argv0); |
272 | sp->argv0 = NULL; | ||
273 | } | ||
274 | if (sp->cmd) { | ||
275 | free(sp->cmd); | ||
276 | sp->cmd = NULL; | ||
277 | } | ||
272 | strcpy(filename_tail, "/cmdline"); | 278 | strcpy(filename_tail, "/cmdline"); |
279 | /* TODO: to get rid of size limits, read into malloc buf, | ||
280 | * then realloc it down to real size. */ | ||
273 | n = read_to_buf(filename, buf); | 281 | n = read_to_buf(filename, buf); |
274 | if (n <= 0) | 282 | if (n <= 0) |
275 | break; | 283 | break; |
276 | if (buf[n-1] == '\n') { | 284 | if (flags & PSSCAN_ARGV0) |
277 | if (!--n) | 285 | sp->argv0 = xstrdup(buf); |
278 | break; | 286 | if (flags & PSSCAN_CMD) { |
279 | buf[n] = '\0'; | 287 | do { |
288 | n--; | ||
289 | if ((unsigned char)(buf[n]) < ' ') | ||
290 | buf[n] = ' '; | ||
291 | } while (n); | ||
292 | sp->cmd = xstrdup(buf); | ||
280 | } | 293 | } |
281 | do { | ||
282 | n--; | ||
283 | if ((unsigned char)(buf[n]) < ' ') | ||
284 | buf[n] = ' '; | ||
285 | } while (n); | ||
286 | sp->cmd = xstrdup(buf); | ||
287 | } | 294 | } |
288 | break; | 295 | break; |
289 | } | 296 | } |