bug #35544: --pipe would read from :::: (-a)

This commit is contained in:
Ole Tange 2012-02-27 01:51:54 +01:00
parent 6f730374d8
commit bcebac44b1
3 changed files with 25 additions and 4 deletions

View file

@ -156,7 +156,7 @@ if($Global::semaphore) {
$SIG{TERM} = \&start_no_new_jobs; $SIG{TERM} = \&start_no_new_jobs;
start_more_jobs(); start_more_jobs();
if($::opt_pipe) { if($::opt_pipe) {
spreadstdin(); spreadstdin(@fhlist);
} }
reap_if_needed(); reap_if_needed();
::debug("Start draining\n"); ::debug("Start draining\n");
@ -177,6 +177,7 @@ sub __PIPE_MODE__ {}
sub spreadstdin { sub spreadstdin {
# read a record # read a record
# Spawn a job and print the record to it. # Spawn a job and print the record to it.
my @fhlist = @_; # Filehandles to read from (Defaults to STDIN)
my $record; my $record;
my $buf = ""; my $buf = "";
my $header = ""; my $header = "";
@ -220,7 +221,8 @@ sub spreadstdin {
my $recendrecstart = $recend.$recstart; my $recendrecstart = $recend.$recstart;
# Force the while-loop once if everything was read by header reading # Force the while-loop once if everything was read by header reading
my $force_one_time_through = 0; my $force_one_time_through = 0;
while(!$force_one_time_through++ or read(STDIN,substr($buf,length $buf,0),$::opt_blocksize)) { for my $in (@fhlist) {
while(!$force_one_time_through++ or read($in,substr($buf,length $buf,0),$::opt_blocksize)) {
# substr above = append to $buf # substr above = append to $buf
reap_if_needed(); # Re-enable reaping after read() (Bug#33352) reap_if_needed(); # Re-enable reaping after read() (Bug#33352)
if($::opt_r) { if($::opt_r) {
@ -269,13 +271,15 @@ sub spreadstdin {
} }
} }
} }
do_not_reap(); # Disable reaping before read(STDIN) (Bug#33352) do_not_reap(); # Disable reaping before read($in) (Bug#33352)
} }
}
# If there is anything left in the buffer write it # If there is anything left in the buffer write it
substr($buf,0,0) = $header; substr($buf,0,0) = $header;
write_record_to_pipe(\$buf,$recstart,$recend); write_record_to_pipe(\$buf,$recstart,$recend);
::debug("Done reading STDIN\n"); ::debug("Done reading input\n");
flush_and_close_pipes(); flush_and_close_pipes();
::debug("Done flushing to children\n"); ::debug("Done flushing to children\n");
$Global::start_no_new_jobs = 1; $Global::start_no_new_jobs = 1;

View file

@ -43,4 +43,8 @@ echo '### Test --wd .';
ssh $SSHLOGIN2 mkdir -p mydir; ssh $SSHLOGIN2 mkdir -p mydir;
mkdir -p $HOME/mydir; cd $HOME/mydir; mkdir -p $HOME/mydir; cd $HOME/mydir;
parallel --workdir . -S $SSHLOGIN2 ::: pwd parallel --workdir . -S $SSHLOGIN2 ::: pwd
echo '### bug #35544: --pipe would read from :::: (-a)';
parallel -j1 --pipe echo foo\;cat ::: a b c :::: <(seq 3) <(seq 4 6)
EOF EOF

View file

@ -70,3 +70,16 @@ vm1
/home/parallel/mydir /home/parallel/mydir
### Test --wd . ### Test --wd .
/home/parallel/mydir /home/parallel/mydir
### bug #35544: --pipe would read from :::: (-a)
foo
a
b
c
foo
1
2
3
foo
4
5
6