From 18425501da3ad57fcf78eb111cf62ca4d79c3f5f Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Fri, 15 Mar 2019 12:16:24 -0400 Subject: rough out --- wait.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/wait.c b/wait.c index 16b64d7..d4a224b 100644 --- a/wait.c +++ b/wait.c @@ -1,8 +1,37 @@ +#define _XOPEN_SOURCE 700 #include +#include +#include -int -wait_main(int argc, char **argv) +#include "jobcontrol.h" + +int wait_main(int argc, char *argv[]) { - printf("Sorry, %s isn't implemented yet.\n", argv[0]); - return argc; + int c; + while ((c = getopt(argc, argv, "")) != -1) { + return 1; + } + + if (optind >= argc) { + /* wait for all children */ + return 0; + } + + int ret = 0; + do { + pid_t pid = pidfrom(argv[optind++]); + pid = waitpid(pid, &ret, 0); + + if (pid == -1) { + ret = 127; + } else if (WIFEXITED(ret)) { + ret = WEXITSTATUS(ret); + } else if (WIFSIGNALED(ret)) { + ret = 128; /* + something */ + } else { + ret = 126; + } + } while (argv[optind]); + + return 0; } -- cgit v1.2.1