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.
This commit is contained in:
parent
9a1c5783c1
commit
7ec616e1e5
15
xargs.c
15
xargs.c
@ -1,4 +1,5 @@
|
|||||||
/* See LICENSE file for copyright and license details. */
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -19,7 +20,7 @@ static int parsequote(int);
|
|||||||
static void parseescape(void);
|
static void parseescape(void);
|
||||||
static char *poparg(void);
|
static char *poparg(void);
|
||||||
static void pusharg(char *);
|
static void pusharg(char *);
|
||||||
static int runcmd(void);
|
static void runcmd(void);
|
||||||
|
|
||||||
static char **cmd;
|
static char **cmd;
|
||||||
static char *argb;
|
static char *argb;
|
||||||
@ -85,11 +86,7 @@ main(int argc, char *argv[])
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
cmd[i] = NULL;
|
cmd[i] = NULL;
|
||||||
if (i == 1 && rflag == 1)
|
if (i == 1 && rflag == 1); else runcmd();
|
||||||
;
|
|
||||||
else
|
|
||||||
if (runcmd() == -1)
|
|
||||||
arg = NULL;
|
|
||||||
for (; i >= 0; i--)
|
for (; i >= 0; i--)
|
||||||
free(cmd[i]);
|
free(cmd[i]);
|
||||||
} while (arg);
|
} while (arg);
|
||||||
@ -221,7 +218,7 @@ pusharg(char *arg)
|
|||||||
deinputc(*p);
|
deinputc(*p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static void
|
||||||
runcmd(void)
|
runcmd(void)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
@ -233,9 +230,9 @@ runcmd(void)
|
|||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
execvp(*cmd, cmd);
|
execvp(*cmd, cmd);
|
||||||
eprintf("execvp %s:", *cmd);
|
eprintf("execvp %s:", *cmd);
|
||||||
|
_exit(errno == ENOENT ? 127 : 126);
|
||||||
}
|
}
|
||||||
wait(&status);
|
wait(&status);
|
||||||
if (WIFEXITED(status) && WEXITSTATUS(status) == 255)
|
if (WIFEXITED(status) && WEXITSTATUS(status) == 255)
|
||||||
return -1;
|
exit(124);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user