killall, pidof: use argv0 for process matching too

top: show cmdline, not comm field
(fixes problems with re-execed applets showing as processes with name "exe",
and not being found by pidof/killall by applet name)

function                                             old     new   delta
find_pid_by_name                                      98     156     +58
procps_scan                                          692     732     +40
top_main                                            2724    2762     +38
find_pair                                            164     180     +16
collect_int                                          114     123      +9
cmp_main                                             547     555      +8
collect_fork                                         112     119      +7
collect_ctx                                          112     119      +7
read_package_field                                   253     257      +4
passwd_main                                         1983    1985      +2
process_stdin                                        435     433      -2
xstrtoul_range_sfx                                   229     226      -3
get_next_block                                      1852    1849      -3
arith                                               2042    2033      -9
sv_main                                             1236    1226     -10
singlemount                                         4690    4672     -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 10/6 up/down: 189/-45)          Total: 144 bytes
   text    data     bss     dec     hex filename
 734789    3028   14400  752217   b7a59 busybox_old
 734933    3028   14400  752361   b7ae9 busybox_unstripped
This commit is contained in:
Denis Vlasenko
2007-06-30 08:03:26 +00:00
parent 42ee26d00c
commit f7d07b1723
4 changed files with 60 additions and 27 deletions

View File

@ -92,7 +92,7 @@ static int read_to_buf(const char *filename, void *buf)
return ret;
}
procps_status_t* alloc_procps_scan(int flags)
procps_status_t *alloc_procps_scan(int flags)
{
procps_status_t* sp = xzalloc(sizeof(procps_status_t));
sp->dir = xopendir("/proc");
@ -133,7 +133,7 @@ static char *skip_fields(char *str, int count)
#endif
void BUG_comm_size(void);
procps_status_t* procps_scan(procps_status_t* sp, int flags)
procps_status_t *procps_scan(procps_status_t* sp, int flags)
{
struct dirent *entry;
char buf[PROCPS_BUFSIZE];
@ -266,24 +266,31 @@ procps_status_t* procps_scan(procps_status_t* sp, int flags)
}
if (flags & PSSCAN_CMD) {
free(sp->cmd);
sp->cmd = NULL;
if (flags & (PSSCAN_CMD|PSSCAN_ARGV0)) {
if (sp->argv0) {
free(sp->argv0);
sp->argv0 = NULL;
}
if (sp->cmd) {
free(sp->cmd);
sp->cmd = NULL;
}
strcpy(filename_tail, "/cmdline");
/* TODO: to get rid of size limits, read into malloc buf,
* then realloc it down to real size. */
n = read_to_buf(filename, buf);
if (n <= 0)
break;
if (buf[n-1] == '\n') {
if (!--n)
break;
buf[n] = '\0';
if (flags & PSSCAN_ARGV0)
sp->argv0 = xstrdup(buf);
if (flags & PSSCAN_CMD) {
do {
n--;
if ((unsigned char)(buf[n]) < ' ')
buf[n] = ' ';
} while (n);
sp->cmd = xstrdup(buf);
}
do {
n--;
if ((unsigned char)(buf[n]) < ' ')
buf[n] = ' ';
} while (n);
sp->cmd = xstrdup(buf);
}
break;
}