compat: prefer waitpid() over waitid()

while both are defined by POSIX, waitpid() is more common than waitid().

Signed-off-by: Sebastien Marie <semarie@online.fr>
This commit is contained in:
Sébastien Marie 2024-01-19 16:08:21 +00:00 committed by Daniel Stone
parent a74aa93394
commit 791912c678
2 changed files with 19 additions and 27 deletions

View file

@ -103,26 +103,23 @@ handle_client_destroy(void *data)
{ {
struct client_info *ci = data; struct client_info *ci = data;
struct display *d; struct display *d;
siginfo_t status; int status;
d = ci->display; d = ci->display;
assert(waitid(P_PID, ci->pid, &status, WEXITED) != -1); assert(waitpid(ci->pid, &status, 0) != -1);
switch (status.si_code) { if (WIFSIGNALED(status)) {
case CLD_KILLED:
case CLD_DUMPED:
fprintf(stderr, "Client '%s' was killed by signal %d\n", fprintf(stderr, "Client '%s' was killed by signal %d\n",
ci->name, status.si_status); ci->name, WTERMSIG(status));
ci->kill_code = status.si_status; ci->kill_code = WTERMSIG(status);
break;
case CLD_EXITED:
if (status.si_status != EXIT_SUCCESS)
fprintf(stderr, "Client '%s' exited with code %d\n",
ci->name, status.si_status);
ci->exit_code = status.si_status; } else if (WIFEXITED(status)) {
break; if (WEXITSTATUS(status) != EXIT_SUCCESS)
fprintf(stderr, "Client '%s' exited with code %d\n",
ci->name, WEXITSTATUS(status));
ci->exit_code = WEXITSTATUS(status);
} }
++d->clients_terminated_no; ++d->clients_terminated_no;

View file

@ -315,7 +315,7 @@ int main(int argc, char *argv[])
const struct test *t; const struct test *t;
pid_t pid; pid_t pid;
int total, pass; int total, pass;
siginfo_t info; int info;
if (isatty(fileno(stderr))) if (isatty(fileno(stderr)))
is_atty = 1; is_atty = 1;
@ -358,37 +358,32 @@ int main(int argc, char *argv[])
if (pid == 0) if (pid == 0)
run_test(t); /* never returns */ run_test(t); /* never returns */
if (waitid(P_PID, pid, &info, WEXITED)) { if (waitpid(pid, &info, 0) == -1) {
stderr_set_color(RED); stderr_set_color(RED);
fprintf(stderr, "waitid failed: %s\n", fprintf(stderr, "waitpid failed: %s\n",
strerror(errno)); strerror(errno));
stderr_reset_color(); stderr_reset_color();
abort(); abort();
} }
switch (info.si_code) { if (WIFEXITED(info)) {
case CLD_EXITED: if (WEXITSTATUS(info) == EXIT_SUCCESS)
if (info.si_status == EXIT_SUCCESS)
success = !t->must_fail; success = !t->must_fail;
else else
success = t->must_fail; success = t->must_fail;
stderr_set_color(success ? GREEN : RED); stderr_set_color(success ? GREEN : RED);
fprintf(stderr, "test \"%s\":\texit status %d", fprintf(stderr, "test \"%s\":\texit status %d",
t->name, info.si_status); t->name, WEXITSTATUS(info));
break; } else if (WIFSIGNALED(info)) {
case CLD_KILLED:
case CLD_DUMPED:
if (t->must_fail) if (t->must_fail)
success = 1; success = 1;
stderr_set_color(success ? GREEN : RED); stderr_set_color(success ? GREEN : RED);
fprintf(stderr, "test \"%s\":\tsignal %d", fprintf(stderr, "test \"%s\":\tsignal %d",
t->name, info.si_status); t->name, WTERMSIG(info));
break;
} }
if (success) { if (success) {