Factor out waiting for children into a separate function
This commit is contained in:
parent
e27c55aec3
commit
20c0a0b1e7
33
xargs.c
33
xargs.c
@ -20,6 +20,7 @@ static int parsequote(int);
|
||||
static int parseescape(void);
|
||||
static char *poparg(void);
|
||||
static void pusharg(char *);
|
||||
static void waitchld(void);
|
||||
static void runcmd(void);
|
||||
|
||||
static char **cmd;
|
||||
@ -232,20 +233,10 @@ pusharg(char *arg)
|
||||
}
|
||||
|
||||
static void
|
||||
runcmd(void)
|
||||
waitchld(void)
|
||||
{
|
||||
pid_t pid;
|
||||
int status, saved_errno;
|
||||
int status;
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0)
|
||||
eprintf("fork:");
|
||||
if (pid == 0) {
|
||||
execvp(*cmd, cmd);
|
||||
saved_errno = errno;
|
||||
weprintf("execvp %s:", *cmd);
|
||||
_exit(saved_errno == ENOENT ? 127 : 126);
|
||||
}
|
||||
wait(&status);
|
||||
if (WIFEXITED(status)) {
|
||||
if (WEXITSTATUS(status) == 255)
|
||||
@ -259,3 +250,21 @@ runcmd(void)
|
||||
if (WIFSIGNALED(status))
|
||||
exit(125);
|
||||
}
|
||||
|
||||
static void
|
||||
runcmd(void)
|
||||
{
|
||||
pid_t pid;
|
||||
int saved_errno;
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0)
|
||||
eprintf("fork:");
|
||||
if (pid == 0) {
|
||||
execvp(*cmd, cmd);
|
||||
saved_errno = errno;
|
||||
weprintf("execvp %s:", *cmd);
|
||||
_exit(saved_errno == ENOENT ? 127 : 126);
|
||||
}
|
||||
waitchld();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user