]> err.no Git - moreutils/commitdiff
Return non-zero if something goes wrong
authorTollef Fog Heen <tfheen@err.no>
Tue, 30 Jun 2009 02:26:16 +0000 (04:26 +0200)
committerTollef Fog Heen <tfheen@err.no>
Tue, 30 Jun 2009 02:26:16 +0000 (04:26 +0200)
The return code of parallel is the OR-ed exit status of all the
children, with 1 being OR-ed in if any child is killed.

parallel.c

index 09588d6a37b68a04006fe07ce382f50262f72760..c03d2e1d5129cee5b921072d07103c7cf2225254 100644 (file)
@@ -61,6 +61,16 @@ void exec_child(char **command, char *argument)
        return;
 }
 
+int wait_for_child(void)
+{
+       id_t id_ignored = 0;
+       siginfo_t infop;
+       waitid(P_ALL, id_ignored, &infop, WEXITED);
+       if (infop.si_code == CLD_EXITED)
+               return infop.si_status;
+       return 1;
+}
+
 int main(int argc, char **argv)
 {
        int maxjobs = -1;
@@ -71,6 +81,7 @@ int main(int argc, char **argv)
        char **arguments;
        int argidx = 0;
        int cidx = 0;
+       int returncode = 0;
 
        while ((opt = getopt(argc, argv, "+hj:l:")) != -1) {
                switch (opt) {
@@ -126,19 +137,15 @@ int main(int argc, char **argv)
                }
 
                if (maxjobs > 0 && curjobs == maxjobs) {
-                       id_t id_ignored;
-                       siginfo_t infop_ignored;
-                       waitid(P_ALL, id_ignored, &infop_ignored, WEXITED);
+                       returncode |= wait_for_child();
                        curjobs--;
                }
        }
        while (curjobs > 0) {
-               id_t id_ignored;
-               siginfo_t infop_ignored;
-               waitid(P_ALL, id_ignored, &infop_ignored, WEXITED);
+               returncode |= wait_for_child();
                curjobs--;
        }
 
-       return 0;
+       return returncode;
 }