Move the initialization of push_dir, which calls getcwd, to early in main.
authorDavid Dykstra <dwd@samba.org>
Wed, 3 Feb 1999 15:38:06 +0000 (15:38 +0000)
committerDavid Dykstra <dwd@samba.org>
Wed, 3 Feb 1999 15:38:06 +0000 (15:38 +0000)
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.

clientserver.c
main.c
util.c

index 557eb5f..7b0dd16 100644 (file)
@@ -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 900cd64..8740557 100644 (file)
--- 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 cadf3eb..16d8f6c 100644 (file)
--- 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) {