ctdb-tools: Reformat and explain complex code
authorMartin Schwenke <martin@meltin.net>
Wed, 9 Aug 2017 07:11:18 +0000 (17:11 +1000)
committerAmitay Isaacs <amitay@samba.org>
Mon, 14 Aug 2017 03:15:25 +0000 (05:15 +0200)
There are multiple command groups and redirects on very long lines.
Reformat the long lines to break them up and add a comment to explain
what is happening.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tools/onnode

index b3efe91c85b5ff179d8403649bd4e68901f99db1..8da40d2bd2155b6285c8e5a6828d78a59452f855 100755 (executable)
@@ -359,15 +359,34 @@ trap 'kill -TERM $pids 2>/dev/null' INT TERM
 retcode=0
 for n in $nodes ; do
     set -o pipefail 2>/dev/null
+
+    # The following code applies stdout_filter and stderr_filter to
+    # the relevant streams.  Both filters are at the end of pipes so
+    # they read from stdin and (by default) write to stdout.  To allow
+    # the filters to operate independently, the output of
+    # stdout_filter is sent to a temporary file descriptor (3), which
+    # is redirected back to stdout at the outermost level.
     if $parallel ; then
-       { exec 3>&1 ; { $SSH $ssh_opts $EXTRA_SSH_OPTS "$n" "$command" | stdout_filter >&3 ; } 2>&1 | stderr_filter ; } &
+       {
+           exec 3>&1
+           {
+               $SSH $ssh_opts $EXTRA_SSH_OPTS "$n" "$command" |
+                   stdout_filter >&3
+           } 2>&1 | stderr_filter
+       } &
        pids="${pids} $!"
     else
        if $verbose ; then
            echo >&2 ; echo ">> NODE: $n <<" >&2
        fi
 
-       { exec 3>&1 ; { $SSH $ssh_opts $EXTRA_SSH_OPTS "$n" "$command" | stdout_filter >&3 ; } 2>&1 | stderr_filter ; }
+       {
+           exec 3>&1
+           {
+               $SSH $ssh_opts $EXTRA_SSH_OPTS "$n" "$command" |
+                   stdout_filter >&3
+           } 2>&1 | stderr_filter
+       }
        [ $? = 0 ] || retcode=$?
     fi
 done