Move the initialization of push_dir, which calls getcwd, to early in main.
[rsync/rsync.git] / main.c
diff --git a/main.c b/main.c
index bc587cc..8740557 100644 (file)
--- a/main.c
+++ b/main.c
@@ -36,7 +36,7 @@ static void report(int f)
        extern int do_stats;
 
        if (am_daemon) {
-               log_exit(0);
+               log_exit(0, __FILE__, __LINE__);
                if (f == -1 || !am_sender) return;
        }
 
@@ -171,7 +171,10 @@ static char *get_local_name(struct file_list *flist,char *name)
 
        if (verbose > 2)
                rprintf(FINFO,"get_local_name count=%d %s\n", 
-                       flist->count, name);
+                       flist->count, NS(name));
+
+       if (!name) 
+               return NULL;
 
        if (do_stat(name,&st) == 0) {
                if (S_ISDIR(st.st_mode)) {
@@ -192,9 +195,6 @@ static char *get_local_name(struct file_list *flist,char *name)
        if (flist->count == 1)
                return name;
 
-       if (!name) 
-               return NULL;
-
        if (do_mkdir(name,0777 & ~orig_umask) != 0) {
                rprintf(FERROR,"mkdir %s : %s (1)\n",name,strerror(errno));
                exit_cleanup(RERR_FILEIO);
@@ -464,6 +464,7 @@ static int start_client(int argc, char *argv[])
        extern int local_server;
        extern int am_sender;
        extern char *shell_cmd;
+       extern int rsync_port;
 
        if (strncasecmp(URL_PREFIX, argv[0], strlen(URL_PREFIX)) == 0) {
                char *host, *path;
@@ -476,6 +477,11 @@ static int start_client(int argc, char *argv[])
                } else {
                        path="";
                }
+               p = strchr(host,':');
+               if (p) {
+                       rsync_port = atoi(p+1);
+                       *p = 0;
+               }
                return start_socket_client(host, path, argc-1, argv+1);
        }
 
@@ -600,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();
        }