From b784f4eca6f97648df10e23ba843dcca308e6f3d Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Sun, 18 Jan 2015 00:20:38 +0100 Subject: [PATCH] parallel: --pipe --cat tested with csh. --- src/parallel | 51 ++++++++++++++----- testsuite/tests-to-run/parallel-local-ssh2.sh | 10 ++++ testsuite/wanted-results/parallel-local-ssh2 | 17 +++++++ testsuite/wanted-results/parallel-local12 | 4 +- testsuite/wanted-results/test15 | 8 +-- 5 files changed, 72 insertions(+), 18 deletions(-) diff --git a/src/parallel b/src/parallel index 99030e81..335dbf74 100755 --- a/src/parallel +++ b/src/parallel @@ -5710,6 +5710,32 @@ sub total_failed { return $total_failures; } +{ + my $script; + + sub postpone_exit_and_cleanup { + # Command to remove files and dirs (given as args) without + # affecting the exit value in $?/$status. + if(not $script) { + $script = "perl -e '". + ::spacefree(0,q{ + $bash=shift; + $csh=shift; + for(@ARGV){ + unlink; + rmdir; + } + if($bash=~s/h//) { + exit $bash; + } + exit $csh; + }). + "' ".'"$?h" "$status" '; + } + return $script + } +} + sub wrapped { # Wrap command with: # * --shellquote @@ -5754,22 +5780,23 @@ sub wrapped { } if($opt::cat) { # Prepend 'cat > {};' - # Append '_EXIT=$?;(rm {};exit $_EXIT)' + # Append 'unlink {} without affecting $?' $command = $self->{'commandline'}->replace_placeholders(["cat > \257<\257>; "], 0, 0). - $command. - $self->{'commandline'}->replace_placeholders( - ["; _EXIT=\$?; rm \257<\257>; exit \$_EXIT"], 0, 0); + $command.";". postpone_exit_and_cleanup(). + $self->{'commandline'}->replace_placeholders(["\257<\257>"], 0, 0); } elsif($opt::fifo) { # Prepend 'mkfifo {}; (' - # Append ') & _PID=$!; cat > {}; wait $_PID; _EXIT=$?;(rm {};exit $_EXIT)' + # Append ') & _PID=$!; cat > {}; wait $_PID; ' + # (This makes it fail in csh, but give the correct exit code in bash) + # Append 'unlink {} without affecting $?' $command = - $self->{'commandline'}->replace_placeholders(["mkfifo \257<\257>; ("], 0, 0). - $command. + $self->{'commandline'}->replace_placeholders(["mkfifo \257<\257>;\n ("], 0, 0). + $command.";". $self->{'commandline'}->replace_placeholders([") & _PID=\$!; cat > \257<\257>; ", - "wait \$_PID; _EXIT=\$?; ", - "rm \257<\257>; exit \$_EXIT"], - 0,0); + "wait \$_PID; "]). + postpone_exit_and_cleanup(). + $self->{'commandline'}->replace_placeholders(["\257<\257>"], 0, 0); } # Wrap with ssh + tranferring of files $command = $self->sshlogin_wrap($command); @@ -5872,7 +5899,7 @@ sub hex_zip_eval { } wait; eval $eval; - }); + }); ::debug("hex",$script,"\n"); return $script; } @@ -8551,4 +8578,4 @@ sub mkdir_or_die { # Keep perl -w happy $opt::ctrlc = $opt::x = $Semaphore::timeout = $Semaphore::wait = -$Job::file_descriptor_warning_printed = 0; +$opt::ignored_option = $Job::file_descriptor_warning_printed = 0; diff --git a/testsuite/tests-to-run/parallel-local-ssh2.sh b/testsuite/tests-to-run/parallel-local-ssh2.sh index fb4d140b..ddf9332e 100644 --- a/testsuite/tests-to-run/parallel-local-ssh2.sh +++ b/testsuite/tests-to-run/parallel-local-ssh2.sh @@ -44,4 +44,14 @@ echo '### bug #42999: --pipepart with remote does not work' parallel --sshdelay 0.2 --pipepart --block 31 -a /tmp/bug42999 -k --fifo -S parallel@lo wc | perl -pe s:/tmp/.........pip:/tmp/XXXX: ; parallel --sshdelay 0.1 --pipepart --block 31 -a /tmp/bug42999 -k --cat -S parallel@lo wc | perl -pe s:/tmp/.........pip:/tmp/XXXX: ; +echo '### --cat gives incorrect exit value in csh' + echo false | parallel --pipe --cat -Scsh@lo 'cat {}; false' ; echo $?; + echo false | parallel --pipe --cat -Stcsh@lo 'cat {}; false' ; echo $?; + echo true | parallel --pipe --cat -Scsh@lo 'cat {}; true' ; echo $?; + echo true | parallel --pipe --cat -Stcsh@lo 'cat {}; true' ; echo $?; + +echo '### --cat and --fifo exit value in bash' + echo true | parallel --pipe --fifo -Slo 'cat {}; true' ; echo $?; + echo false | parallel --pipe --fifo -Slo 'cat {}; false' ; echo $?; + EOF diff --git a/testsuite/wanted-results/parallel-local-ssh2 b/testsuite/wanted-results/parallel-local-ssh2 index ab7f2fe4..60d3572d 100644 --- a/testsuite/wanted-results/parallel-local-ssh2 +++ b/testsuite/wanted-results/parallel-local-ssh2 @@ -72,3 +72,20 @@ echo '### bug #42999: --pipepart with remote does not work' 11 11 33 /tmp/XXXX 11 11 33 /tmp/XXXX 10 9 29 /tmp/XXXX +echo '### --cat gives incorrect exit value in csh' +### --cat gives incorrect exit value in csh + echo false | parallel --pipe --cat -Scsh@lo 'cat {}; false' ; echo $?; echo false | parallel --pipe --cat -Stcsh@lo 'cat {}; false' ; echo $?; echo true | parallel --pipe --cat -Scsh@lo 'cat {}; true' ; echo $?; echo true | parallel --pipe --cat -Stcsh@lo 'cat {}; true' ; echo $?; echo '### --cat and --fifo exit value in bash' +false +1 +false +1 +true +0 +true +0 +### --cat and --fifo exit value in bash + echo true | parallel --pipe --fifo -Slo 'cat {}; true' ; echo $?; echo false | parallel --pipe --fifo -Slo 'cat {}; false' ; echo $?; +true +0 +false +1 diff --git a/testsuite/wanted-results/parallel-local12 b/testsuite/wanted-results/parallel-local12 index f71f0146..8f50d890 100644 --- a/testsuite/wanted-results/parallel-local12 +++ b/testsuite/wanted-results/parallel-local12 @@ -8,7 +8,7 @@ When using programs that use GNU Parallel to process data for publication please This helps funding further development; and it won't cost you a cent. If you pay 10000 EUR you should feel free to use GNU Parallel without citing. -To silence this citation notice run 'parallel --bibtex' once or use '--no-notice'. +To silence this citation notice run 'parallel --bibtex' once or use '--will-cite'. cat - via first cat @@ -24,7 +24,7 @@ When using programs that use GNU Parallel to process data for publication please This helps funding further development; and it won't cost you a cent. If you pay 10000 EUR you should feel free to use GNU Parallel without citing. -To silence this citation notice run 'parallel --bibtex' once or use '--no-notice'. +To silence this citation notice run 'parallel --bibtex' once or use '--will-cite'. echo a a diff --git a/testsuite/wanted-results/test15 b/testsuite/wanted-results/test15 index b0dd8f80..d63325ac 100644 --- a/testsuite/wanted-results/test15 +++ b/testsuite/wanted-results/test15 @@ -9,7 +9,7 @@ When using programs that use GNU Parallel to process data for publication please This helps funding further development; and it won't cost you a cent. If you pay 10000 EUR you should feel free to use GNU Parallel without citing. -To silence this citation notice run 'parallel --bibtex' once or use '--no-notice'. +To silence this citation notice run 'parallel --bibtex' once or use '--will-cite'. sleep 0.1; echo opt-p 1 ?...y sleep 0.1; echo opt-p 2 ?...n @@ -25,7 +25,7 @@ When using programs that use GNU Parallel to process data for publication please This helps funding further development; and it won't cost you a cent. If you pay 10000 EUR you should feel free to use GNU Parallel without citing. -To silence this citation notice run 'parallel --bibtex' once or use '--no-notice'. +To silence this citation notice run 'parallel --bibtex' once or use '--will-cite'. sleep 0.1; echo opt--interactive 1 ?...y sleep 0.1; echo opt--interactive 2 ?...n @@ -267,7 +267,7 @@ When using programs that use GNU Parallel to process data for publication please This helps funding further development; and it won't cost you a cent. If you pay 10000 EUR you should feel free to use GNU Parallel without citing. -To silence this citation notice run 'parallel --bibtex' once or use '--no-notice'. +To silence this citation notice run 'parallel --bibtex' once or use '--will-cite'. 3 1 @@ -287,7 +287,7 @@ When using programs that use GNU Parallel to process data for publication please This helps funding further development; and it won't cost you a cent. If you pay 10000 EUR you should feel free to use GNU Parallel without citing. -To silence this citation notice run 'parallel --bibtex' once or use '--no-notice'. +To silence this citation notice run 'parallel --bibtex' once or use '--will-cite'. 1 3