diff options
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/procps.c | 35 | ||||
-rw-r--r-- | libbb/read.c | 6 |
2 files changed, 37 insertions, 4 deletions
diff --git a/libbb/procps.c b/libbb/procps.c index 8413ce8..1987e98 100644 --- a/libbb/procps.c +++ b/libbb/procps.c @@ -102,7 +102,7 @@ procps_status_t *alloc_procps_scan(int flags) void free_procps_scan(procps_status_t* sp) { closedir(sp->dir); - free(sp->cmd); + free(sp->argv0); USE_SELINUX(free(sp->context);) free(sp); } @@ -266,6 +266,7 @@ procps_status_t *procps_scan(procps_status_t* sp, int flags) } +#if 0 /* PSSCAN_CMD is not used */ if (flags & (PSSCAN_CMD|PSSCAN_ARGV0)) { if (sp->argv0) { free(sp->argv0); @@ -292,10 +293,42 @@ procps_status_t *procps_scan(procps_status_t* sp, int flags) sp->cmd = xstrdup(buf); } } +#else + if (flags & PSSCAN_ARGV0) { + if (sp->argv0) { + free(sp->argv0); + sp->argv0 = NULL; + } + strcpy(filename_tail, "/cmdline"); + n = read_to_buf(filename, buf); + if (n <= 0) + break; + if (flags & PSSCAN_ARGV0) + sp->argv0 = xstrdup(buf); + } +#endif break; } return sp; } + +void read_cmdline(char *buf, int col, unsigned pid, const char *comm) +{ + ssize_t sz; + char filename[sizeof("/proc//cmdline") + sizeof(int)*3]; + + sprintf(filename, "/proc/%u/cmdline", pid); + sz = open_read_close(filename, buf, col); + if (sz > 0) { + buf[sz] = '\0'; + while (--sz >= 0) + if ((unsigned char)(buf[sz]) < ' ') + buf[sz] = ' '; + } else { + snprintf(buf, col, "[%s]", comm); + } +} + /* from kernel: // pid comm S ppid pgid sid tty_nr tty_pgrp flg sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \ diff --git a/libbb/read.c b/libbb/read.c index 05bf754..502d407 100644 --- a/libbb/read.c +++ b/libbb/read.c @@ -124,11 +124,11 @@ char *xmalloc_reads(int fd, char *buf) ssize_t read_close(int fd, void *buf, size_t size) { - int e; + /*int e;*/ size = full_read(fd, buf, size); - e = errno; + /*e = errno;*/ close(fd); - errno = e; + /*errno = e;*/ return size; } |