From 8e9bea214cac73a4fe033891a6e25338c12f3ecf Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Mon, 17 Sep 2018 16:48:16 +0200 Subject: pwait: verify pid as late as possible --- pwait.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/pwait.c b/pwait.c index ca2cafb..842fe9a 100644 --- a/pwait.c +++ b/pwait.c @@ -185,14 +185,6 @@ usage: argv[n]); continue; } - errno = 0; - kill(pid, 0); - if (errno == ESRCH) { - fprintf(stderr, "pwait: %s: no such process\n", - argv[n]); - continue; - } - pids[m++] = pid; } @@ -247,6 +239,21 @@ usage: signal(SIGINT, sigint); + quit = 1; + for (n = 0; n < m; n++) { + errno = 0; + kill(pids[n], 0); + if (errno == ESRCH) { + fprintf(stderr, "pwait: %d: no such process\n", + pids[n]); + pids[n] = 0; + continue; + } + quit = 0; + } + if (quit) + exit(1); + rc = 0; while (!quit) { memset(buff, 0, sizeof buff); -- cgit 1.4.1