Skip to content

Commit

Permalink
Merge pull request #144 from jerrymannil/fail-fast
Browse files Browse the repository at this point in the history
fail fast on connect error or non-zero return code
  • Loading branch information
mergify[bot] committed Jun 14, 2022
2 parents 139ef36 + c94c3ca commit 3bc95a8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
5 changes: 4 additions & 1 deletion doc/pdsh.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,13 @@ as if they had been given to \fB\-w\fR and preceeded with the minus `-'
character.

.SH "Standard pdsh options"
.TP
.TP
.I "-S"
Return the largest of the remote command return values.
.TP
.I "-k"
Fail fast on connect failure or non-zero return code.
.TP
.I "-h"
Output usage menu and quit. A list of available rcmd modules
will also be printed at the end of the usage message.
Expand Down
2 changes: 1 addition & 1 deletion src/pdsh/dsh.c
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ static void *_rsh_thread(void *args)
a->rc = rv;

/* if a single qshell thread fails, terminate whole job */
if (a->kill_on_fail && a->state == DSH_FAILED) {
if (a->kill_on_fail && ((a->state == DSH_FAILED) || (a->rc > 0))) {
_fwd_signal(SIGTERM);
errx("%p: terminating all processes\n");
}
Expand Down
10 changes: 7 additions & 3 deletions src/pdsh/opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@

#define OPT_USAGE_DSH "\
Usage: pdsh [-options] command ...\n\
-S return largest of remote command return values\n"
-S return largest of remote command return values\n\
-k fail fast on connect failure or non-zero return code\n"

/* -s option only useful on AIX */
#if HAVE_MAGIC_RSHELL_CLEANUP
Expand Down Expand Up @@ -113,9 +114,9 @@ Usage: rpdcp [-options] src [src2...] dir\n\
/* undocumented "-K" option - keep domain name in output */

#if HAVE_MAGIC_RSHELL_CLEANUP
#define DSH_ARGS "sS"
#define DSH_ARGS "sSk"
#else
#define DSH_ARGS "S"
#define DSH_ARGS "Sk"
#endif
#define PCP_ARGS "pryzZe:"
#define GEN_ARGS "hLNKR:M:t:cqf:w:x:l:u:bI:dVT:Q"
Expand Down Expand Up @@ -691,6 +692,9 @@ void opt_args(opt_t * opt, int argc, char *argv[])
else
goto test_module_option;
break;
case 'k':
opt->kill_on_fail = true;
break;
default: test_module_option:
if (mod_process_opt(opt, c, optarg) < 0)
_usage(opt);
Expand Down
15 changes: 15 additions & 0 deletions tests/t2001-ssh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,20 @@ test_expect_success 'ssh works with pdsh -S and multiple targets' '
done
'
unset PDSH_SSH_ARGS
test_expect_success 'ssh works with pdsh -k' '
TEST_EXIT_CODE=$(random 254) &&
export PDSH_SSH_ARGS="-n%n -i0 -e$TEST_EXIT_CODE"
test_expect_code "1" pdsh -Rssh -k -w foo0 command
'
unset PDSH_SSH_ARGS
test_expect_success 'ssh works with pdsh -k and multiple targets' '
for n in $(seq 1 24); do
TEST_EXIT_CODE=$(random 254) &&
FAILING_RANK=$(random $n) &&
export PDSH_SSH_ARGS="-n%n -i$FAILING_RANK -e$TEST_EXIT_CODE"
test_expect_code "1" pdsh -Rssh -k -wfoo[0-$n] command
done
'
unset PDSH_SSH_ARGS

test_done

0 comments on commit 3bc95a8

Please sign in to comment.