From 95eb81b901a6dcf98ce54089f3acde7d618e70dc Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Wed, 14 Oct 2020 22:49:58 +0200 Subject: [PATCH] Fixed bug #59146: Support --termseq for remote jobs. --- src/parallel | 14 +++++++++-- testsuite/tests-to-run/parallel-local-ssh6.sh | 34 +++++++++++++++++++++++++++ testsuite/wanted-results/parallel-local-ssh6 | 34 +++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 2 deletions(-) diff --git a/src/parallel b/src/parallel index eb151258..3f719392 100755 --- a/src/parallel +++ b/src/parallel @@ -9063,6 +9063,7 @@ sub sshlogin_wrap($) { ::spacefree(0,'$shell = "'.($ENV{'PARALLEL_SHELL'} || '$ENV{SHELL}').'";'. '$tmpdir = "'.::perl_quote_scalar($ENV{'TMPDIR'}).'";'. '$nice = '.$opt::nice.';'. + '$termseq = "'.$opt::termseq.'";'. q{ # Set $PARALLEL_TMP to a non-existent file name in $TMPDIR do { @@ -9084,8 +9085,17 @@ sub sshlogin_wrap($) { $s = $s < 1 ? 0.001 + $s * 1.03 : $s; select(undef, undef, undef, $s); } until ($done || getppid == 1); - # Kill HUP the process group if job not done - kill(SIGHUP, -${pid}) unless $done; + if(not $done) { + # Kill as per --termseq + my @term_seq = split/,/,$termseq; + if(not @term_seq) { + @term_seq = ("TERM",200,"TERM",100,"TERM",50,"KILL",25); + } + while(@term_seq && kill(0,-$pid)) { + kill(shift @term_seq, -$pid); + select(undef, undef, undef, (shift @term_seq)/1000); + } + } wait; exit ($?&127 ? 128+($?&127) : 1+$?>>8) }); diff --git a/testsuite/tests-to-run/parallel-local-ssh6.sh b/testsuite/tests-to-run/parallel-local-ssh6.sh index 9761000e..38631bb4 100644 --- a/testsuite/tests-to-run/parallel-local-ssh6.sh +++ b/testsuite/tests-to-run/parallel-local-ssh6.sh @@ -6,6 +6,40 @@ export SSHLOGIN1=parallel@lo export SSHLOGIN2=csh@lo mkdir -p tmp +par_termseq_remote() { + echo '### bug #59146: Support --termseq for remote jobs' + doit() { + # setup signal handlers for all signals + exec perl -e ' + $file = shift; + for $i (qw( + HUP INT QUIT ILL TRAP + ABRT BUS FPE KILL USR1 + SEGV USR2 PIPE ALRM TERM + STKFLT CHLD CONT STOP TSTP + TTIN TTOU URG XCPU XFSZ + VTALRM PROF WINCH IO PWR + SYS RTMIN RTMIN+1 RTMIN+2 RTMIN+3 + RTMIN+4 RTMIN+5 RTMIN+6 RTMIN+7 RTMIN+8 + RTMIN+9 RTMIN+10 RTMIN+11 RTMIN+12 RTMIN+13 + RTMIN+14 RTMIN+15 RTMAX-14 RTMAX-13 RTMAX-12 + RTMAX-11 RTMAX-10 RTMAX-9 RTMAX-8 RTMAX-7 + RTMAX-6 RTMAX-5 RTMAX-4 RTMAX-3 RTMAX-2 + RTMAX-1 RTMAX + )) { + eval q[$SIG{].$i.q[}=sub{open(A,">>$file");print A "].$i.q[\n";};]; + } + for(1..100) { sleep(1);} + ' $file + } + file=/tmp/sig$$ + . `which env_parallel.bash` + env_parallel -v --timeout 2 --termseq HUP,30,INT,30,QUIT,30,ILL,30,TRAP,30,ABRT,30,BUS,30,FPE,30,USR1,30,SEGV,30,USR2,30,PIPE,30,ALRM,30,TERM,30,STKFLT,30,CHLD,30,CONT,30,TSTP,30,TTIN,30,TTOU,30,URG,30,XCPU,30,XFSZ,30,VTALRM,30,PROF,30,WINCH,30,IO,30,PWR,30,SYS,30,RTMIN,30,RTMAX,30,KILL,9 -S $SSHLOGIN1 doit ::: 1 + sleep 1 + cat $file + ssh $SSHLOGIN1 rm $file +} + par_nonall_ssh() { echo 'bug #59181: --ssh is not propagated to --nonall' parallel --ssh 'echo OK | ssh' -S $SSHLOGIN1 --nonall cat diff --git a/testsuite/wanted-results/parallel-local-ssh6 b/testsuite/wanted-results/parallel-local-ssh6 index 5f294ca0..475bb7e2 100644 --- a/testsuite/wanted-results/parallel-local-ssh6 +++ b/testsuite/wanted-results/parallel-local-ssh6 @@ -34,6 +34,40 @@ par_rsync_3.2.3 bug59006 par_sshlogin_replacement ### show {sshlogin} and {host} par_sshlogin_replacement parallel@lo and lo par_sshlogin_replacement /usr/bin/ssh parallel@lo and lo +par_termseq_remote ### bug #59146: Support --termseq for remote jobs +par_termseq_remote parallel: Warning: This job was killed because it timed out: +par_termseq_remote parallel: Warning: doit 1 +par_termseq_remote doit 1 +par_termseq_remote HUP +par_termseq_remote INT +par_termseq_remote QUIT +par_termseq_remote ILL +par_termseq_remote TRAP +par_termseq_remote ABRT +par_termseq_remote BUS +par_termseq_remote FPE +par_termseq_remote USR1 +par_termseq_remote SEGV +par_termseq_remote USR2 +par_termseq_remote PIPE +par_termseq_remote ALRM +par_termseq_remote TERM +par_termseq_remote STKFLT +par_termseq_remote CHLD +par_termseq_remote CONT +par_termseq_remote TSTP +par_termseq_remote TTIN +par_termseq_remote TTOU +par_termseq_remote URG +par_termseq_remote XCPU +par_termseq_remote XFSZ +par_termseq_remote VTALRM +par_termseq_remote PROF +par_termseq_remote WINCH +par_termseq_remote IO +par_termseq_remote PWR +par_termseq_remote SYS +par_termseq_remote RTMIN par_test_nonall ### Test --nonall par_test_nonall /home/csh par_test_nonall /home/parallel -- 2.11.4.GIT