diff --git a/doc/pdsh.1.in b/doc/pdsh.1.in index ccd529d4..d4d7f0d2 100644 --- a/doc/pdsh.1.in +++ b/doc/pdsh.1.in @@ -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. diff --git a/src/pdsh/dsh.c b/src/pdsh/dsh.c index 1957421b..cad8d41d 100644 --- a/src/pdsh/dsh.c +++ b/src/pdsh/dsh.c @@ -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"); } diff --git a/src/pdsh/opt.c b/src/pdsh/opt.c index 790fa2db..44b85dc2 100644 --- a/src/pdsh/opt.c +++ b/src/pdsh/opt.c @@ -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 @@ -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" @@ -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); diff --git a/tests/t2001-ssh.sh b/tests/t2001-ssh.sh index 44efe73c..a9dddb07 100755 --- a/tests/t2001-ssh.sh +++ b/tests/t2001-ssh.sh @@ -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