Commit c226b7c2 authored by David Dykstra's avatar David Dykstra

Move the initialization of push_dir, which calls getcwd, to early in main.

The reason for that is that on SVR2-based UTS 2.1.2 (which along with many
other old systems implements getcwd by forking "pwd") getcwd hangs when
called when other child processes are running.

I also added a quick return from push_dir if name == NULL so it doesn't
actually have to chdir anywhere when just initializing.

An initializing call to push_dir("/",0) had previously been put in at the
beginning of daemon_main() to avoid calling getcwd after a chroot, but
since that is no longer I needed I removed it and changed the call to
chdir("/") after chroot into a push_dir("/",0) so it will remember the
correct current directory.
parent 5865fcdd
......@@ -212,7 +212,7 @@ static int rsync_module(int fd, int i)
return -1;
}
if (chdir("/")) {
if (!push_dir("/", 0)) {
rprintf(FERROR,"chdir %s failed\n", lp_path(i));
io_printf(fd,"@ERROR: chdir failed\n");
return -1;
......@@ -422,11 +422,6 @@ int daemon_main(void)
extern char *config_file;
char *pid_file;
/* this ensures that we don't call getcwd after the chroot,
which doesn't work on platforms that use popen("pwd","r")
for getcwd */
push_dir("/", 0);
if (is_a_socket(STDIN_FILENO)) {
int i;
......
......@@ -606,6 +606,12 @@ int main(int argc,char *argv[])
signal(SIGHUP,SIGNAL_CAST sig_int);
signal(SIGTERM,SIGNAL_CAST sig_int);
/* Initialize push_dir here because on some old systems getcwd
(implemented by forking "pwd" and reading its output) doesn't
work when there are other child processes. Also, on all systems
that implement getcwd that way "pwd" can't be found after chroot. */
push_dir(NULL,0);
if (am_daemon) {
return daemon_main();
}
......
......@@ -638,6 +638,8 @@ char *push_dir(char *dir, int save)
getcwd(curr_dir, sizeof(curr_dir)-1);
}
if (!dir) return NULL; /* this call was probably just to initialize */
if (chdir(dir)) return NULL;
if (save) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment