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 {
# Defaults:
$Global::version = 20150403;
$Global::version = 20150409;
$Global::progname = 'parallel';
$Global::infinity = 2**31;
$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]
if(not $cattail) {
$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
use Fcntl;
$|=1;
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) {
open(IN,"<",$read_file) || die("cattail: Cannot open $read_file");
} else {
*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 $flags;
@ -5528,11 +5536,8 @@ sub slot {
my $writer_running = kill 0, $writerpid;
$read = sysread(IN,$buf,32768);
if($read) {
# We can unlink the file now: The writer has written something
-e $unlink_file and unlink $unlink_file;
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;
open(OUT,"|-",$cmd) || die("cattail: Cannot run $cmd");
}
@ -5548,7 +5553,6 @@ sub slot {
} else {
if(eof(IN) and not $writer_running) {
# Writer dead: There will never be more to read => exit
-e $unlink_file and unlink $unlink_file;
exit;
}
# TODO This could probably be done more efficiently using select(2)
@ -5695,6 +5699,9 @@ sub filter_through_compress {
my $cattail = cattail();
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().
"| ($opt::compress_program) >>".
$self->fh($fdno,'name')) || die $?;