Add compatibility with an unmodified zlib.
[rsync.git] / main.c
diff --git a/main.c b/main.c
index d020e6c2f95e217b29dcd0de00eb1f8f4b949d05..17ba62d65e975784df52565b980439e7988912bb 100644 (file)
--- a/main.c
+++ b/main.c
@@ -70,6 +70,7 @@ extern int sock_f_out;
 extern int filesfrom_fd;
 extern int connect_timeout;
 extern int send_msgs_to_gen;
+extern dev_t filesystem_dev;
 extern pid_t cleanup_child_pid;
 extern size_t bwlimit_writemax;
 extern unsigned int module_dirlen;
@@ -130,7 +131,7 @@ static void show_malloc_stats(void);
 pid_t wait_process(pid_t pid, int *status_ptr, int flags)
 {
        pid_t waited_pid;
-       
+
        do {
                waited_pid = waitpid(pid, status_ptr, flags);
        } while (waited_pid == -1 && errno == EINTR);
@@ -363,7 +364,7 @@ static void show_malloc_stats(void)
 
        rprintf(FCLIENT, "\n");
        rprintf(FINFO, RSYNC_NAME "[%d] (%s%s%s) heap statistics:\n",
-               getpid(), am_server ? "server " : "",
+               (int)getpid(), am_server ? "server " : "",
                am_daemon ? "daemon " : "", who_am_i());
        rprintf(FINFO, "  arena:     %10ld   (bytes from sbrk)\n",
                (long)mi.arena);
@@ -493,7 +494,11 @@ static pid_t do_cmd(char *cmd, char *machine, char *user, char **remote_argv, in
                                rprintf(FERROR, "internal: args[] overflowed in do_cmd()\n");
                                exit_cleanup(RERR_SYNTAX);
                        }
-                       args[argc++] = *remote_argv++;
+                       if (**remote_argv == '-') {
+                               if (asprintf(args + argc++, "./%s", *remote_argv++) < 0)
+                                       out_of_memory("do_cmd");
+                       } else
+                               args[argc++] = *remote_argv++;
                        remote_argc--;
                }
        }
@@ -589,7 +594,7 @@ static char *get_local_name(struct file_list *flist, char *dest_path)
                if ((*dest_path != '.' || dest_path[1] != '\0')
                 && (check_filter(&daemon_filter_list, FLOG, dest_path, 0) < 0
                  || check_filter(&daemon_filter_list, FLOG, dest_path, 1) < 0)) {
-                       rprintf(FERROR, "skipping daemon-excluded destination \"%s\"\n",
+                       rprintf(FERROR, "ERROR: daemon has excluded destination \"%s\"\n",
                                dest_path);
                        exit_cleanup(RERR_FILESELECT);
                }
@@ -606,6 +611,7 @@ static char *get_local_name(struct file_list *flist, char *dest_path)
                                        full_fname(dest_path));
                                exit_cleanup(RERR_FILESELECT);
                        }
+                       filesystem_dev = st.st_dev; /* ensures --force works right w/-x */
                        return NULL;
                }
                if (file_total > 1) {
@@ -768,10 +774,8 @@ static void do_server_sender(int f_in, int f_out, int argc, char *argv[])
        struct file_list *flist;
        char *dir = argv[0];
 
-       if (DEBUG_GTE(SEND, 1)) {
-               rprintf(FINFO, "server_sender starting pid=%ld\n",
-                       (long)getpid());
-       }
+       if (DEBUG_GTE(SEND, 1))
+               rprintf(FINFO, "server_sender starting pid=%d\n", (int)getpid());
 
        if (am_daemon && lp_write_only(module_id)) {
                rprintf(FERROR, "ERROR: module is write only\n");
@@ -803,8 +807,12 @@ static void do_server_sender(int f_in, int f_out, int argc, char *argv[])
        }
 
        flist = send_file_list(f_out,argc,argv);
-       if (!flist || flist->used == 0)
+       if (!flist || flist->used == 0) {
+               /* Make sure input buffering is off so we can't hang in noop_io_until_death(). */
+               io_end_buffering_in(0);
+               /* TODO:  we should really exit in a more controlled manner. */
                exit_cleanup(0);
+       }
 
        io_start_buffering_in(f_in);
 
@@ -962,10 +970,8 @@ static void do_server_recv(int f_in, int f_out, int argc, char *argv[])
        } else
                negated_levels = 0;
 
-       if (DEBUG_GTE(RECV, 1)) {
-               rprintf(FINFO, "server_recv(%d) starting pid=%ld\n",
-                       argc, (long)getpid());
-       }
+       if (DEBUG_GTE(RECV, 1))
+               rprintf(FINFO, "server_recv(%d) starting pid=%d\n", argc, (int)getpid());
 
        if (am_daemon && read_only) {
                rprintf(FERROR,"ERROR: module is read only\n");
@@ -1307,6 +1313,9 @@ static int start_client(int argc, char *argv[])
                remote_argc = argc = 1;
        }
 
+       if (!rsync_port && remote_argc && !**remote_argv) /* Turn an empty arg into a dot dir. */
+               *remote_argv = ".";
+
        if (am_sender) {
                char *dummy_host;
                int dummy_port = rsync_port;
@@ -1342,6 +1351,8 @@ static int start_client(int argc, char *argv[])
                                        rprintf(FERROR, "All source args must use the same port number.\n");
                                exit_cleanup(RERR_SYNTAX);
                        }
+                       if (!rsync_port && !*arg) /* Turn an empty arg into a dot dir. */
+                               arg = ".";
                        remote_argv[i] = arg;
                }
        }
@@ -1476,10 +1487,9 @@ const char *get_panic_action(void)
 static RETSIGTYPE rsync_panic_handler(UNUSED(int whatsig))
 {
        char cmd_buf[300];
-       int ret;
+       int ret, pid_int = getpid();
 
-       snprintf(cmd_buf, sizeof cmd_buf, get_panic_action(),
-                getpid(), getpid());
+       snprintf(cmd_buf, sizeof cmd_buf, get_panic_action(), pid_int, pid_int);
 
        /* Unless we failed to execute gdb, we allow the process to
         * continue.  I'm not sure if that's right. */