bug #55399: Clean up --wd ... when run locally.

bug #55398: set $OLDPWD when using --wd.
This commit is contained in:
Ole Tange 2019-01-06 13:45:43 +01:00
parent 48b1743b84
commit e79d1d978b
6 changed files with 49 additions and 51 deletions

View file

@ -199,51 +199,25 @@ http://groups.google.com/group/comp.unix.admin/post
https://lists.gnu.org/mailman/admindb/bug-parallel https://lists.gnu.org/mailman/admindb/bug-parallel
https://lists.gnu.org/mailman/admindb/parallel https://lists.gnu.org/mailman/admindb/parallel
<<<<<
file:///home/tange/privat/parallel/doc/release_new_version file:///home/tange/privat/parallel/doc/release_new_version
from:tange@gnu.org from:tange@gnu.org
to:parallel@gnu.org, bug-parallel@gnu.org to:parallel@gnu.org, bug-parallel@gnu.org
stable-bcc: Jesse Alama <jessealama@fastmail.fm> stable-bcc: Jesse Alama <jessealama@fastmail.fm>
<<<<<<< HEAD Subject: GNU Parallel 20190122 ('Indonesia=Tanjung Lesung=Sunda') released <<[stable]>>
Subject: GNU Parallel 20190122 ('Indonesia=Tanjung Lesung=Sunda ') released <<[stable]>>
GNU Parallel 20190122 ('') <<[stable]>> has been released. It is available for download at: http://ftpmirror.gnu.org/parallel/ GNU Parallel 20190122 ('') <<[stable]>> has been released. It is available for download at: http://ftpmirror.gnu.org/parallel/
=======
Subject: GNU Parallel 20181222 ('Yellow Jacket/InSight/Jacob Sparre') released <<[stable]>>
GNU Parallel 20181222 ('Jacob Sparre') <<[stable]>> has been released. It is available for download at: http://ftpmirror.gnu.org/parallel/
>>>>>>> 41a40a1304b92206859d061fa1bb2e22d9cfc196
<<No new functionality was introduced so this is a good candidate for a stable release.>> <<No new functionality was introduced so this is a good candidate for a stable release.>>
Quote of the month: Quote of the month:
<<<<<<< HEAD
<<>> <<>>
New in this release: New in this release:
* * Using GNU Parallel in pentesting https://youtu.be/mZ0OUJmkIlA?t=873
=======
GNU parallel is a seriously powerful flexible and tool.
-- Greg Hurrell @wincent
New in this release:
* Better /proc/cpuinfo parser.
* Simpler job scheduling flow.
* MPGI Workshop: Job Parallelization with Task Arrays and GNU Parallel https://www.msi.umn.edu/tutorials/mpgi-workshop-module-4
* CONCOCT uses GNU Parallel https://media.readthedocs.org/pdf/concoct/latest/concoct.pdf
* If you use SLURM read https://wiki.hpc.uconn.edu/index.php/Advanced_SLURM
* すぐ忘れてしまう、仕事で使う技 https://qiita.com/hana_shin/items/53c3c78525c9c758ae7c
>>>>>>> 41a40a1304b92206859d061fa1bb2e22d9cfc196
* Bug fixes and man page updates. * Bug fixes and man page updates.

View file

@ -1516,6 +1516,7 @@ sub init_globals() {
$Global::max_jobs_running = 0; $Global::max_jobs_running = 0;
$Global::job_already_run = ''; $Global::job_already_run = '';
$ENV{'TMPDIR'} ||= "/tmp"; $ENV{'TMPDIR'} ||= "/tmp";
$ENV{'OLDPWD'} = $ENV{'PWD'};
if(not $ENV{HOME}) { if(not $ENV{HOME}) {
# $ENV{HOME} is sometimes not set if called from PHP # $ENV{HOME} is sometimes not set if called from PHP
::warning("\$HOME not set. Using /tmp."); ::warning("\$HOME not set. Using /tmp.");
@ -2165,7 +2166,6 @@ sub cleanup() {
sub __QUOTING_ARGUMENTS_FOR_SHELL__() {} sub __QUOTING_ARGUMENTS_FOR_SHELL__() {}
sub shell_quote(@) { sub shell_quote(@) {
# Input: # Input:
# @strings = strings to be quoted # @strings = strings to be quoted
@ -2285,7 +2285,7 @@ sub shell_quote_file($) {
return Q($a); return Q($a);
} }
sub shell_words() { sub shell_words(@) {
# Input: # Input:
# $string = shell line # $string = shell line
# Returns: # Returns:
@ -2307,6 +2307,7 @@ sub perl_quote_scalar($) {
return $a; return $a;
} }
# -w complains about prototype
sub pQ($) { sub pQ($) {
# pQ alias for ::perl_quote_scalar # pQ alias for ::perl_quote_scalar
*pQ = \&::perl_quote_scalar; *pQ = \&::perl_quote_scalar;
@ -5007,6 +5008,7 @@ sub usleep($) {
select(undef, undef, undef, $ms/1000); select(undef, undef, undef, $ms/1000);
} }
sub __KILLER_REAPER__() {}
sub reap_usleep() { sub reap_usleep() {
# Reap dead children. # Reap dead children.
# If no dead children: Sleep specified amount with exponential backoff # If no dead children: Sleep specified amount with exponential backoff
@ -6955,7 +6957,7 @@ sub rsync_transfer_cmd($) {
rsync()." $rsync_opts $file $serverlogin:$rsync_destdir"; rsync()." $rsync_opts $file $serverlogin:$rsync_destdir";
} }
sub cleanup_cmd($) { sub cleanup_cmd($$$) {
# Command to run to remove the remote file # Command to run to remove the remote file
# Input: # Input:
# $file = filename to remove # $file = filename to remove
@ -8233,13 +8235,19 @@ sub sshlogin_wrap($) {
if($serverlogin eq ":") { if($serverlogin eq ":") {
if($opt::workdir) { if($opt::workdir) {
# Create workdir if needed. Then cd to it. # Create workdir if needed. Then cd to it.
my $wd = $self->workdir(); my $wd = $self->workdir();
if($opt::workdir eq "." or $opt::workdir eq "...") { if($opt::workdir eq "." or $opt::workdir eq "...") {
# If $wd does not start with '/': Prepend $HOME # If $wd does not start with '/': Prepend $HOME
$wd =~ s:^([^/]):$ENV{'HOME'}/$1:; $wd =~ s:^([^/]):$ENV{'HOME'}/$1:;
} }
::mkdir_or_die($wd); ::mkdir_or_die($wd);
$command = "cd ".::Q($wd)." || exit 255; ".$command; my $post = "";
if($opt::workdir eq "...") {
$post = ";".exitstatuswrapper("rm -rf ".::Q($wd).";");
}
$command = "cd ".::Q($wd)." || exit 255; " .
$command . $post;;
} }
if(@opt::env) { if(@opt::env) {
# Prepend with environment setter, which sets functions in zsh # Prepend with environment setter, which sets functions in zsh
@ -8299,7 +8307,7 @@ sub sshlogin_wrap($) {
$post .= $self->sshcleanup(); $post .= $self->sshcleanup();
if($post) { if($post) {
# We need to save the exit status of the job # We need to save the exit status of the job
$post = '_EXIT_status=$?; ' . $post . ' exit $_EXIT_status;'; $post = exitstatuswrapper($post);
} }
$self->{'sshlogin_wrap'}{$command} = $self->{'sshlogin_wrap'}{$command} =
($pre ($pre
@ -8449,7 +8457,7 @@ sub sshcleanup($) {
$cleancmd .= $sshlogin->cleanup_cmd($file,$workdir).";"; $cleancmd .= $sshlogin->cleanup_cmd($file,$workdir).";";
} }
if(defined $opt::workdir and $opt::workdir eq "...") { if(defined $opt::workdir and $opt::workdir eq "...") {
$cleancmd .= "$sshcmd $serverlogin -- rm -rf " . ::Q($workdir).';'; $cleancmd .= "$sshcmd $serverlogin -- rm -rf " . ::Q($workdir).';';
} }
return $cleancmd; return $cleancmd;
} }
@ -8467,6 +8475,19 @@ sub remote_cleanup($) {
} }
} }
sub exitstatuswrapper(@) {
if($Global::cshell) {
return ('set _EXIT_status=$status; ' .
join(" ",@_).
'exit $_EXIT_status;');
} else {
return ('_EXIT_status=$?; ' .
join(" ",@_).
'exit $_EXIT_status;');
}
}
sub workdir($) { sub workdir($) {
# Returns: # Returns:
# the workdir on a remote machine # the workdir on a remote machine
@ -10824,14 +10845,14 @@ package MultifileQueue;
@Global::unget_argv=(); @Global::unget_argv=();
sub new($) { sub new($$) {
my $class = shift; my $class = shift;
my $fhs = shift; my $fhs = shift;
for my $fh (@$fhs) { for my $fh (@$fhs) {
if(-t $fh and -t ($Global::status_fd || *STDERR)) { if(-t $fh and -t ($Global::status_fd || *STDERR)) {
::warning("Input is read from the terminal. You either know what you", ::warning("Input is read from the terminal. You either know what you",
"are doing (in which case: YOU ARE AWESOME!) or you forgot", "are doing (in which case: YOU ARE AWESOME!) or you forgot",
"::: or :::: or to pipe data into parallel. If so", "::: or :::: or -a or to pipe data into parallel. If so",
"consider going through the tutorial: man parallel_tutorial", "consider going through the tutorial: man parallel_tutorial",
"Press CTRL-D to exit."); "Press CTRL-D to exit.");
} }

View file

@ -892,6 +892,15 @@ par_halt_on_error_division_by_zero() {
echo $? echo $?
} }
par_wd_dotdotdot() {
echo '### parallel --wd ... should clean up'
parallel --wd ... 'pwd;true' ::: foo | parallel ls 2>/dev/null
echo $? == 1
echo '### $OLDPWD should be the dir in which parallel starts'
cd /tmp
parallel --wd ... 'echo $OLDPWD' ::: foo
}
export -f $(compgen -A function | grep par_) export -f $(compgen -A function | grep par_)
compgen -A function | grep par_ | LC_ALL=C sort | compgen -A function | grep par_ | LC_ALL=C sort |
parallel --timeout 20 -j6 --tag -k --joblog +/tmp/jl-`basename $0` '{} 2>&1' parallel --timeout 20 -j6 --tag -k --joblog +/tmp/jl-`basename $0` '{} 2>&1'

View file

@ -20,10 +20,10 @@ echo '### bug #39572: --tty and --joblog do not work'
seq 1 | parallel --joblog - -u true | tr '0-9' 'X' seq 1 | parallel --joblog - -u true | tr '0-9' 'X'
echo '### How do we deal with missing $HOME' echo '### How do we deal with missing $HOME'
unset HOME; stdout perl -w $(which parallel) -k echo ::: 1 2 3 unset HOME; stdout perl $(which parallel) -k echo ::: 1 2 3
echo '### How do we deal with missing $SHELL' echo '### How do we deal with missing $SHELL'
unset SHELL; stdout perl -w $(which parallel) -k echo ::: 1 2 3 unset SHELL; stdout perl $(which parallel) -k echo ::: 1 2 3
echo '### Test if length is computed correctly - first should give one line, second 2 lines each' echo '### Test if length is computed correctly - first should give one line, second 2 lines each'
seq 4 | parallel -s 29 -X -kj1 echo a{}b{}c seq 4 | parallel -s 29 -X -kj1 echo a{}b{}c

View file

@ -1690,3 +1690,7 @@ par_wd_3dot_local OK
par_wd_3dot_local ~/privat/parallel/testsuite par_wd_3dot_local ~/privat/parallel/testsuite
par_wd_3dot_local ~/privat/parallel/testsuite par_wd_3dot_local ~/privat/parallel/testsuite
par_wd_3dot_local OK par_wd_3dot_local OK
par_wd_dotdotdot ### parallel --wd ... should clean up
par_wd_dotdotdot 1 == 1
par_wd_dotdotdot ### $OLDPWD should be the dir in which parallel starts
par_wd_dotdotdot /tmp foo

View file

@ -91,24 +91,14 @@ Seq Host Starttime JobRuntime Send Receive Exitval Signal Command
X : XXXXXXXXXX.XXX X.XXX X X X X true X X : XXXXXXXXXX.XXX X.XXX X X X X true X
echo '### How do we deal with missing $HOME' echo '### How do we deal with missing $HOME'
### How do we deal with missing $HOME ### How do we deal with missing $HOME
unset HOME; stdout perl -w $(which parallel) -k echo ::: 1 2 3 unset HOME; stdout perl $(which parallel) -k echo ::: 1 2 3
main::shell_quote_scalar() called too early to check prototype at /usr/local/bin/parallel line 2299.
main::Q() called too early to check prototype at /usr/local/bin/parallel line 2306.
main::pQ() called too early to check prototype at /usr/local/bin/parallel line 2353.
Arg::Q() called too early to check prototype at /usr/local/bin/parallel line 11163.
Arg::pQ() called too early to check prototype at /usr/local/bin/parallel line 11169.
parallel: Warning: $HOME not set. Using /tmp. parallel: Warning: $HOME not set. Using /tmp.
1 1
2 2
3 3
echo '### How do we deal with missing $SHELL' echo '### How do we deal with missing $SHELL'
### How do we deal with missing $SHELL ### How do we deal with missing $SHELL
unset SHELL; stdout perl -w $(which parallel) -k echo ::: 1 2 3 unset SHELL; stdout perl $(which parallel) -k echo ::: 1 2 3
main::shell_quote_scalar() called too early to check prototype at /usr/local/bin/parallel line 2299.
main::Q() called too early to check prototype at /usr/local/bin/parallel line 2306.
main::pQ() called too early to check prototype at /usr/local/bin/parallel line 2353.
Arg::Q() called too early to check prototype at /usr/local/bin/parallel line 11163.
Arg::pQ() called too early to check prototype at /usr/local/bin/parallel line 11169.
1 1
2 2
3 3