From 3a08d80d2917c605339ff5611b8535449f1e4a21 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sun, 30 Oct 2016 04:50:49 -0700 Subject: [PATCH] daemons: cd to "/" before starting While unlikely, it's possible that whatever the current working directory is when jobd and/or taskd is started might subsequently be removed while jobd and/or taskd is running. If that happens, attempts to run any subcommands (such as anything that uses the shell) are guaranteed to fail if they try to get the current working directory. Avoid this by just doing a "cd /" before entering any loops or starting any long-running processes. If the root directory somehow becomes invalid there's a much bigger problem with the system than just jobd and/or taskd failing to function. Signed-off-by: Kyle J. McKay --- jobd/jobd.pl | 1 + taskd/taskd.pl | 1 + toolbox/run-jobd.sh | 2 +- toolbox/run-taskd.sh | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/jobd/jobd.pl b/jobd/jobd.pl index 0cbebc5..1e46ea8 100755 --- a/jobd/jobd.pl +++ b/jobd/jobd.pl @@ -467,6 +467,7 @@ sub fatal($) { ######### Main {{{1 +chdir "/"; close(DATA) if fileno(DATA); # Parse options Getopt::Long::Configure('bundling'); diff --git a/taskd/taskd.pl b/taskd/taskd.pl index a40cfb2..75965a9 100755 --- a/taskd/taskd.pl +++ b/taskd/taskd.pl @@ -962,6 +962,7 @@ sub WRITE { package main; +chdir "/"; close(DATA) if fileno(DATA); my $sfac; Getopt::Long::Configure('bundling'); diff --git a/toolbox/run-jobd.sh b/toolbox/run-jobd.sh index 57696b8..443cda4 100755 --- a/toolbox/run-jobd.sh +++ b/toolbox/run-jobd.sh @@ -4,7 +4,7 @@ DEFAULTOPTS="-q -P" test -n "$PATH" || PATH="$(/usr/bin/getconf PATH)" export PATH -cd "${HOME:-/}" || cd / +cd / shbin=@shbin@ exec_login_shell() { diff --git a/toolbox/run-taskd.sh b/toolbox/run-taskd.sh index 1fd0d80..203dbb4 100755 --- a/toolbox/run-taskd.sh +++ b/toolbox/run-taskd.sh @@ -4,7 +4,7 @@ DEFAULTOPTS="-q -P" test -n "$PATH" || PATH="$(/usr/bin/getconf PATH)" export PATH -cd "${HOME:-/}" || cd / +cd / shbin=@shbin@ exec_login_shell() { -- 2.11.4.GIT