From 36264b0af908b11d8a07966cb14acdbcdd6625b6 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sat, 7 Jan 2017 15:00:59 -0800 Subject: [PATCH] jobd/taskd: avoid assigning to $0 Perl allows assignments to $0 to change the argv[0] value reported in the environment and ps-type listings. However, this doesn't always work out so well on some systems leading to peculiar and unwanted garbage in ps listings. Originally the only reason the assignment to $0 was done was to avoid leaving a relative $0 pointing nowhere after doing chdir("/") which caused pod2usage to fail to work properly. However, $0 is not actually used for anything after the point at which the chdir and $0 assignment were done other than as a default location for pod2usage and to be passed to the basename function. But the original $0 is a better choice to be passed to the basename function in case symbolic links are involved because basename(realpath($0)) could end up being different than basename($0). Therefore remove the assigments to $0 to prevent ps-produced process printout peculiarities, resolve $0 using realpath and save the result in a "my" variable before using chdir("/") and then pass the saved realpath($0) to pod2usage as the -input argument so it can still find the source file. Signed-off-by: Kyle J. McKay --- jobd/jobd.pl | 7 ++++--- taskd/taskd.pl | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/jobd/jobd.pl b/jobd/jobd.pl index cfb7762..61ce050 100755 --- a/jobd/jobd.pl +++ b/jobd/jobd.pl @@ -507,13 +507,14 @@ sub fatal($) { ######### Main {{{1 my $reexec = Girocco::ExecUtil->new; -$0 = realpath($0); +my $realpath0 = realpath($0); chdir "/"; close(DATA) if fileno(DATA); # Parse options Getopt::Long::Configure('bundling'); my $parse_res = GetOptions( - 'help|?|h' => sub { pod2usage(-verbose => 2, -exitval => 0); }, + 'help|?|h' => sub { + pod2usage(-verbose => 2, -exitval => 0, -input => $realpath0)}, 'quiet|q' => \$quiet, 'progress|P' => \$progress, 'kill-after|k=i' => \$kill_after, @@ -525,7 +526,7 @@ my $parse_res = GetOptions( 'same-pid' => \$same_pid, 'all-once|a' => \$all_once, 'one|o=s' => \$one, -) || pod2usage(2); +) || pod2usage(-exitval => 2, -input => $realpath0); fatal("Error: can only use one out of --all-once and --one") if ($all_once && $one); diff --git a/taskd/taskd.pl b/taskd/taskd.pl index 42cfef4..61ebcf8 100755 --- a/taskd/taskd.pl +++ b/taskd/taskd.pl @@ -1149,14 +1149,15 @@ sub cancel_jobd_restart { } my $reexec = Girocco::ExecUtil->new; -$0 = realpath($0); +my $realpath0 = realpath($0); chdir "/"; close(DATA) if fileno(DATA); my $sfac; Getopt::Long::Configure('bundling'); my ($stiv, $idiv); my $parse_res = GetOptions( - 'help|?|h' => sub {pod2usage(-verbose => 2, -exitval => 0)}, + 'help|?|h' => sub { + pod2usage(-verbose => 2, -exitval => 0, -input => $realpath0)}, 'quiet|q' => \$quiet, 'no-quiet' => sub {$quiet = 0}, 'progress|P' => \$progress, @@ -1174,7 +1175,7 @@ my $parse_res = GetOptions( 'no-same-pid' => sub {$same_pid = 0}, 'status-interval=i' => \$stiv, 'idle-status-interval=i' => \$idiv, -) || pod2usage(2); +) || pod2usage(-exitval => 2, -input => $realpath0); $same_pid = !$daemon unless defined($same_pid); $syslog = 1 if defined($sfac); $progress = 1 unless $quiet; -- 2.11.4.GIT