[hackers] [sbase] Factor out waiting for children into a separate function || sin

From: <git_AT_suckless.org>
Date: Tue, 07 Jan 2014 15:52:36 +0100

commit 20c0a0b1e759d2bc171694c8e290146c60c61e31
Author: sin <sin_AT_2f30.org>
Date: Tue Jan 7 14:50:59 2014 +0000

    Factor out waiting for children into a separate function

diff --git a/xargs.c b/xargs.c
index b77c90f..77da254 100644
--- a/xargs.c
+++ b/xargs.c
_AT_@ -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;
_AT_@ -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)
_AT_@ -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();
+}
Received on Tue Jan 07 2014 - 15:52:36 CET

This archive was generated by hypermail 2.3.0 : Tue Jan 07 2014 - 16:00:12 CET