parallel: Fixed bug #44810: --compress leaves tmp file hanging.

This commit is contained in:
Ole Tange 2015-04-11 20:54:56 +02:00
parent d8ec46d2d8
commit 18d62fe452

View file

@ -1051,7 +1051,7 @@ sub parse_options {
sub init_globals { sub init_globals {
# Defaults: # Defaults:
$Global::version = 20150403; $Global::version = 20150409;
$Global::progname = 'parallel'; $Global::progname = 'parallel';
$Global::infinity = 2**31; $Global::infinity = 2**31;
$Global::debug = 0; $Global::debug = 0;
@ -5503,18 +5503,26 @@ sub slot {
# $cattail = perl program for: cattail "decompress program" writerpid [file_to_decompress or stdin] [file_to_unlink] # $cattail = perl program for: cattail "decompress program" writerpid [file_to_decompress or stdin] [file_to_unlink]
if(not $cattail) { if(not $cattail) {
$cattail = q{ $cattail = q{
# cat followed by tail. # cat followed by tail (possibly with rm as soon at the file is opened)
# If $writerpid dead: finish after this round # If $writerpid dead: finish after this round
use Fcntl; use Fcntl;
$|=1; $|=1;
my ($cmd, $writerpid, $read_file, $unlink_file) = @ARGV; my ($cmd, $writerpid, $read_file, $unlink_file) = @ARGV;
while(defined $unlink_file and not -e $unlink_file) {
# Writer has not opened file, so we cannot open it
$sleep = ($sleep < 30) ? ($sleep * 1.001 + 0.01) : ($sleep);
usleep($sleep);
}
if($read_file) { if($read_file) {
open(IN,"<",$read_file) || die("cattail: Cannot open $read_file"); open(IN,"<",$read_file) || die("cattail: Cannot open $read_file");
} else { } else {
*IN = *STDIN; *IN = *STDIN;
} }
# The writer and we have both opened the file, so it is safe to unlink it
unlink $unlink_file;
my $first_round = 1; my $first_round = 1;
my $flags; my $flags;
@ -5528,11 +5536,8 @@ sub slot {
my $writer_running = kill 0, $writerpid; my $writer_running = kill 0, $writerpid;
$read = sysread(IN,$buf,32768); $read = sysread(IN,$buf,32768);
if($read) { if($read) {
# We can unlink the file now: The writer has written something
-e $unlink_file and unlink $unlink_file;
if($first_round) { if($first_round) {
# Do not start command if there is no input # Only start the command if there any input to process
$first_round = 0; $first_round = 0;
open(OUT,"|-",$cmd) || die("cattail: Cannot run $cmd"); open(OUT,"|-",$cmd) || die("cattail: Cannot run $cmd");
} }
@ -5548,7 +5553,6 @@ sub slot {
} else { } else {
if(eof(IN) and not $writer_running) { if(eof(IN) and not $writer_running) {
# Writer dead: There will never be more to read => exit # Writer dead: There will never be more to read => exit
-e $unlink_file and unlink $unlink_file;
exit; exit;
} }
# TODO This could probably be done more efficiently using select(2) # TODO This could probably be done more efficiently using select(2)
@ -5695,6 +5699,9 @@ sub filter_through_compress {
my $cattail = cattail(); my $cattail = cattail();
for my $fdno (1,2) { for my $fdno (1,2) {
# The tmpfile is used to tell the reader that the writer has started,
# so unlink it to start with.
unlink $self->fh($fdno,'name');
my $wpid = open(my $fdw,"|-", empty_input_detector(). my $wpid = open(my $fdw,"|-", empty_input_detector().
"| ($opt::compress_program) >>". "| ($opt::compress_program) >>".
$self->fh($fdno,'name')) || die $?; $self->fh($fdno,'name')) || die $?;