From 7ec616e1e5040e7c4b8c1e6dae0fc656e744a90f Mon Sep 17 00:00:00 2001 From: sin Date: Sat, 4 Jan 2014 13:51:13 +0000 Subject: [PATCH] Exit with proper error codes We still have a few error codes to do, namely when the process is killed or stopped by a signal or when one or more invocations of the command returned a nonzero exit status. --- xargs.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/xargs.c b/xargs.c index da505f9..b283b5e 100644 --- a/xargs.c +++ b/xargs.c @@ -1,4 +1,5 @@ /* See LICENSE file for copyright and license details. */ +#include #include #include #include @@ -19,7 +20,7 @@ static int parsequote(int); static void parseescape(void); static char *poparg(void); static void pusharg(char *); -static int runcmd(void); +static void runcmd(void); static char **cmd; static char *argb; @@ -85,11 +86,7 @@ main(int argc, char *argv[]) i++; } cmd[i] = NULL; - if (i == 1 && rflag == 1) - ; - else - if (runcmd() == -1) - arg = NULL; + if (i == 1 && rflag == 1); else runcmd(); for (; i >= 0; i--) free(cmd[i]); } while (arg); @@ -221,7 +218,7 @@ pusharg(char *arg) deinputc(*p); } -static int +static void runcmd(void) { pid_t pid; @@ -233,9 +230,9 @@ runcmd(void) if (pid == 0) { execvp(*cmd, cmd); eprintf("execvp %s:", *cmd); + _exit(errno == ENOENT ? 127 : 126); } wait(&status); if (WIFEXITED(status) && WEXITSTATUS(status) == 255) - return -1; - return 0; + exit(124); }