From: David Dykstra Date: Wed, 3 Feb 1999 15:38:06 +0000 (+0000) Subject: Move the initialization of push_dir, which calls getcwd, to early in main. X-Git-Tag: v2.3.0~37 X-Git-Url: http://git.samba.org/samba.git/?p=rsync.git;a=commitdiff_plain;h=c226b7c2fdd6cc4357337514b22c3042195ab091 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. --- diff --git a/clientserver.c b/clientserver.c index 557eb5fd..7b0dd161 100644 --- a/clientserver.c +++ b/clientserver.c @@ -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; diff --git a/main.c b/main.c index 900cd64e..87405579 100644 --- a/main.c +++ b/main.c @@ -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(); } diff --git a/util.c b/util.c index cadf3ebf..16d8f6cc 100644 --- a/util.c +++ b/util.c @@ -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) {