parallel: Code cleanup.

This commit is contained in:
Ole Tange 2014-02-21 10:20:16 +01:00
parent 9aaa763447
commit 04781ab6e9

View file

@ -626,7 +626,7 @@ sub get_options_from_array {
sub parse_options {
# Returns: N/A
# Defaults:
$Global::version = 20140122;
$Global::version = 20140220;
$Global::progname = 'parallel';
$Global::infinity = 2**31;
$Global::debug = 0;
@ -4183,6 +4183,17 @@ sub openoutputfiles {
unlink $self->fh($fdno,"unlink");
}
}
if($opt::linebuffer) {
# Set non-blocking when using --linebuffer
$Global::use{"Fcntl"} ||= eval "use Fcntl qw(:DEFAULT :flock); 1;";
for my $fdno (1,2) {
my $fdr = $self->fh($fdno,'r');
my $flags;
fcntl($fdr, &F_GETFL, $flags) || die $!; # Get the current flags on the filehandle
$flags |= &O_NONBLOCK; # Add non-blocking to the flags
fcntl($fdr, &F_SETFL, $flags) || die $!; # Set the flags on the filehandle
}
}
}
sub set_fh {
@ -4908,24 +4919,13 @@ sub print {
my $self = shift;
::debug(">>joboutput ".$self->replaced()."\n");
# if($opt::pipe and $self->virgin()) {
# # Nothing was printed to this job:
# # cleanup tmp files if --files was set
# close $self->fh(0,"w");
# for my $fdno (1,2) {
# close $self->fh($fdno,"w");
# close $self->fh($fdno,"r");
# # Unlink files that are empty
# unlink $self->fh($fdno,"name");
# }
# return;
# }
if($opt::dryrun) {
# Nothing was printed to this job:
# cleanup tmp files if --files was set
unlink $self->fh(1,"name");
}
if($opt::pipe and $self->virgin()) {
# Skip --joblog, --dryrun, --verbose
} else {
if($Global::joblog) { $self->print_joblog() }
@ -4968,7 +4968,7 @@ sub print {
close $self->fh($fdno,"w");
close $in_fh;
if($opt::pipe and $self->virgin()) {
# Nothing was printed to this job: # cleanup tmp files if --files was set
# Nothing was printed to this job: # cleanup unused tmp files if --files was set
for my $fdno (1,2) {
unlink $self->fh($fdno,"name");
unlink $self->fh($fdno,"unlink");
@ -5015,7 +5015,7 @@ sub print {
if($self->fh($fdno,"rpid") and kill 0, $self->fh($fdno,"rpid")) {
# decompress still running
} elsif(defined $self->{'exitstatus'} and length $$partial > 0) {
} elsif(defined $self->{'exitstatus'}) {
# If the job is dead: print the remaining partial line
# read remaining
if($opt::tag or defined $opt::tagstring) {
@ -5023,8 +5023,9 @@ sub print {
$$partial =~ s/^/$tag/gm;
}
print $out_fd $$partial;
# Release the memory
$$partial = undef;
# then close fd
# then close fh
close $in_fh;
}
} else {