Rsync no longer returns a usage error when used with one local
[rsync/rsync.git] / main.c
diff --git a/main.c b/main.c
index e8b5efd..9d8723b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -88,14 +88,14 @@ static int64 total_read, total_written;
 static void show_malloc_stats(void);
 
 /* Works like waitpid(), but if we already harvested the child pid in our
- * sigchld_handler(), we succeed instead of returning an error. */
+ * remember_children(), we succeed instead of returning an error. */
 pid_t wait_process(pid_t pid, int *status_ptr, int flags)
 {
        pid_t waited_pid = waitpid(pid, status_ptr, flags);
 
        if (waited_pid == -1 && errno == ECHILD) {
                /* Status of requested child no longer available:  check to
-                * see if it was processed by sigchld_handler(). */
+                * see if it was processed by remember_children(). */
                int cnt;
                for (cnt = 0; cnt < MAXCHILDPROCS; cnt++) {
                        if (pid == pid_stat_table[cnt].pid) {
@@ -457,7 +457,7 @@ static char *get_local_name(struct file_list *flist, char *dest_path)
                        flist->count, NS(dest_path));
        }
 
-       if (!dest_path)
+       if (!dest_path || list_only)
                return NULL;
 
        /* If the destination path refers to an existing directory, enter
@@ -960,12 +960,12 @@ static int start_client(int argc, char *argv[])
                return rc;
 
        if (!read_batch) { /* for read_batch, NO source is specified */
-               argc--;
                shell_path = check_for_hostspec(argv[0], &shell_machine, &rsync_port);
                if (shell_path) { /* source is remote */
                        char *dummy1;
                        int dummy2;
-                       if (argc && check_for_hostspec(argv[argc], &dummy1, &dummy2)) {
+                       if (--argc
+                        && check_for_hostspec(argv[argc], &dummy1, &dummy2)) {
                                rprintf(FERROR,
                                        "The source and destination cannot both be remote.\n");
                                exit_cleanup(RERR_SYNTAX);
@@ -990,12 +990,14 @@ static int start_client(int argc, char *argv[])
                } else { /* source is local, check dest arg */
                        am_sender = 1;
 
-                       if (argc < 1) { /* destination required */
-                               usage(FERROR);
-                               exit_cleanup(RERR_SYNTAX);
+                       if (argc > 1)
+                               p = argv[--argc];
+                       else {
+                               p = ".";
+                               list_only = 1;
                        }
 
-                       shell_path = check_for_hostspec(argv[argc], &shell_machine, &rsync_port);
+                       shell_path = check_for_hostspec(p, &shell_machine, &rsync_port);
                        if (shell_path && filesfrom_host && *filesfrom_host
                            && strcmp(filesfrom_host, shell_machine) != 0) {
                                rprintf(FERROR,
@@ -1010,7 +1012,7 @@ static int start_client(int argc, char *argv[])
                                        exit_cleanup(RERR_SYNTAX);
                                }
                                shell_machine = NULL;
-                               shell_path = argv[argc];
+                               shell_path = p;
                        } else if (rsync_port) {
                                if (!shell_cmd) {
                                        return start_socket_client(shell_machine,
@@ -1093,7 +1095,7 @@ static RETSIGTYPE sigusr2_handler(UNUSED(int val))
        _exit(0);
 }
 
-static RETSIGTYPE sigchld_handler(UNUSED(int val))
+RETSIGTYPE remember_children(UNUSED(int val))
 {
 #ifdef WNOHANG
        int cnt, status;
@@ -1115,7 +1117,7 @@ static RETSIGTYPE sigchld_handler(UNUSED(int val))
        }
 #endif
 #ifndef HAVE_SIGACTION
-       signal(SIGCHLD, sigchld_handler);
+       signal(SIGCHLD, remember_children);
 #endif
 }
 
@@ -1186,7 +1188,7 @@ int main(int argc,char *argv[])
 #endif
        SIGACTMASK(SIGUSR1, sigusr1_handler);
        SIGACTMASK(SIGUSR2, sigusr2_handler);
-       SIGACTMASK(SIGCHLD, sigchld_handler);
+       SIGACTMASK(SIGCHLD, remember_children);
 #ifdef MAINTAINER_MODE
        SIGACTMASK(SIGSEGV, rsync_panic_handler);
        SIGACTMASK(SIGFPE, rsync_panic_handler);
@@ -1229,6 +1231,9 @@ int main(int argc,char *argv[])
        /* Ignore SIGPIPE; we consistently check error codes and will
         * see the EPIPE. */
        SIGACTION(SIGPIPE, SIG_IGN);
+#ifdef SIGXFSZ
+       SIGACTION(SIGXFSZ, SIG_IGN);
+#endif
 
        /* Initialize push_dir here because on some old systems getcwd
         * (implemented by forking "pwd" and reading its output) doesn't