Collect status of the child process to detect test failures.
OK tb@
-/* $OpenBSD: descrip.c,v 1.1 2018/08/10 15:58:16 jsing Exp $ */
+/* $OpenBSD: descrip.c,v 1.2 2021/09/27 18:10:24 bluhm Exp $ */
/*
* Copyright (c) 2018 Joel Sing <jsing@openbsd.org>
*
int
main(int argc, char **argv)
{
- int fd, kq;
+ int fd, kq, status;
+ pid_t pf, pw;
kq = kqueue();
assert(kq == 3);
fd = open("/etc/hosts", O_RDONLY);
assert(fd == 4);
- if (fork() == 0) {
+ pf = fork();
+ if (pf == 0) {
/*
* The existing kq fd should have been closed across fork,
* hence we expect fd 3 to be reallocated on this kqueue call.
*/
fd = open("/etc/hosts", O_RDONLY);
assert(fd == 5);
+
+ _exit(0);
}
+ assert(pf > 0);
+
+ pw = wait(&status);
+ assert(pf == pw);
+ assert(status == 0);
- wait(NULL);
+ return 0;
}