chiark / gitweb /
check, rcheck: Propagate exit status better; capture lines more precisely.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 15 Apr 2015 16:05:22 +0000 (17:05 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 15 Apr 2015 16:05:22 +0000 (17:05 +0100)
check
rcheck

diff --git a/check b/check
index 92965e3..74c7f80 100755 (executable)
--- a/check
+++ b/check
@@ -4,17 +4,26 @@
 
 set -e
 
+exec 4>&1
+rc=0
 for check in check.d/[!#]*[!~]; do
-  { { { set +e; "$check"; rc=$?; set -e
-       case $rc in 0) ;; *) echo >&2 "failed (rc = $rc)" ;; esac
-    } >&3; } 2>&1 |
-    sed 's/^/E: /'
-  } 3>&1 | {
-    if read line; then
-      echo "## ${check##*/}"
-      echo "$line"
-      cat
-      echo
-    fi
-  }
+  nrc=$(
+    exec 5>&1
+    { { { set +e; "$check"; rc=$?; set -e
+         echo $rc >&5
+         case $rc in 0) ;; *) echo >&2 "failed (rc = $rc)" ;; esac
+      } >&3; } 2>&1 |
+      sed 's/^/E: /'
+    } 3>&1 | {
+      if IFS= read -r line; then
+       echo "## ${check##*/}"
+       echo "$line"
+       cat
+       echo
+      fi
+    } >&4
+  )
+  if [ $nrc -gt $rc ]; then rc=$nrc; fi
 done
+
+exit $rc
diff --git a/rcheck b/rcheck
index cd40440..318aab6 100755 (executable)
--- a/rcheck
+++ b/rcheck
@@ -12,11 +12,15 @@ do
   prog=$(readlink "${prog##*/}")
 done
 
+exec 4>&1
+rc=0
 for host in "$@"; do
 
-  { { { set +e
-       tar czf - check check.d |
-       ssh "$host" '
+  nrc=$(
+    exec 5>&1
+    { { { set +e
+         tar czf - check check.d |
+         ssh "$host" '
 set -e
 cd /tmp
 
@@ -34,21 +38,25 @@ cd $tmpdir
 
 tar xzf -
 ./check'
-       rc=$?; set -e
-       case $rc in
-         0) ;;
-         *) echo >&2 "remote check process failed (rc = $rc)" ;;
-       esac
-      } 1>&3; } 2>&1 |
-    sed 's/^/!!! /'
-  } 3>&1 |
-  if read line; then
-    cat <<EOF
+         rc=$?; set -e; echo $rc >&5
+         case $rc in
+           0) ;;
+           *) echo >&2 "remote check process failed (rc = $rc)" ;;
+         esac
+       } 1>&3; } 2>&1 |
+      sed 's/^/!!! /'
+    } 3>&1 |
+    if IFS= read -r line; then
+      cat <<EOF
 ###--------------------------------------------------------------------------
 ### $host
 
 $line
 EOF
-    cat
-  fi
+      cat
+    fi >&4
+  )
+  if [ $nrc -gt $rc ]; then rc=$nrc; fi
 done
+
+exit $rc