diff options
author | Leah Neukirchen <leah@vuxu.org> | 2018-09-17 16:48:16 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2018-09-17 16:48:16 +0200 |
commit | 8e9bea214cac73a4fe033891a6e25338c12f3ecf (patch) | |
tree | 5540d3a3782e21e80eb8a24d59b8e2a238cb2e9b | |
parent | 10f6237df0234b4704b1609a190b72da1b0333fa (diff) | |
download | extrace-8e9bea214cac73a4fe033891a6e25338c12f3ecf.tar.gz extrace-8e9bea214cac73a4fe033891a6e25338c12f3ecf.tar.xz extrace-8e9bea214cac73a4fe033891a6e25338c12f3ecf.zip |
pwait: verify pid as late as possible
-rw-r--r-- | pwait.c | 23 |
1 files 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); |