diff options
author | fergus.henderson <fergushenderson@users.noreply.github.com> | 2010-08-19 20:07:45 +0000 |
---|---|---|
committer | fergus.henderson <fergushenderson@users.noreply.github.com> | 2010-08-19 20:07:45 +0000 |
commit | d6c36cec73f2ef6c0e612c1acb9f42549e035717 (patch) | |
tree | fdc619e67bcf50280c96bc423ed49d9c0578e10b | |
parent | dc2c66bf523a70178fc486abcbdfa9c2a379dbb1 (diff) | |
download | distcc-git-d6c36cec73f2ef6c0e612c1acb9f42549e035717.tar.gz |
Change directory back to the original server working directory after each
distcc-pump compilation. This fixes a bug where distcc-pump was changing
to a directory and then deleting that directory and not changing back
to the original directory. That caused problems when you used a server
first in distcc-pump mode and then in distcc mode, and the compiler
invoked a shell script. The compilation would succeed, but the shell would
report a confusing warning ("shell-init: error retrieving current directory:
getcwd: cannot access parent directories: No such file or directory").
-rw-r--r-- | src/daemon.c | 18 | ||||
-rw-r--r-- | src/daemon.h | 2 | ||||
-rw-r--r-- | src/serve.c | 12 |
3 files changed, 23 insertions, 9 deletions
diff --git a/src/daemon.c b/src/daemon.c index 984ad62..a1056f8 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -84,6 +84,9 @@ /* for trace.c */ char const *rs_program_name = "distccd"; +/* for serve.c */ +char const *dcc_daemon_wd; /* The working directory for the server. */ + static int dcc_inetd_server(void); static void dcc_setup_real_log(void); @@ -156,7 +159,6 @@ static int dcc_setup_daemon_path(void) int main(int argc, char *argv[]) { int ret; - const char *tmp; dcc_setup_startup_log(); @@ -189,18 +191,18 @@ int main(int argc, char *argv[]) * the right ownership. */ dcc_setup_real_log(); - /* Do everything from root directory. Allows start directory to be - * unmounted, should make accidental writing of local files cause a - * failure... */ - if ((ret = dcc_get_tmp_top(&tmp))) + /* Do everything from $TMPDIR directory. Allows start directory to be + * unmounted. */ + if ((ret = dcc_get_tmp_top(&dcc_daemon_wd))) goto out; - if (chdir(tmp) == -1) { - rs_log_error("failed to chdir to %s: %s", tmp, strerror(errno)); + if (chdir(dcc_daemon_wd) == -1) { + rs_log_error("failed to chdir to %s: %s", + dcc_daemon_wd, strerror(errno)); ret = EXIT_IO_ERROR; goto out; } else { - rs_trace("chdir to %s", tmp); + rs_trace("chdir to %s", dcc_daemon_wd); } if ((ret = dcc_setup_daemon_path())) diff --git a/src/daemon.h b/src/daemon.h index 36a7fd2..d48bb6b 100644 --- a/src/daemon.h +++ b/src/daemon.h @@ -22,6 +22,8 @@ /* daemon.c */ +extern const char *dcc_daemon_wd; + int dcc_refuse_root(void); int dcc_set_lifetime(void); int dcc_log_daemon_started(const char *role); diff --git a/src/serve.c b/src/serve.c index 56c1486..e6c2232 100644 --- a/src/serve.c +++ b/src/serve.c @@ -584,6 +584,7 @@ static int dcc_run_job(int in_fd, enum dcc_cpp_where cpp_where; char *server_cwd = NULL; char *client_cwd = NULL; + int changed_directory = 0; gettimeofday(&start, NULL); @@ -616,10 +617,12 @@ static int dcc_run_job(int in_fd, dcc_get_features_from_protover(protover, &compr, &cpp_where); - if (cpp_where == DCC_CPP_ON_SERVER) + if (cpp_where == DCC_CPP_ON_SERVER) { if ((ret = make_temp_dir_and_chdir_for_cpp(in_fd, &temp_dir, &client_cwd, &server_cwd))) goto out_cleanup; + changed_directory = 1; + } if ((ret = dcc_r_argv(in_fd, &argv)) || (ret = dcc_scan_args(argv, &orig_input_tmp, &orig_output_tmp, @@ -742,6 +745,13 @@ static int dcc_run_job(int in_fd, out_cleanup: + /* Restore the working directory, if needed. */ + if (changed_directory) { + if (chdir(dcc_daemon_wd) != 0) { + rs_log_warning("chdir(%s) failed: %s", dcc_daemon_wd, strerror(errno)); + } + } + switch (ret) { case EXIT_BUSY: /* overloaded */ job_result = STATS_REJ_OVERLOAD; |