]> err.no Git - moreutils/commitdiff
pee: Propigate exit status of commands run.
authorJoey Hess <joey@kitenet.net>
Sat, 19 Feb 2011 21:35:32 +0000 (17:35 -0400)
committerJoey Hess <joey@kitenet.net>
Sat, 19 Feb 2011 21:35:32 +0000 (17:35 -0400)
debian/changelog
pee.c

index 6d41dffd08a9e8e5dbf40bba4f0f3ca6fdafa2da..66f923c8256d93f967e201ee5c776a9eb268c6f6 100644 (file)
@@ -1,3 +1,9 @@
+moreutils (0.44) UNRELEASED; urgency=low
+
+  * pee: Propigate exit status of commands run.
+
+ -- Joey Hess <joeyh@debian.org>  Sat, 19 Feb 2011 17:34:50 -0400
+
 moreutils (0.43) unstable; urgency=low
 
   * chronic: New command, runs a command quietly, unless it fails.
diff --git a/pee.c b/pee.c
index 6ba38f78da10b61c8670b1c450fa769248ef84c4..cd3ff200de1114e67f54623bd023520d07364e56 100644 (file)
--- a/pee.c
+++ b/pee.c
@@ -1,5 +1,7 @@
 #include <stdlib.h>
 #include <stdio.h>
+#include <sys/types.h>
+#include <sys/wait.h>
 
 /* Licensed under the GPL
  * Copyright (c) Miek Gieben, 2006
  * pipes _and_ output to standard output
  */
 
-void
+int
 close_pipes(FILE **p, size_t i) 
 {
+       int ret=EXIT_SUCCESS;
        size_t j;
-       for (j = 0; j < i; j++) 
-               pclose(p[j]);
+       for (j = 0; j < i; j++) {
+               int r = pclose(p[j]);
+               if (WIFEXITED(r))
+                       ret |= WEXITSTATUS(r);
+               else
+                       ret |= 1;
+       }
+       return ret;
 }
 
 int
@@ -48,7 +57,5 @@ main(int argc, char **argv) {
                        }
                }
        }
-       close_pipes(pipes, argc);
-
-       exit(EXIT_SUCCESS);
+       exit(close_pipes(pipes, argc));
 }