parallel: Cleaned up error() and warning().

This commit is contained in:
Ole Tange 2015-05-14 16:14:42 +02:00
parent d4c347c22b
commit 09de088df9

View file

@ -393,7 +393,7 @@ sub spreadstdin {
my $old_blocksize = $blocksize; my $old_blocksize = $blocksize;
$blocksize = ::min(ceil($blocksize * 1.3 + 1), $two_gb); $blocksize = ::min(ceil($blocksize * 1.3 + 1), $two_gb);
::warning("A record was longer than $old_blocksize. " . ::warning("A record was longer than $old_blocksize. " .
"Increasing to --blocksize $blocksize\n"); "Increasing to --blocksize $blocksize.");
} }
} }
} }
@ -930,7 +930,7 @@ sub parse_options {
$opt::memfree = multiply_binary_prefix($opt::memfree); $opt::memfree = multiply_binary_prefix($opt::memfree);
if(defined $opt::controlmaster) { $opt::noctrlc = 1; } if(defined $opt::controlmaster) { $opt::noctrlc = 1; }
if(defined $opt::timeout and $opt::timeout !~ /^\d+(\.\d+)?%?$/) { if(defined $opt::timeout and $opt::timeout !~ /^\d+(\.\d+)?%?$/) {
::error("--timeout must be seconds or percentage\n"); ::error("--timeout must be seconds or percentage.");
wait_and_exit(255); wait_and_exit(255);
} }
if(defined $opt::minversion) { if(defined $opt::minversion) {
@ -1014,8 +1014,8 @@ sub parse_options {
if(defined $opt::pipepart and if(defined $opt::pipepart and
(defined $opt::L or defined $opt::max_lines (defined $opt::L or defined $opt::max_lines
or defined $opt::max_replace_args)) { or defined $opt::max_replace_args)) {
::error("--pipepart is incompatible with --max-replace-args, ", ::error("--pipepart is incompatible with --max-replace-args, ".
"--max-lines, and -L.\n"); "--max-lines, and -L.");
wait_and_exit(255); wait_and_exit(255);
} }
if(grep /^$Global::arg_sep$|^$Global::arg_file_sep$/o, @ARGV) { if(grep /^$Global::arg_sep$|^$Global::arg_file_sep$/o, @ARGV) {
@ -1031,14 +1031,14 @@ sub parse_options {
$opt::progress = $opt::bar; $opt::progress = $opt::bar;
} }
if(defined $opt::retired) { if(defined $opt::retired) {
::error("-g has been retired. Use --group.\n"); ::error("-g has been retired. Use --group.",
::error("-B has been retired. Use --bf.\n"); "-B has been retired. Use --bf.",
::error("-T has been retired. Use --tty.\n"); "-T has been retired. Use --tty.",
::error("-U has been retired. Use --er.\n"); "-U has been retired. Use --er.",
::error("-W has been retired. Use --wd.\n"); "-W has been retired. Use --wd.",
::error("-Y has been retired. Use --shebang.\n"); "-Y has been retired. Use --shebang.",
::error("-H has been retired. Use --halt.\n"); "-H has been retired. Use --halt.",
::error("--tollef has been retired. Use -u -q --arg-sep -- and --load for -l.\n"); "--tollef has been retired. Use -u -q --arg-sep -- and --load for -l.");
::wait_and_exit(255); ::wait_and_exit(255);
} }
citation_notice(); citation_notice();
@ -1051,7 +1051,7 @@ sub parse_options {
# As we do not know the max line length on the remote machine # As we do not know the max line length on the remote machine
# long commands generated by xargs may fail # long commands generated by xargs may fail
# If $opt::max_replace_args is set, it is probably safe # If $opt::max_replace_args is set, it is probably safe
::warning("Using -X or -m with --sshlogin may fail.\n"); ::warning("Using -X or -m with --sshlogin may fail.");
} }
if(not defined $opt::jobs) { if(not defined $opt::jobs) {
@ -1110,7 +1110,7 @@ sub init_globals {
$ENV{'TMPDIR'} ||= "/tmp"; $ENV{'TMPDIR'} ||= "/tmp";
if(not $ENV{HOME}) { if(not $ENV{HOME}) {
# $ENV{HOME} is sometimes not set if called from PHP # $ENV{HOME} is sometimes not set if called from PHP
::warning("\$HOME not set. Using /tmp\n"); ::warning("\$HOME not set. Using /tmp.");
$ENV{HOME} = "/tmp"; $ENV{HOME} = "/tmp";
} }
} }
@ -1266,7 +1266,7 @@ sub parse_semaphore {
} }
if($Global::interactive and $opt::bg) { if($Global::interactive and $opt::bg) {
::error("Jobs running in the ". ::error("Jobs running in the ".
"background cannot be interactive.\n"); "background cannot be interactive.");
::wait_and_exit(255); ::wait_and_exit(255);
} }
} }
@ -1279,7 +1279,7 @@ sub record_env {
if(open(my $vars_fh, ">", $ignore_filename)) { if(open(my $vars_fh, ">", $ignore_filename)) {
print $vars_fh map { $_,"\n" } keys %ENV; print $vars_fh map { $_,"\n" } keys %ENV;
} else { } else {
::error("Cannot write to $ignore_filename.\n"); ::error("Cannot write to $ignore_filename.");
::wait_and_exit(255); ::wait_and_exit(255);
} }
} }
@ -1321,7 +1321,7 @@ sub open_joblog {
if(($opt::resume or $opt::resume_failed) if(($opt::resume or $opt::resume_failed)
and and
not ($opt::joblog or $opt::results)) { not ($opt::joblog or $opt::results)) {
::error("--resume and --resume-failed require --joblog or --results.\n"); ::error("--resume and --resume-failed require --joblog or --results.");
::wait_and_exit(255); ::wait_and_exit(255);
} }
if($opt::joblog) { if($opt::joblog) {
@ -1343,6 +1343,7 @@ sub open_joblog {
# This is 30% faster than set_job_already_run($1); # This is 30% faster than set_job_already_run($1);
vec($Global::job_already_run,($1||0),1) = 1; vec($Global::job_already_run,($1||0),1) = 1;
} elsif(not /\d+\s+[^\s]+\s+([-0-9.]+\s+){6}/) { } elsif(not /\d+\s+[^\s]+\s+([-0-9.]+\s+){6}/) {
chomp;
::error("Format of '$opt::joblog' is wrong: $_"); ::error("Format of '$opt::joblog' is wrong: $_");
::wait_and_exit(255); ::wait_and_exit(255);
} }
@ -1353,7 +1354,7 @@ sub open_joblog {
if($append) { if($append) {
# Append to joblog # Append to joblog
if(not open($Global::joblog, ">>", $opt::joblog)) { if(not open($Global::joblog, ">>", $opt::joblog)) {
::error("Cannot append to --joblog $opt::joblog.\n"); ::error("Cannot append to --joblog $opt::joblog.");
::wait_and_exit(255); ::wait_and_exit(255);
} }
} else { } else {
@ -1362,7 +1363,7 @@ sub open_joblog {
$Global::joblog = $Global::fd{1}; $Global::joblog = $Global::fd{1};
} elsif(not open($Global::joblog, ">", $opt::joblog)) { } elsif(not open($Global::joblog, ">", $opt::joblog)) {
# Overwrite the joblog # Overwrite the joblog
::error("Cannot write to --joblog $opt::joblog.\n"); ::error("Cannot write to --joblog $opt::joblog.");
::wait_and_exit(255); ::wait_and_exit(255);
} }
print $Global::joblog print $Global::joblog
@ -1484,7 +1485,7 @@ sub read_options {
if(grep /^$profile$/, @config_profiles) { if(grep /^$profile$/, @config_profiles) {
# config file is not required to exist # config file is not required to exist
} else { } else {
::error("$profile not readable.\n"); ::error("$profile not readable.");
wait_and_exit(255); wait_and_exit(255);
} }
} }
@ -1758,7 +1759,7 @@ sub open_or_exit {
} }
my $fh = gensym; my $fh = gensym;
if(not open($fh, "<", $file)) { if(not open($fh, "<", $file)) {
::error("Cannot open input file `$file': No such file or directory.\n"); ::error("Cannot open input file `$file': No such file or directory.");
wait_and_exit(255); wait_and_exit(255);
} }
return $fh; return $fh;
@ -2011,15 +2012,15 @@ sub init_run_jobs {
# Count down the number of jobs to run for this SSHLogin. # Count down the number of jobs to run for this SSHLogin.
my $max = $sshlogin->max_jobs_running(); my $max = $sshlogin->max_jobs_running();
if($max > 1) { $max--; } else { if($max > 1) { $max--; } else {
::error("No more processes: cannot run a single job. Something is wrong.\n"); ::error("No more processes: cannot run a single job. Something is wrong.");
::wait_and_exit(255); ::wait_and_exit(255);
} }
$sshlogin->set_max_jobs_running($max); $sshlogin->set_max_jobs_running($max);
# Sleep up to 300 ms to give other processes time to die # Sleep up to 300 ms to give other processes time to die
::usleep(rand()*300); ::usleep(rand()*300);
::warning("No more processes: ", ::warning("No more processes: ".
"Decreasing number of running jobs to $max. ", "Decreasing number of running jobs to $max.",
"Raising ulimit -u or /etc/security/limits.conf may help.\n"); "Raising ulimit -u or /etc/security/limits.conf may help.");
return 0; return 0;
} }
} }
@ -2027,7 +2028,7 @@ sub init_run_jobs {
# No more file handles # No more file handles
$no_more_file_handles_warned++ or $no_more_file_handles_warned++ or
::warning("No more file handles. ", ::warning("No more file handles. ",
"Raising ulimit -n or /etc/security/limits.conf may help.\n"); "Raising ulimit -n or /etc/security/limits.conf may help.");
return 0; return 0;
} }
} }
@ -2096,7 +2097,7 @@ sub drain_job_queue {
# These jobs may not be started: # These jobs may not be started:
# * because there the --filter-hosts has removed all # * because there the --filter-hosts has removed all
if(not %Global::host) { if(not %Global::host) {
::error("There are no hosts left to run on.\n"); ::error("There are no hosts left to run on.");
::wait_and_exit(255); ::wait_and_exit(255);
} }
# * because of loadavg # * because of loadavg
@ -2104,7 +2105,7 @@ sub drain_job_queue {
start_more_jobs(); start_more_jobs();
$sleep = ::reap_usleep($sleep); $sleep = ::reap_usleep($sleep);
if($Global::max_jobs_running == 0) { if($Global::max_jobs_running == 0) {
::warning("There are no job slots available. Increase --jobs.\n"); ::warning("There are no job slots available. Increase --jobs.");
} }
} }
} while ($Global::total_running > 0 } while ($Global::total_running > 0
@ -2473,7 +2474,7 @@ sub expand_slf_shorthand {
} elsif(not -r $file) { } elsif(not -r $file) {
if(not -r $ENV{'HOME'}."/.parallel/".$file) { if(not -r $ENV{'HOME'}."/.parallel/".$file) {
# Try prepending ~/.parallel # Try prepending ~/.parallel
::error("Cannot open $file.\n"); ::error("Cannot open $file.");
::wait_and_exit(255); ::wait_and_exit(255);
} else { } else {
$file = $ENV{'HOME'}."/.parallel/".$file; $file = $ENV{'HOME'}."/.parallel/".$file;
@ -2499,7 +2500,7 @@ sub read_sshloginfile {
} else { } else {
if(not open($in_fh, "<", $file)) { if(not open($in_fh, "<", $file)) {
# Try the filename # Try the filename
::error("Cannot open $file.\n"); ::error("Cannot open $file.");
::wait_and_exit(255); ::wait_and_exit(255);
} }
} }
@ -2587,15 +2588,15 @@ sub parse_sshlogin {
if(not remote_hosts()) { if(not remote_hosts()) {
# There are no remote hosts # There are no remote hosts
if(@opt::trc) { if(@opt::trc) {
::warning("--trc ignored as there are no remote --sshlogin.\n"); ::warning("--trc ignored as there are no remote --sshlogin.");
} elsif (defined $opt::transfer) { } elsif (defined $opt::transfer) {
::warning("--transfer ignored as there are no remote --sshlogin.\n"); ::warning("--transfer ignored as there are no remote --sshlogin.");
} elsif (@opt::return) { } elsif (@opt::return) {
::warning("--return ignored as there are no remote --sshlogin.\n"); ::warning("--return ignored as there are no remote --sshlogin.");
} elsif (defined $opt::cleanup) { } elsif (defined $opt::cleanup) {
::warning("--cleanup ignored as there are no remote --sshlogin.\n"); ::warning("--cleanup ignored as there are no remote --sshlogin.");
} elsif (@opt::basefile) { } elsif (@opt::basefile) {
::warning("--basefile ignored as there are no remote --sshlogin.\n"); ::warning("--basefile ignored as there are no remote --sshlogin.");
} }
} }
} }
@ -2624,7 +2625,7 @@ sub setup_basefile {
if($sshlogin->string() eq ":") { next } if($sshlogin->string() eq ":") { next }
for my $file (@opt::basefile) { for my $file (@opt::basefile) {
if($file !~ m:^/: and $opt::workdir eq "...") { if($file !~ m:^/: and $opt::workdir eq "...") {
::error("Work dir '...' will not work with relative basefiles.\n"); ::error("Work dir '...' will not work with relative basefiles.");
::wait_and_exit(255); ::wait_and_exit(255);
} }
$workdir ||= Job->new("")->workdir(); $workdir ||= Job->new("")->workdir();
@ -2669,7 +2670,7 @@ sub filter_hosts {
parse_host_filtering(parallelized_host_filtering()); parse_host_filtering(parallelized_host_filtering());
delete @Global::host{@$down_hosts_ref}; delete @Global::host{@$down_hosts_ref};
@$down_hosts_ref and ::warning("Removed @$down_hosts_ref\n"); @$down_hosts_ref and ::warning("Removed @$down_hosts_ref.");
$Global::minimal_command_line_length = 8_000_000; $Global::minimal_command_line_length = 8_000_000;
while (my ($sshlogin, $obj) = each %Global::host) { while (my ($sshlogin, $obj) = each %Global::host) {
@ -2734,7 +2735,7 @@ sub parse_host_filtering {
# signal == 127: parallel not installed remote # signal == 127: parallel not installed remote
# Set ncpus and ncores = 1 # Set ncpus and ncores = 1
::warning("Could not figure out ", ::warning("Could not figure out ",
"number of cpus on $host. Using 1.\n"); "number of cpus on $host. Using 1.");
$ncores{$host} = 1; $ncores{$host} = 1;
$ncpus{$host} = 1; $ncpus{$host} = 1;
$maxlen{$host} = Limits::Command::max_length(); $maxlen{$host} = Limits::Command::max_length();
@ -3282,16 +3283,14 @@ sub status {
sub warning { sub warning {
my @w = @_; my @w = @_;
my $fh = $Global::status_fd || *STDERR;
my $prog = $Global::progname || "parallel"; my $prog = $Global::progname || "parallel";
print $fh $prog, ": Warning: ", @w; status(map { ($prog, ": Warning: ", $_, "\n"); } @w);
} }
sub error { sub error {
my @w = @_; my @w = @_;
my $fh = $Global::status_fd || *STDERR;
my $prog = $Global::progname || "parallel"; my $prog = $Global::progname || "parallel";
print $fh $prog, ": Error: ", @w; status(map { ($prog, ": Error: ", $_, "\n"); } @w);
} }
sub die_bug { sub die_bug {
@ -3401,6 +3400,14 @@ sub tmpname {
# if you ssh to localhost (or a shared file system) under a different name # if you ssh to localhost (or a shared file system) under a different name
my $name = shift; my $name = shift;
my($tmpname); my($tmpname);
if(not -w $ENV{'TMPDIR'}) {
if(not -e $ENV{'TMPDIR'}) {
::error("Tmpdir '$ENV{'TMPDIR'}' does not exist.","Try 'mkdir $ENV{'TMPDIR'}'");
} else {
::error("Tmpdir '$ENV{'TMPDIR'}' is not writable.","Try 'chmod +w $ENV{'TMPDIR'}'");
}
::wait_and_exit(255);
}
do { do {
$tmpname = $ENV{'TMPDIR'}."/".$name. $tmpname = $ENV{'TMPDIR'}."/".$name.
join"", map { (0..9,"a".."z","A".."Z")[rand(62)] } (1..5); join"", map { (0..9,"a".."z","A".."Z")[rand(62)] } (1..5);
@ -3555,8 +3562,8 @@ sub multiply_binary_prefix {
tell $disk_full_fh != 8193) { tell $disk_full_fh != 8193) {
# On raspbian the disk can be full except for 10 chars. # On raspbian the disk can be full except for 10 chars.
if(not $error_printed) { if(not $error_printed) {
::error("Output is incomplete. Cannot append to buffer file in $ENV{'TMPDIR'}. Is the disk full?\n"); ::error("Output is incomplete. Cannot append to buffer file in $ENV{'TMPDIR'}. Is the disk full?",
::error("Change \$TMPDIR with --tmpdir or use --compress.\n"); "Change \$TMPDIR with --tmpdir or use --compress.");
$error_printed = 1; $error_printed = 1;
} }
::wait_and_exit(255); ::wait_and_exit(255);
@ -4524,11 +4531,11 @@ sub compute_max_loadavg {
close $in_fh; close $in_fh;
$load = $self->compute_max_loadavg($opt_load_file); $load = $self->compute_max_loadavg($opt_load_file);
} else { } else {
::error("Cannot open $loadspec.\n"); ::error("Cannot open $loadspec.");
::wait_and_exit(255); ::wait_and_exit(255);
} }
} else { } else {
::error("Parsing of --load failed.\n"); ::error("Parsing of --load failed.");
::die_usage(); ::die_usage();
} }
if($load < 0.01) { if($load < 0.01) {
@ -4730,8 +4737,8 @@ sub compute_number_of_processes {
# It took more than 0.01 second to fork a processes on avg. # It took more than 0.01 second to fork a processes on avg.
# Give the user a warning. He can press Ctrl-C if this # Give the user a warning. He can press Ctrl-C if this
# sucks. # sucks.
::warning("Starting $system_limit processes took > $forktime sec.\n", ::warning("Starting $system_limit processes took > $forktime sec.",
"Consider adjusting -j. Press CTRL-C to stop.\n"); "Consider adjusting -j. Press CTRL-C to stop.");
$slow_spawining_warning_printed = 1; $slow_spawining_warning_printed = 1;
} }
} }
@ -4740,19 +4747,20 @@ sub compute_number_of_processes {
if($system_limit < $wanted_processes) { if($system_limit < $wanted_processes) {
# The system_limit is less than the wanted_processes # The system_limit is less than the wanted_processes
if($system_limit < 1 and not $Global::JobQueue->empty()) { if($system_limit < 1 and not $Global::JobQueue->empty()) {
::warning("Cannot spawn any jobs. Raising ulimit -u or /etc/security/limits.conf\n", ::warning("Cannot spawn any jobs. Raising ulimit -u or /etc/security/limits.conf",
"or /proc/sys/kernel/pid_max may help.\n"); "or /proc/sys/kernel/pid_max may help.");
::wait_and_exit(255); ::wait_and_exit(255);
} }
if(not $more_filehandles) { if(not $more_filehandles) {
::warning("Only enough file handles to run ", $system_limit, " jobs in parallel.\n", ::warning("Only enough file handles to run ", $system_limit, " jobs in parallel.",
"Running 'parallel -j0 -N", $system_limit, " --pipe parallel -j0' or ", "Running 'parallel -j0 -N $system_limit --pipe parallel -j0' or ".
"raising ulimit -n or /etc/security/limits.conf may help.\n"); "raising ulimit -n or /etc/security/limits.conf may help.");
} }
if($max_system_proc_reached) { if($max_system_proc_reached) {
::warning("Only enough available processes to run ", $system_limit, ::warning("Only enough available processes to run ". $system_limit.
" jobs in parallel. Raising ulimit -u or /etc/security/limits.conf\n", " jobs in parallel.",
"or /proc/sys/kernel/pid_max may help.\n"); "Raising ulimit -u or /etc/security/limits.conf ",
"or /proc/sys/kernel/pid_max may help.");
} }
} }
if($] == 5.008008 and $system_limit > 1000) { if($] == 5.008008 and $system_limit > 1000) {
@ -4788,12 +4796,12 @@ sub simultaneous_sshlogin_limit {
$self->simultaneous_sshlogin($wanted_processes)); $self->simultaneous_sshlogin($wanted_processes));
if($ssh_limit < $wanted_processes) { if($ssh_limit < $wanted_processes) {
my $serverlogin = $self->serverlogin(); my $serverlogin = $self->serverlogin();
::warning("ssh to $serverlogin only allows ", ::warning("ssh to $serverlogin only allows ".
"for $ssh_limit simultaneous logins.\n", "for $ssh_limit simultaneous logins.",
"You may raise this by changing ", "You may raise this by changing ".
"/etc/ssh/sshd_config:MaxStartups and MaxSessions on $serverlogin.\n", "/etc/ssh/sshd_config:MaxStartups and MaxSessions on $serverlogin.",
"Using only ",$ssh_limit-1," connections ", "Using only ".($ssh_limit-1)." connections ".
"to avoid race conditions.\n"); "to avoid race conditions.");
} }
# Race condition can cause problem if using all sshs. # Race condition can cause problem if using all sshs.
if($ssh_limit > 1) { $ssh_limit -= 1; } if($ssh_limit > 1) { $ssh_limit -= 1; }
@ -4863,11 +4871,11 @@ sub user_requested_processes {
close $in_fh; close $in_fh;
$processes = $self->user_requested_processes($opt_P_file); $processes = $self->user_requested_processes($opt_P_file);
} else { } else {
::error("Cannot open $opt_P.\n"); ::error("Cannot open $opt_P.");
::wait_and_exit(255); ::wait_and_exit(255);
} }
} else { } else {
::error("Parsing of --jobs/-j/--max-procs/-P failed.\n"); ::error("Parsing of --jobs/-j/--max-procs/-P failed.");
::die_usage(); ::die_usage();
} }
$processes = ::ceil($processes); $processes = ::ceil($processes);
@ -4899,8 +4907,8 @@ sub ncpus {
if($ncpu =~ /^\s*[0-9]+\s*$/s) { if($ncpu =~ /^\s*[0-9]+\s*$/s) {
$self->{'ncpus'} = $ncpu; $self->{'ncpus'} = $ncpu;
} else { } else {
::warning("Could not figure out ", ::warning("Could not figure out ".
"number of cpus on $serverlogin ($ncpu). Using 1.\n"); "number of cpus on $serverlogin ($ncpu). Using 1.");
$self->{'ncpus'} = 1; $self->{'ncpus'} = 1;
} }
} }
@ -4961,7 +4969,7 @@ sub no_of_cpus {
chomp $no_of_cpus; chomp $no_of_cpus;
return $no_of_cpus; return $no_of_cpus;
} else { } else {
::warning("Cannot figure out number of cpus. Using 1.\n"); ::warning("Cannot figure out number of cpus. Using 1.");
return 1; return 1;
} }
} }
@ -5018,7 +5026,7 @@ sub no_of_cores {
chomp $no_of_cores; chomp $no_of_cores;
return $no_of_cores; return $no_of_cores;
} else { } else {
::warning("Cannot figure out number of CPU cores. Using 1.\n"); ::warning("Cannot figure out number of CPU cores. Using 1.");
return 1; return 1;
} }
} }
@ -5460,7 +5468,7 @@ sub rsync_transfer_cmd {
my $file = shift; my $file = shift;
my $workdir = shift; my $workdir = shift;
if(not -r $file) { if(not -r $file) {
::warning($file, " is not readable and will not be transferred.\n"); ::warning($file. " is not readable and will not be transferred.");
return "true"; return "true";
} }
my $rsync_destdir; my $rsync_destdir;
@ -5599,10 +5607,10 @@ sub total_jobs {
my $start = time; my $start = time;
while($job = $self->get()) { while($job = $self->get()) {
if(time - $start > 10) { if(time - $start > 10) {
::warning("Reading ".scalar(@queue)." arguments took longer than 10 seconds.\n"); ::warning("Reading ".scalar(@queue)." arguments took longer than 10 seconds.");
$opt::eta && ::warning("Consider removing --eta.\n"); $opt::eta && ::warning("Consider removing --eta.");
$opt::bar && ::warning("Consider removing --bar.\n"); $opt::bar && ::warning("Consider removing --bar.");
$opt::shuf && ::warning("Consider removing --shuf.\n"); $opt::shuf && ::warning("Consider removing --shuf.");
last; last;
} }
push @queue, $job; push @queue, $job;
@ -5792,13 +5800,13 @@ sub openoutputfiles {
# prefix/name1/val1/name2/val2/stdout # prefix/name1/val1/name2/val2/stdout
$outname = "$dir/stdout"; $outname = "$dir/stdout";
if(not open($outfhw, "+>", $outname)) { if(not open($outfhw, "+>", $outname)) {
::error("Cannot write to `$outname'.\n"); ::error("Cannot write to `$outname'.");
::wait_and_exit(255); ::wait_and_exit(255);
} }
# prefix/name1/val1/name2/val2/stderr # prefix/name1/val1/name2/val2/stderr
$errname = "$dir/stderr"; $errname = "$dir/stderr";
if(not open($errfhw, "+>", $errname)) { if(not open($errfhw, "+>", $errname)) {
::error("Cannot write to `$errname'.\n"); ::error("Cannot write to `$errname'.");
::wait_and_exit(255); ::wait_and_exit(255);
} }
$self->set_fh(1,"unlink",""); $self->set_fh(1,"unlink","");
@ -6517,7 +6525,7 @@ sub sshlogin_wrap {
push @vars, grep { not defined $ignore{$_} } keys %ENV; push @vars, grep { not defined $ignore{$_} } keys %ENV;
@vars = grep { not /^_$/ } @vars; @vars = grep { not /^_$/ } @vars;
} else { } else {
::error("Run '$Global::progname --record-env' in a clean environment first.\n"); ::error("Run '$Global::progname --record-env' in a clean environment first.");
::wait_and_exit(255); ::wait_and_exit(255);
} }
} }
@ -6548,7 +6556,7 @@ sub sshlogin_wrap {
if(@bashfunc) { if(@bashfunc) {
# Functions are not supported for all shells # Functions are not supported for all shells
if($Global::shell !~ m:/(bash|rbash|zsh|rzsh|dash|ksh):) { if($Global::shell !~ m:/(bash|rbash|zsh|rzsh|dash|ksh):) {
::warning("Shell functions may not be supported in $Global::shell\n"); ::warning("Shell functions may not be supported in $Global::shell.");
} }
$bashfuncset = $bashfuncset =
'@bash_functions=qw('."@bash_functions".");". '@bash_functions=qw('."@bash_functions".");".
@ -7006,13 +7014,13 @@ sub print_dryrun_and_verbose {
# # FIFO for communicating exit val # # FIFO for communicating exit val
# my $tmpfifo = ::tmpfifo(); # my $tmpfifo = ::tmpfifo();
if(length($tmpfifo) >=100) { if(length($tmpfifo) >=100) {
::error("tmux does not support sockets with path > 100\n"); ::error("tmux does not support sockets with path > 100.");
::wait_and_exit(255); ::wait_and_exit(255);
} }
my $visual_command = $self->replaced(); my $visual_command = $self->replaced();
my $title = $visual_command; my $title = $visual_command;
if($visual_command =~ /\0/) { if($visual_command =~ /\0/) {
::error("Command line contains NUL. tmux is confused by NUL.\n"); ::error("Command line contains NUL. tmux is confused by NUL.");
::wait_and_exit(255); ::wait_and_exit(255);
} }
# ; causes problems # ; causes problems
@ -7229,7 +7237,7 @@ sub files_print {
# If the job is dead: close printing fh. Needed for --compress # If the job is dead: close printing fh. Needed for --compress
close $self->fh($fdno,"w"); close $self->fh($fdno,"w");
if($? and $opt::compress) { if($? and $opt::compress) {
::error($opt::compress_program." failed.\n"); ::error($opt::compress_program." failed.");
$self->set_exitstatus(255); $self->set_exitstatus(255);
} }
if($opt::compress) { if($opt::compress) {
@ -7260,7 +7268,7 @@ sub linebuffer_print {
# If the job is dead: close printing fh. Needed for --compress # If the job is dead: close printing fh. Needed for --compress
close $self->fh($fdno,"w"); close $self->fh($fdno,"w");
if($? and $opt::compress) { if($? and $opt::compress) {
::error($opt::compress_program." failed.\n"); ::error($opt::compress_program." failed.");
$self->set_exitstatus(255); $self->set_exitstatus(255);
} }
if($opt::compress) { if($opt::compress) {
@ -7330,7 +7338,7 @@ sub linebuffer_print {
# decompress done: close fh # decompress done: close fh
close $in_fh; close $in_fh;
if($? and $opt::compress) { if($? and $opt::compress) {
::error($opt::decompress_program." failed.\n"); ::error($opt::decompress_program." failed.");
$self->set_exitstatus(255); $self->set_exitstatus(255);
} }
} }
@ -7343,7 +7351,7 @@ sub tag_print {
my $buf; my $buf;
close $self->fh($fdno,"w"); close $self->fh($fdno,"w");
if($? and $opt::compress) { if($? and $opt::compress) {
::error($opt::compress_program." failed.\n"); ::error($opt::compress_program." failed.");
$self->set_exitstatus(255); $self->set_exitstatus(255);
} }
seek $in_fh, 0, 0; seek $in_fh, 0, 0;
@ -7373,7 +7381,7 @@ sub tag_print {
} }
close $in_fh; close $in_fh;
if($? and $opt::compress) { if($? and $opt::compress) {
::error($opt::decompress_program." failed.\n"); ::error($opt::decompress_program." failed.");
$self->set_exitstatus(255); $self->set_exitstatus(255);
} }
} }
@ -7384,7 +7392,7 @@ sub normal_print {
my $buf; my $buf;
close $self->fh($fdno,"w"); close $self->fh($fdno,"w");
if($? and $opt::compress) { if($? and $opt::compress) {
::error($opt::compress_program." failed.\n"); ::error($opt::compress_program." failed.");
$self->set_exitstatus(255); $self->set_exitstatus(255);
} }
seek $in_fh, 0, 0; seek $in_fh, 0, 0;
@ -7407,7 +7415,7 @@ sub normal_print {
} }
close $in_fh; close $in_fh;
if($? and $opt::compress) { if($? and $opt::compress) {
::error($opt::decompress_program." failed.\n"); ::error($opt::decompress_program." failed.");
$self->set_exitstatus(255); $self->set_exitstatus(255);
} }
} }
@ -7672,15 +7680,15 @@ sub populate {
last; last;
} else { } else {
my $args = join(" ", map { $_->orig() } @$next_arg); my $args = join(" ", map { $_->orig() } @$next_arg);
::error("Command line too long (", ::error("Command line too long (".
$self->len(), " >= ", $self->len(). " >= ".
$max_len, $max_len.
") at input ", ") at input ".
$self->{'arg_queue'}->arg_number(), $self->{'arg_queue'}->arg_number().
": ". ": ".
((length $args > 50) ? ((length $args > 50) ?
(substr($args,0,50))."...\n" : (substr($args,0,50))."..." :
$args."\n")); $args));
$self->{'arg_queue'}->unget($self->pop()); $self->{'arg_queue'}->unget($self->pop());
::wait_and_exit(255); ::wait_and_exit(255);
} }
@ -8126,7 +8134,7 @@ sub new {
# Is this really a command in $PATH starting with '-'? # Is this really a command in $PATH starting with '-'?
my $cmd = $1; my $cmd = $1;
if(not ::which($cmd)) { if(not ::which($cmd)) {
::error("Command ($cmd) starts with '-'. Is this a wrong option?\n"); ::error("Command ($cmd) starts with '-'. Is this a wrong option?");
::wait_and_exit(255); ::wait_and_exit(255);
} }
} }
@ -8140,7 +8148,7 @@ sub new {
(defined $opt::tagstring ? $opt::tagstring : $dummy)) { (defined $opt::tagstring ? $opt::tagstring : $dummy)) {
# Disallow \257 to avoid nested {= {= =} =} # Disallow \257 to avoid nested {= {= =} =}
if(/\257/) { if(/\257/) {
::error("Command cannot contain the character \257. Use a function for that.\n"); ::error("Command cannot contain the character \257. Use a function for that.");
::wait_and_exit(255); ::wait_and_exit(255);
} }
# Needs to match rightmost left parens (Perl defaults to leftmost) # Needs to match rightmost left parens (Perl defaults to leftmost)
@ -8337,7 +8345,7 @@ sub get {
if($opt::pipe or $opt::pipepart) { if($opt::pipe or $opt::pipepart) {
if($cmd_line->replaced() eq "") { if($cmd_line->replaced() eq "") {
# Empty command - pipe requires a command # Empty command - pipe requires a command
::error("--pipe must have a command to pipe into (e.g. 'cat').\n"); ::error("--pipe must have a command to pipe into (e.g. 'cat').");
::wait_and_exit(255); ::wait_and_exit(255);
} }
} else { } else {
@ -8412,8 +8420,7 @@ sub max_length {
if($opt::max_chars <= $cached_limit) { if($opt::max_chars <= $cached_limit) {
$Limits::Command::line_max_len = $opt::max_chars; $Limits::Command::line_max_len = $opt::max_chars;
} else { } else {
::warning("Value for -s option ", ::warning("Value for -s option should be < $cached_limit.");
"should be < $cached_limit.\n");
} }
} }
} }
@ -8477,7 +8484,7 @@ sub tmux_length {
if($opt::tmux) { if($opt::tmux) {
$ENV{'TMUX'} ||= "tmux"; $ENV{'TMUX'} ||= "tmux";
if(not ::which($ENV{'TMUX'})) { if(not ::which($ENV{'TMUX'})) {
::error($ENV{'TMUX'}." not found in \$PATH.\n"); ::error($ENV{'TMUX'}." not found in \$PATH.");
::wait_and_exit(255); ::wait_and_exit(255);
} }
my @out; my @out;
@ -8630,9 +8637,9 @@ sub new {
my $fhs = shift; my $fhs = shift;
for my $fh (@$fhs) { for my $fh (@$fhs) {
if(-t $fh) { if(-t $fh) {
::warning("Input is read from the terminal.\n"); ::warning("Input is read from the terminal.",
::warning("Only experts do this on purpose. ". "Only experts do this on purpose. ".
"Press CTRL-D to exit.\n"); "Press CTRL-D to exit.");
} }
} }
return bless { return bless {
@ -8865,7 +8872,7 @@ sub new {
# We found hostgroups on the arg # We found hostgroups on the arg
@hostgroups = split(/\+/, $1); @hostgroups = split(/\+/, $1);
if(not grep { defined $Global::hostgroups{$_} } @hostgroups) { if(not grep { defined $Global::hostgroups{$_} } @hostgroups) {
::warning("No such hostgroup (@hostgroups)\n"); ::warning("No such hostgroup (@hostgroups).");
@hostgroups = (keys %Global::hostgroups); @hostgroups = (keys %Global::hostgroups);
} }
} else { } else {
@ -8908,7 +8915,7 @@ sub new {
# All is good # All is good
} else { } else {
# The eval failed. Maybe $perlexpr is invalid perl? # The eval failed. Maybe $perlexpr is invalid perl?
::error("Cannot use $perlexpr: $@\n"); ::error("Cannot use $perlexpr: $@");
::wait_and_exit(255); ::wait_and_exit(255);
} }
} }
@ -8942,7 +8949,7 @@ sub trim_of {
} elsif($Global::trim eq "rl" or $Global::trim eq "lr") { } elsif($Global::trim eq "rl" or $Global::trim eq "lr") {
for my $arg (@strings) { $arg =~ s/^\s+//; $arg =~ s/\s+$//; } for my $arg (@strings) { $arg =~ s/^\s+//; $arg =~ s/\s+$//; }
} else { } else {
::error("--trim must be one of: r l rl lr.\n"); ::error("--trim must be one of: r l rl lr.");
::wait_and_exit(255); ::wait_and_exit(255);
} }
return wantarray ? @strings : "@strings"; return wantarray ? @strings : "@strings";
@ -9114,7 +9121,7 @@ sub acquire {
and and
time - $start_time > $opt::semaphoretimeout) { time - $start_time > $opt::semaphoretimeout) {
# Timeout: Take the semaphore anyway # Timeout: Take the semaphore anyway
::warning("Semaphore timed out. Stealing the semaphore.\n"); ::warning("Semaphore timed out. Stealing the semaphore.");
if(not -e $self->{'idfile'}) { if(not -e $self->{'idfile'}) {
open (my $fh, ">", $self->{'idfile'}) or open (my $fh, ">", $self->{'idfile'}) or
::die_bug("timeout_write_idfile: $self->{'idfile'}"); ::die_bug("timeout_write_idfile: $self->{'idfile'}");
@ -9127,7 +9134,7 @@ sub acquire {
and and
time - $start_time > -$opt::semaphoretimeout) { time - $start_time > -$opt::semaphoretimeout) {
# Timeout: Exit # Timeout: Exit
::warning("Semaphore timed out. Exiting.\n"); ::warning("Semaphore timed out. Exiting.");
exit(1); exit(1);
last; last;
} }
@ -9216,8 +9223,8 @@ sub lock {
last; last;
} else { } else {
if ($! =~ m/Function not implemented/) { if ($! =~ m/Function not implemented/) {
::warning("flock: $!"); ::warning("flock: $!",
::warning("Will wait for a random while\n"); "Will wait for a random while.");
::usleep(rand(5000)); ::usleep(rand(5000));
# File cannot be locked: No need to retry # File cannot be locked: No need to retry
$locked = 2; $locked = 2;
@ -9276,7 +9283,7 @@ sub mkdir_or_die {
mkdir $ddir; mkdir $ddir;
} }
if(not -w $dir) { if(not -w $dir) {
::error("Cannot write to $dir: $!\n"); ::error("Cannot write to $dir: $!");
::wait_and_exit(255); ::wait_and_exit(255);
} }
} }