parallel: Bash aliases only visible if exec'ed as a single command - not a string.

This commit is contained in:
Ole Tange 2016-08-03 23:58:52 +02:00
parent b9470f8964
commit f8467c9a6b

View file

@ -6439,7 +6439,7 @@ sub empty_input_wrapper {
my $script =
::spacefree(0,q{
if(sysread(STDIN, $buf, 1)) {
open($fh, "|-", "@ARGV") || die;
open($fh, "|-", @ARGV) || die;
syswrite($fh, $buf);
# Align up to 128k block
if($read = sysread(STDIN, $buf, 131071)) {
@ -6454,7 +6454,7 @@ sub empty_input_wrapper {
});
::debug("run",'Empty wrap: perl -e '.::shell_quote_scalar($script)."\n");
return 'perl -e '.::shell_quote_scalar($script)." ".
::shell_quote_scalar($Global::shell." -c ".::shell_quote_scalar($command));
$Global::shell." -c ".::shell_quote_scalar($command);
}
sub filter_through_compress {
@ -7411,7 +7411,7 @@ sub sshreturn {
$nobasedir =~ s:.*/\./::;
$cd = ::shell_quote_file(::dirname($nobasedir));
my $rsync_cd = '--rsync-path='.::shell_quote_scalar("cd $wd$cd; rsync");
my $basename = ::shell_quote_scalar(::shell_quote_file(basename($file)));
my $basename = ::shell_quote_scalar(::shell_quote_file(::basename($file)));
# --return
# mkdir -p /home/tange/dir/subdir/;
# rsync (--protocol 30) -rlDzR --rsync-path="cd /home/tange/dir/subdir/; rsync"
@ -7549,7 +7549,7 @@ sub start {
if(not $pid = ::open3($stdin_fh, ">&OUT", ">&ERR", "-")) {
# Each child gets its own process group to make it safe to killall
setpgrp(0,0) || ::die_bug("setpgrp failed");
exec("exec $Global::shell -c ".::shell_quote_scalar_default($command))
exec($Global::shell,"-c",$command)
|| ::die_bug("open3-$stdin_fh $command");
}
};
@ -7587,24 +7587,32 @@ sub start {
sub open3_setpgrp {
# Select and run open3_setpgrp_internal/open3_setpgrp_external
# parallel -j0 --timeout 5 '( (sleep {}) & )& sleep 7' ::: {1..55} &
# ps -opid,ppid,pgrp,cmd
# parallel --timeout 6 -q perl -e 'sleep(1);if(fork()){sleep(30)}while(not fork and $t++<30000){ }' ::: 1
# perl -e 'sleep(1);if(fork()){sleep(3)}while(not fork and time-$^T<8){ }'
no warnings 'redefine';
my ($outfh,$name) = ::tmpfile(SUFFIX => ".tst");
# Test to see if open3(x,x,x,"-") is supported
my $script = 'if(not $pid=::open3($i,$o,$e,"-")) { unlink shift }';
qx{ perl -MIPC::Open3 -e '$script' $name 2>/dev/null };
# Test to see if open3(x,x,x,"-") is fully supported
# Can an exported bash function be called via open3?
my $script = 'if($pid=::open3($i,$o,$e,"-")) { wait; } '.
'else { exec("bash","-c","testfun && true"); }';
my $bash =
::shell_quote_scalar_default(
"testfun() { rm $name; }; export -f testfun; ".
"perl -MIPC::Open3 -e ".
::shell_quote_scalar_default($script)
);
::debug("init",qq{bash -c $bash 2>/dev/null});
qx{ bash -c $bash 2>/dev/null };
if(-e $name) {
# Does not support open3(x,x,x,"-")
# or does not have bash:
# Use (slow) external version
unlink($name);
*open3_setpgrp = \&open3_setpgrp_external;
::debug("init","open3_setpgrp_external chosen\n");
} else {
# Supports open3(x,x,x,"-")
# This is 0.5 ms faster to run
*open3_setpgrp = \&open3_setpgrp_internal;
::debug("init","open3_setpgrp_internal chosen\n");
}
# The sub is now redefined. Call it
return open3_setpgrp(@_);