1303 files changed, 32187 insertions, 57138 deletions
diff --git a/libbb/procps.c b/libbb/procps.c index 5b68d34..4edc54d 100644 --- a/libbb/procps.c +++ b/libbb/procps.c @@ -205,11 +205,11 @@ int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total, // Rss: nnn kB // ..... - char *tp = buf, *p; + char *tp, *p; #define SCAN(S, X) \ - if (strncmp(tp, S, sizeof(S)-1) == 0) { \ - tp = skip_whitespace(tp + sizeof(S)-1); \ + if ((tp = is_prefixed_with(buf, S)) != NULL) { \ + tp = skip_whitespace(tp); \ total->X += currec.X = fast_strtoul_10(&tp); \ continue; \ } @@ -247,7 +247,7 @@ int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total, // skipping "rw-s FILEOFS M:m INODE " tp = skip_whitespace(skip_fields(tp, 4)); // filter out /dev/something (something != zero) - if (strncmp(tp, "/dev/", 5) != 0 || strcmp(tp, "/dev/zero\n") == 0) { + if (!is_prefixed_with(tp, "/dev/") || strcmp(tp, "/dev/zero\n") == 0) { if (currec.smap_mode[1] == 'w') { currec.mapped_rw = currec.smap_size; total->mapped_rw += currec.smap_size; @@ -283,7 +283,6 @@ int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total, } #endif -void BUG_comm_size(void); procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) { if (!sp) @@ -385,8 +384,7 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) /*if (!cp || cp[1] != ' ') continue;*/ cp[0] = '\0'; - if (sizeof(sp->comm) < 16) - BUG_comm_size(); + BUILD_BUG_ON(sizeof(sp->comm) < 16); comm1 = strchr(buf, '('); /*if (comm1)*/ safe_strncpy(sp->comm, comm1 + 1, sizeof(sp->comm)); @@ -497,8 +495,8 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) while (fgets(buf, sizeof(buf), file)) { char *tp; #define SCAN_TWO(str, name, statement) \ - if (strncmp(buf, str, sizeof(str)-1) == 0) { \ - tp = skip_whitespace(buf + sizeof(str)-1); \ + if ((tp = is_prefixed_with(buf, str)) != NULL) { \ + tp = skip_whitespace(tp); \ sscanf(tp, "%u", &sp->name); \ statement; \ } @@ -554,8 +552,7 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) break; if (flags & PSSCAN_ARGVN) { sp->argv_len = n; - sp->argv0 = xmalloc(n + 1); - memcpy(sp->argv0, buf, n + 1); + sp->argv0 = xmemdup(buf, n + 1); /* sp->argv0[n] = '\0'; - buf has it */ } else { sp->argv_len = 0; @@ -591,12 +588,14 @@ void FAST_FUNC read_cmdline(char *buf, int col, unsigned pid, const char *comm) buf[sz] = ' '; sz--; } + if (base[0] == '-') /* "-sh" (login shell)? */ + base++; /* If comm differs from argv0, prepend "{comm} ". * It allows to see thread names set by prctl(PR_SET_NAME). */ - if (base[0] == '-') /* "-sh" (login shell)? */ - base++; + if (!comm) + return; comm_len = strlen(comm); /* Why compare up to comm_len, not COMM_LEN-1? * Well, some processes rewrite argv, and use _spaces_ there @@ -614,9 +613,8 @@ void FAST_FUNC read_cmdline(char *buf, int col, unsigned pid, const char *comm) buf[comm_len - 1] = ' '; buf[col - 1] = '\0'; } - } else { - snprintf(buf, col, "[%s]", comm); + snprintf(buf, col, "[%s]", comm ? comm : "?"); } } |