When using daemon mode over a remote shell program and not running as root,
[rsync/rsync.git] / options.c
index dd70623..310e8a0 100644 (file)
--- a/options.c
+++ b/options.c
@@ -66,7 +66,8 @@ int module_id = -1;
 int am_server = 0;
 int am_sender = 0;
 int recurse = 0;
-int am_daemon=0;
+int am_daemon = 0;
+int daemon_over_rsh = 0;
 int do_stats=0;
 int do_progress=0;
 int keep_partial=0;
@@ -102,17 +103,19 @@ int no_detach = 0;
 
 int write_batch = 0;
 int read_batch = 0;
+int suffix_specified = 0;
 
 char *backup_suffix = BACKUP_SUFFIX;
 char *tmpdir = NULL;
 char *compare_dest = NULL;
-char *config_file = RSYNCD_CONF;
+char *config_file = NULL;
 char *shell_cmd = NULL;
 char *log_format = NULL;
 char *password_file = NULL;
 char *rsync_path = RSYNC_PATH;
 char *backup_dir = NULL;
 int rsync_port = RSYNC_PORT;
+int link_dest = 0;
 
 int verbose = 0;
 int quiet = 0;
@@ -200,6 +203,7 @@ void usage(enum logcode F)
   rprintf(F,"  or   rsync [OPTION]... [USER@]HOST::SRC [DEST]\n");
   rprintf(F,"  or   rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST\n");
   rprintf(F,"  or   rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]\n");
+  rprintf(F,"  or   rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST\n");
   rprintf(F,"SRC on single-colon remote HOST will be expanded by remote shell\n");
   rprintf(F,"SRC on server remote HOST may contain shell wildcards or multiple\n");
   rprintf(F,"  sources separated by space as long as they have same top-level\n");
@@ -230,7 +234,7 @@ void usage(enum logcode F)
   rprintf(F,"     --no-whole-file         turn off --whole-file\n");
   rprintf(F," -x, --one-file-system       don't cross filesystem boundaries\n");
   rprintf(F," -B, --block-size=SIZE       checksum blocking size (default %d)\n",BLOCK_SIZE);  
-  rprintf(F," -e, --rsh=COMMAND           specify rsh replacement\n");
+  rprintf(F," -e, --rsh=COMMAND           specify the remote shell\n");
   rprintf(F,"     --rsync-path=PATH       specify path to rsync on the remote machine\n");
   rprintf(F," -C, --cvs-exclude           auto ignore files in the same way CVS does\n");
   rprintf(F,"     --existing              only update files that already exist\n");
@@ -286,7 +290,7 @@ enum {OPT_VERSION = 1000, OPT_SUFFIX, OPT_SENDER, OPT_SERVER, OPT_EXCLUDE,
       OPT_EXCLUDE_FROM, OPT_DELETE, OPT_DELETE_EXCLUDED, OPT_NUMERIC_IDS,
       OPT_RSYNC_PATH, OPT_FORCE, OPT_TIMEOUT, OPT_DAEMON, OPT_CONFIG, OPT_PORT,
       OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_STATS, OPT_PARTIAL, OPT_PROGRESS,
-      OPT_COPY_UNSAFE_LINKS, OPT_SAFE_LINKS, OPT_COMPARE_DEST,
+      OPT_COPY_UNSAFE_LINKS, OPT_SAFE_LINKS, OPT_COMPARE_DEST, OPT_LINK_DEST,
       OPT_LOG_FORMAT, OPT_PASSWORD_FILE, OPT_SIZE_ONLY, OPT_ADDRESS,
       OPT_DELETE_AFTER, OPT_EXISTING, OPT_MAX_DELETE, OPT_BACKUP_DIR, 
       OPT_IGNORE_ERRORS, OPT_BWLIMIT, OPT_BLOCKING_IO,
@@ -296,7 +300,7 @@ enum {OPT_VERSION = 1000, OPT_SUFFIX, OPT_SENDER, OPT_SERVER, OPT_EXCLUDE,
 static struct poptOption long_options[] = {
   /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
   {"version",          0,  POPT_ARG_NONE,   0,             OPT_VERSION, 0, 0},
-  {"suffix",           0,  POPT_ARG_STRING, &backup_suffix,    0, 0, 0 },
+  {"suffix",           0,  POPT_ARG_STRING, &backup_suffix,    OPT_SUFFIX, 0, 0 },
   {"rsync-path",       0,  POPT_ARG_STRING, &rsync_path,       0, 0, 0 },
   {"password-file",    0,  POPT_ARG_STRING, &password_file,    0, 0, 0 },
   {"ignore-times",    'I', POPT_ARG_NONE,   &ignore_times , 0, 0, 0 },
@@ -306,7 +310,7 @@ static struct poptOption long_options[] = {
   {"delete",           0,  POPT_ARG_NONE,   &delete_mode , 0, 0, 0 },
   {"existing",         0,  POPT_ARG_NONE,   &only_existing , 0, 0, 0 },
   {"ignore-existing",  0,  POPT_ARG_NONE,   &opt_ignore_existing , 0, 0, 0 },
-  {"delete-after",     0,  POPT_ARG_NONE,   &delete_after , 0, 0, 0 },
+  {"delete-after",     0,  POPT_ARG_NONE,   0,              OPT_DELETE_AFTER, 0, 0 },
   {"delete-excluded",  0,  POPT_ARG_NONE,   0,              OPT_DELETE_EXCLUDED, 0, 0 },
   {"force",            0,  POPT_ARG_NONE,   &force_delete , 0, 0, 0 },
   {"numeric-ids",      0,  POPT_ARG_NONE,   &numeric_ids , 0, 0, 0 },
@@ -345,6 +349,7 @@ static struct poptOption long_options[] = {
   {"timeout",          0,  POPT_ARG_INT,    &io_timeout , 0, 0, 0 },
   {"temp-dir",        'T', POPT_ARG_STRING, &tmpdir , 0, 0, 0 },
   {"compare-dest",     0,  POPT_ARG_STRING, &compare_dest , 0, 0, 0 },
+  {"link-dest",        0,  POPT_ARG_STRING, 0,               OPT_LINK_DEST, 0, 0 },
   /* TODO: Should this take an optional int giving the compression level? */
   {"compress",        'z', POPT_ARG_NONE,   &do_compression , 0, 0, 0 },
   {"daemon",           0,  POPT_ARG_NONE,   &am_daemon , 0, 0, 0 },
@@ -470,13 +475,25 @@ int parse_arguments(int *argc, const char ***argv, int frommain)
                         print_rsync_version(FINFO);
                        exit_cleanup(0);
                        
+               case OPT_SUFFIX:
+                        /* The value has already been set by popt, but
+                         * we need to remember that a suffix was specified
+                         * in case a backup-directory is used. */
+                        suffix_specified = 1;
+                       break;
+                       
                case OPT_MODIFY_WINDOW:
                         /* The value has already been set by popt, but
                          * we need to remember that we're using a
                          * non-default setting. */
                        modify_window_set = 1;
                        break;
-                       
+
+               case OPT_DELETE_AFTER:
+                       delete_after = 1;
+                       delete_mode = 1;
+                       break;
+
                case OPT_DELETE_EXCLUDED:
                        delete_excluded = 1;
                        delete_mode = 1;
@@ -576,6 +593,19 @@ int parse_arguments(int *argc, const char ***argv, int frommain)
                        /* popt stores the filename in batch_prefix for us */
                        read_batch = 1;
                        break;
+               case OPT_LINK_DEST:
+#if HAVE_LINK
+                       compare_dest = poptGetOptArg(pc);
+                       link_dest = 1;
+                       break;
+#else
+                       snprintf(err_buf,sizeof(err_buf),
+                                 "hard links are not supported on this %s\n",
+                                am_server ? "server" : "client");
+                       rprintf(FERROR,"ERROR: hard links not supported on this platform\n");
+                       return 0;
+#endif
+
 
                default:
                         /* FIXME: If --daemon is specified, then errors for later
@@ -642,6 +672,13 @@ void server_options(char **args,int *argc)
 
        args[ac++] = "--server";
 
+       if (daemon_over_rsh) {
+               args[ac++] = "--daemon";
+               *argc = ac;
+               /* if we're passing --daemon, we're done */
+               return;
+       }
+
        if (!am_sender)
                args[ac++] = "--sender";
 
@@ -805,7 +842,7 @@ void server_options(char **args,int *argc)
                 *   and it may be an older version that doesn't know this
                 *   option, so don't send it if client is the sender.
                 */
-               args[ac++] = "--compare-dest";
+               args[ac++] = link_dest ? "--link-dest" : "--compare-dest";
                args[ac++] = compare_dest;
        }