diff options
author | Denis Vlasenko | 2006-11-01 09:16:49 +0000 |
---|---|---|
committer | Denis Vlasenko | 2006-11-01 09:16:49 +0000 |
commit | 35fb51272863c8723a40e59d2024c7f4c9ec8946 (patch) | |
tree | a97deb26bca43e394a603840039846cd9d89cae9 /procps | |
parent | d3ada3228551e2556afb9de6d3126fd016df1fb1 (diff) | |
download | busybox-35fb51272863c8723a40e59d2024c7f4c9ec8946.zip busybox-35fb51272863c8723a40e59d2024c7f4c9ec8946.tar.gz |
PID should be stored in pid_t, not int or long.
find_pid_by_name() was returning 0 or -1 in last array element,
but -1 was never checked. We can use just 0 intead.
Diffstat (limited to 'procps')
-rw-r--r-- | procps/kill.c | 30 | ||||
-rw-r--r-- | procps/pidof.c | 36 | ||||
-rw-r--r-- | procps/ps.c | 8 | ||||
-rw-r--r-- | procps/top.c | 9 |
4 files changed, 44 insertions, 39 deletions
diff --git a/procps/kill.c b/procps/kill.c index b29f61b..f22bdbe 100644 --- a/procps/kill.c +++ b/procps/kill.c @@ -103,31 +103,31 @@ do_it_now: } /* Pid or name required for kill/killall */ - if (argc<1) + if (argc < 1) bb_show_usage(); if (killall) { /* Looks like they want to do a killall. Do that */ pid = getpid(); while (arg) { - long* pidList; + pid_t* pidList; pidList = find_pid_by_name(arg); - if (!pidList || *pidList<=0) { + if (*pidList == 0) { errors++; if (!quiet) bb_error_msg("%s: no process killed", arg); } else { - long *pl; + pid_t *pl; - for (pl = pidList; *pl!=0; pl++) { - if (*pl==pid) + for (pl = pidList; *pl; pl++) { + if (*pl == pid) continue; - if (kill(*pl, signo)!=0) { - errors++; - if (!quiet) - bb_perror_msg("cannot kill pid %ld", *pl); - } + if (kill(*pl, signo) == 0) + continue; + errors++; + if (!quiet) + bb_perror_msg("cannot kill pid %u", (unsigned)*pl); } } free(pidList); @@ -138,12 +138,14 @@ do_it_now: /* Looks like they want to do a kill. Do that */ while (arg) { - if (!isdigit(arg[0]) && arg[0]!='-') + /* Huh? + if (!isdigit(arg[0]) && arg[0] != '-') bb_error_msg_and_die("bad pid '%s'", arg); + */ pid = xatou(arg); /* FIXME: better overflow check? */ - if (kill(pid, signo)!=0) { - bb_perror_msg("cannot kill pid %ld", (long)pid); + if (kill(pid, signo) != 0) { + bb_perror_msg("cannot kill pid %u", (unsigned)pid); errors++; } arg = *++argv; diff --git a/procps/pidof.c b/procps/pidof.c index 62c590f..28c5c04 100644 --- a/procps/pidof.c +++ b/procps/pidof.c @@ -18,18 +18,18 @@ #endif #if ENABLE_FEATURE_PIDOF_OMIT -#define _OMIT_COMPL(a) a -#define _OMIT(a) ,a -#if ENABLE_FEATURE_PIDOF_SINGLE -#define OMIT (1<<1) -#else -#define OMIT (1<<0) -#endif +# define _OMIT_COMPL(a) a +# define _OMIT(a) ,a +# if ENABLE_FEATURE_PIDOF_SINGLE +# define OMIT (1<<1) +# else +# define OMIT (1<<0) +# endif #else -#define _OMIT_COMPL(a) "" -#define _OMIT(a) -#define OMIT (0) -#define omitted (0) +# define _OMIT_COMPL(a) "" +# define _OMIT(a) +# define OMIT (0) +# define omitted (0) #endif int pidof_main(int argc, char **argv) @@ -65,21 +65,23 @@ int pidof_main(int argc, char **argv) #endif /* Looks like everything is set to go. */ while (optind < argc) { - long *pidList; - long *pl; + pid_t *pidList; + pid_t *pl; /* reverse the pidlist like GNU pidof does. */ pidList = pidlist_reverse(find_pid_by_name(argv[optind])); - for (pl = pidList; *pl > 0; pl++) { + for (pl = pidList; *pl; pl++) { #if ENABLE_FEATURE_PIDOF_OMIT unsigned omitted = 0; if (opt & OMIT) { llist_t *omits_p = omits; - while (omits_p) + while (omits_p) { if (xatoul(omits_p->data) == *pl) { - omitted = 1; break; + omitted = 1; + break; } else omits_p = omits_p->link; + } } #endif if (!omitted) { @@ -88,7 +90,7 @@ int pidof_main(int argc, char **argv) } else { n = 1; } - printf("%ld", *pl); + printf("%u", (unsigned)*pl); } fail = (!ENABLE_FEATURE_PIDOF_OMIT && omitted); diff --git a/procps/ps.c b/procps/ps.c index 97e239b..df4dcc4 100644 --- a/procps/ps.c +++ b/procps/ps.c @@ -58,7 +58,7 @@ int ps_main(int argc, char **argv) len = sizeof(sbuf); if (is_selinux_enabled()) { - if (getpidcon(p->pid,&sid) < 0) + if (getpidcon(p->pid, &sid) < 0) sid = NULL; } @@ -71,14 +71,14 @@ int ps_main(int argc, char **argv) } else { safe_strncpy(sbuf, "unknown", 7); } - len = printf("%5d %-32s %s ", p->pid, sbuf, p->state); + len = printf("%5u %-32s %s ", (unsigned)p->pid, sbuf, p->state); } else #endif if (p->rss == 0) - len = printf("%5d %-8s %s ", p->pid, p->user, p->state); + len = printf("%5u %-8s %s ", (unsigned)p->pid, p->user, p->state); else - len = printf("%5d %-8s %6ld %s ", p->pid, p->user, p->rss, p->state); + len = printf("%5u %-8s %6ld %s ", (unsigned)p->pid, p->user, p->rss, p->state); i = terminal_width-len; diff --git a/procps/top.c b/procps/top.c index d58fdda..3ff61df 100644 --- a/procps/top.c +++ b/procps/top.c @@ -78,7 +78,7 @@ static int mult_lvl_cmp(void* a, void* b) { the next. Mostly used for sorting. */ struct save_hist { int ticks; - int pid; + pid_t pid; }; /* @@ -119,7 +119,8 @@ static void get_jiffy_counts(void) static void do_stats(void) { procps_status_t *cur; - int pid, total_time, i, last_i, n; + pid_t pid; + int total_time, i, last_i, n; struct save_hist *new_hist; get_jiffy_counts(); @@ -328,9 +329,9 @@ static void display_status(int count, int scr_width) else sprintf(rss_str_buf, "%7ld", s->rss); USE_FEATURE_TOP_CPU_USAGE_PERCENTAGE(pcpu = div((s->pcpu*pcpu_scale) >> pcpu_shift, 10);) - col -= printf("\n%5d %-8s %s %s%6d%3u.%c" \ + col -= printf("\n%5u %-8s %s %s%6u%3u.%c" \ USE_FEATURE_TOP_CPU_USAGE_PERCENTAGE("%3u.%c") " ", - s->pid, s->user, s->state, rss_str_buf, s->ppid, + (unsigned)s->pid, s->user, s->state, rss_str_buf, (unsigned)s->ppid, USE_FEATURE_TOP_CPU_USAGE_PERCENTAGE(pcpu.quot, '0'+pcpu.rem,) pmem.quot, '0'+pmem.rem); if (col > 0) |