From a2031e792e57e5201afeeda9de0cb7f9a7bea7aa Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Mon, 17 Sep 2018 12:55:22 +0200 Subject: pwait: don't store pid 0 for invalid pids --- pwait.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pwait.c b/pwait.c index fabbd7f..15b4904 100644 --- a/pwait.c +++ b/pwait.c @@ -146,7 +146,7 @@ main(int argc, char *argv[]) enum proc_cn_mcast_op *mcop_msg; size_t recv_len = 0; int opt; - int n; + int n, m; pid_t *pids; pid_t pid; char *end; @@ -177,14 +177,14 @@ usage: exit(1); } - for (n = 0; n < argc; n++) { + for (n = m = 0; n < argc; n++) { errno = 0; pid = strtol(argv[n], &end, 10); if (pid < 0 || *end != '\0' || errno != 0) { fprintf(stderr, "%s: bad process id\n", argv[n]); continue; } - pids[n] = pid; + pids[m++] = pid; } sk_nl = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR); @@ -261,7 +261,7 @@ usage: pid_t pid = ev->event_data.exit.process_pid; seen = 0; - for (n = 0; n < argc; n++) + for (n = 0; n < m; n++) if (pids[n] == pid) { if (verbose && !seen) display(pid, status); @@ -280,7 +280,7 @@ usage: } quit = 1; - for (n = 0; n < argc; n++) + for (n = 0; n < m; n++) if (pids[n] != 0) quit = 0; } -- cgit 1.4.1