Added a command-line override for daemon config parameters:
authorWayne Davison <wayned@samba.org>
Sun, 27 Jul 2008 19:13:35 +0000 (12:13 -0700)
committerWayne Davison <wayned@samba.org>
Sun, 27 Jul 2008 19:13:35 +0000 (12:13 -0700)
--dparam=PARAMETER=VALUE (-M PARAMETER=VALUE).

clientserver.c
loadparm.c
options.c
rsync.yo
rsyncd.conf.yo

index 6fce7c4..2a911d6 100644 (file)
@@ -1040,6 +1040,7 @@ int daemon_main(void)
                fprintf(stderr, "Failed to parse config file: %s\n", config_file);
                exit_cleanup(RERR_SYNTAX);
        }
                fprintf(stderr, "Failed to parse config file: %s\n", config_file);
                exit_cleanup(RERR_SYNTAX);
        }
+       set_dparams(0);
 
        if (no_detach)
                create_pid_file();
 
        if (no_detach)
                create_pid_file();
index 2af7b8d..3515358 100644 (file)
@@ -45,6 +45,9 @@
 
 #include "rsync.h"
 #include "ifuncs.h"
 
 #include "rsync.h"
 #include "ifuncs.h"
+
+extern item_list dparam_list;
+
 #define strequal(a, b) (strcasecmp(a, b)==0)
 #define BOOLSTR(b) ((b) ? "Yes" : "No")
 
 #define strequal(a, b) (strcasecmp(a, b)==0)
 #define BOOLSTR(b) ((b) ? "Yes" : "No")
 
@@ -699,8 +702,11 @@ static BOOL do_section(char *sectionname)
        isglobal = strwicmp(sectionname, GLOBAL_NAME) == 0;
 
        /* if we were in a global section then do the local inits */
        isglobal = strwicmp(sectionname, GLOBAL_NAME) == 0;
 
        /* if we were in a global section then do the local inits */
-       if (bInGlobalSection && !isglobal)
+       if (bInGlobalSection && !isglobal) {
+               if (!section_list.count)
+                       set_dparams(0);
                init_locals();
                init_locals();
+       }
 
        /* if we've just struck a global section, note the fact. */
        bInGlobalSection = isglobal;
 
        /* if we've just struck a global section, note the fact. */
        bInGlobalSection = isglobal;
@@ -745,6 +751,30 @@ int lp_load(char *pszFname, int globals_only)
        return pm_process(pszFname, globals_only ? NULL : do_section, do_parameter);
 }
 
        return pm_process(pszFname, globals_only ? NULL : do_section, do_parameter);
 }
 
+BOOL set_dparams(int syntax_check_only)
+{
+       char *equal, *val, **params = dparam_list.items;
+       unsigned j;
+
+       for (j = 0; j < dparam_list.count; j++) {
+               equal = strchr(params[j], '='); /* options.c verified this */
+               *equal = '\0';
+               if (syntax_check_only) {
+                       if (map_parameter(params[j]) < 0) {
+                               rprintf(FCLIENT, "Unknown parameter \"%s\"\n", params[j]);
+                               *equal = '=';
+                               return False;
+                       }
+               } else {
+                       for (val = equal+1; isSpace(val); val++) {}
+                       do_parameter(params[j], val);
+               }
+               *equal = '=';
+       }
+
+       return True;
+}
+
 /* Return the max number of modules (sections). */
 int lp_num_modules(void)
 {
 /* Return the max number of modules (sections). */
 int lp_num_modules(void)
 {
index dce215e..4fd2565 100644 (file)
--- a/options.c
+++ b/options.c
@@ -121,6 +121,7 @@ int inplace = 0;
 int delay_updates = 0;
 long block_size = 0; /* "long" because popt can't set an int32. */
 char *skip_compress = NULL;
 int delay_updates = 0;
 long block_size = 0; /* "long" because popt can't set an int32. */
 char *skip_compress = NULL;
+item_list dparam_list = EMPTY_ITEM_LIST;
 
 /** Network address family. **/
 int default_af_hint
 
 /** Network address family. **/
 int default_af_hint
@@ -992,6 +993,7 @@ static struct poptOption long_options[] = {
   /* All the following options switch us into daemon-mode option-parsing. */
   {"config",           0,  POPT_ARG_STRING, 0, OPT_DAEMON, 0, 0 },
   {"daemon",           0,  POPT_ARG_NONE,   0, OPT_DAEMON, 0, 0 },
   /* All the following options switch us into daemon-mode option-parsing. */
   {"config",           0,  POPT_ARG_STRING, 0, OPT_DAEMON, 0, 0 },
   {"daemon",           0,  POPT_ARG_NONE,   0, OPT_DAEMON, 0, 0 },
+  {"dparam",           0,  POPT_ARG_STRING, 0, OPT_DAEMON, 0, 0 },
   {"detach",           0,  POPT_ARG_NONE,   0, OPT_DAEMON, 0, 0 },
   {"no-detach",        0,  POPT_ARG_NONE,   0, OPT_DAEMON, 0, 0 },
   {0,0,0,0, 0, 0, 0}
   {"detach",           0,  POPT_ARG_NONE,   0, OPT_DAEMON, 0, 0 },
   {"no-detach",        0,  POPT_ARG_NONE,   0, OPT_DAEMON, 0, 0 },
   {0,0,0,0, 0, 0, 0}
@@ -1006,6 +1008,7 @@ static void daemon_usage(enum logcode F)
   rprintf(F,"     --address=ADDRESS       bind to the specified address\n");
   rprintf(F,"     --bwlimit=KBPS          limit I/O bandwidth; KBytes per second\n");
   rprintf(F,"     --config=FILE           specify alternate rsyncd.conf file\n");
   rprintf(F,"     --address=ADDRESS       bind to the specified address\n");
   rprintf(F,"     --bwlimit=KBPS          limit I/O bandwidth; KBytes per second\n");
   rprintf(F,"     --config=FILE           specify alternate rsyncd.conf file\n");
+  rprintf(F," -M, --dparam=OVERRIDE       override global daemon config parameter\n");
   rprintf(F,"     --no-detach             do not detach from the parent\n");
   rprintf(F,"     --port=PORT             listen on alternate port number\n");
   rprintf(F,"     --log-file=FILE         override the \"log file\" setting\n");
   rprintf(F,"     --no-detach             do not detach from the parent\n");
   rprintf(F,"     --port=PORT             listen on alternate port number\n");
   rprintf(F,"     --log-file=FILE         override the \"log file\" setting\n");
@@ -1027,6 +1030,7 @@ static struct poptOption long_daemon_options[] = {
   {"bwlimit",          0,  POPT_ARG_INT,    &daemon_bwlimit, 0, 0, 0 },
   {"config",           0,  POPT_ARG_STRING, &config_file, 0, 0, 0 },
   {"daemon",           0,  POPT_ARG_NONE,   &daemon_opt, 0, 0, 0 },
   {"bwlimit",          0,  POPT_ARG_INT,    &daemon_bwlimit, 0, 0, 0 },
   {"config",           0,  POPT_ARG_STRING, &config_file, 0, 0, 0 },
   {"daemon",           0,  POPT_ARG_NONE,   &daemon_opt, 0, 0, 0 },
+  {"dparam",          'M', POPT_ARG_STRING, 0, 'M', 0, 0 },
   {"ipv4",            '4', POPT_ARG_VAL,    &default_af_hint, AF_INET, 0, 0 },
   {"ipv6",            '6', POPT_ARG_VAL,    &default_af_hint, AF_INET6, 0, 0 },
   {"detach",           0,  POPT_ARG_VAL,    &no_detach, 0, 0, 0 },
   {"ipv4",            '4', POPT_ARG_VAL,    &default_af_hint, AF_INET, 0, 0 },
   {"ipv6",            '6', POPT_ARG_VAL,    &default_af_hint, AF_INET6, 0, 0 },
   {"detach",           0,  POPT_ARG_VAL,    &no_detach, 0, 0, 0 },
@@ -1310,11 +1314,24 @@ int parse_arguments(int *argc_p, const char ***argv_p)
                        pc = poptGetContext(RSYNC_NAME, argc, argv,
                                            long_daemon_options, 0);
                        while ((opt = poptGetNextOpt(pc)) != -1) {
                        pc = poptGetContext(RSYNC_NAME, argc, argv,
                                            long_daemon_options, 0);
                        while ((opt = poptGetNextOpt(pc)) != -1) {
+                               char **cpp;
                                switch (opt) {
                                case 'h':
                                        daemon_usage(FINFO);
                                        exit_cleanup(0);
 
                                switch (opt) {
                                case 'h':
                                        daemon_usage(FINFO);
                                        exit_cleanup(0);
 
+                               case 'M':
+                                       arg = poptGetOptArg(pc);
+                                       if (!strchr(arg, '=')) {
+                                               rprintf(FERROR,
+                                                   "--dparam value is missing an '=': %s\n",
+                                                   arg);
+                                               goto daemon_error;
+                                       }
+                                       cpp = EXPAND_ITEM_LIST(&dparam_list, char *, 4);
+                                       *cpp = strdup(arg);
+                                       break;
+
                                case 'v':
                                        verbose++;
                                        break;
                                case 'v':
                                        verbose++;
                                        break;
@@ -1328,6 +1345,9 @@ int parse_arguments(int *argc_p, const char ***argv_p)
                                }
                        }
 
                                }
                        }
 
+                       if (dparam_list.count && !set_dparams(1))
+                               exit_cleanup(RERR_SYNTAX);
+
                        if (tmpdir && strlen(tmpdir) >= MAXPATHLEN - 10) {
                                snprintf(err_buf, sizeof err_buf,
                                         "the --temp-dir path is WAY too long.\n");
                        if (tmpdir && strlen(tmpdir) >= MAXPATHLEN - 10) {
                                snprintf(err_buf, sizeof err_buf,
                                         "the --temp-dir path is WAY too long.\n");
index c34d4be..08e3bbc 100644 (file)
--- a/rsync.yo
+++ b/rsync.yo
@@ -438,6 +438,7 @@ accepted: verb(
      --address=ADDRESS       bind to the specified address
      --bwlimit=KBPS          limit I/O bandwidth; KBytes per second
      --config=FILE           specify alternate rsyncd.conf file
      --address=ADDRESS       bind to the specified address
      --bwlimit=KBPS          limit I/O bandwidth; KBytes per second
      --config=FILE           specify alternate rsyncd.conf file
+ -M, --dparam=OVERRIDE       override global daemon config parameter
      --no-detach             do not detach from the parent
      --port=PORT             listen on alternate port number
      --log-file=FILE         override the "log file" setting
      --no-detach             do not detach from the parent
      --port=PORT             listen on alternate port number
      --log-file=FILE         override the "log file" setting
@@ -2220,6 +2221,14 @@ The default is /etc/rsyncd.conf unless the daemon is running over
 a remote shell program and the remote user is not the super-user; in that case
 the default is rsyncd.conf in the current directory (typically $HOME).
 
 a remote shell program and the remote user is not the super-user; in that case
 the default is rsyncd.conf in the current directory (typically $HOME).
 
+dit(bf(-M, --dparam=OVERRIDE)) This option can be used to set a daemon-config
+parameter when starting up rsync in daemon mode.  It is equivalent to adding
+the parameter at the end of the global settings prior to the first module's
+definition.  The parameter names can be specified without spaces, if you so
+desire.  For instance:
+
+verb(    rsync --daemon -M pidfile=/path/rsync.pid )
+
 dit(bf(--no-detach)) When running as a daemon, this option instructs
 rsync to not detach itself and become a background process.  This
 option is required when running as a service on Cygwin, and may also
 dit(bf(--no-detach)) When running as a daemon, this option instructs
 rsync to not detach itself and become a background process.  This
 option is required when running as a service on Cygwin, and may also
index 9c94bbf..f6f34a6 100644 (file)
@@ -83,10 +83,14 @@ dit(bf(motd file)) This parameter allows you to specify a
 "message of the day" to display to clients on each connect. This
 usually contains site information and any legal notices. The default
 is no motd file.
 "message of the day" to display to clients on each connect. This
 usually contains site information and any legal notices. The default
 is no motd file.
+This can be overridden by the bf(--dparam=motdfile=FILE)
+command-line option when starting the daemon.
 
 dit(bf(pid file)) This parameter tells the rsync daemon to write
 its process ID to that file.  If the file already exists, the rsync
 daemon will abort rather than overwrite the file.
 
 dit(bf(pid file)) This parameter tells the rsync daemon to write
 its process ID to that file.  If the file already exists, the rsync
 daemon will abort rather than overwrite the file.
+This can be overridden by the bf(--dparam=pidfile=FILE)
+command-line option when starting the daemon.
 
 dit(bf(port)) You can override the default port the daemon will listen on
 by specifying this value (defaults to 873).  This is ignored if the daemon
 
 dit(bf(port)) You can override the default port the daemon will listen on
 by specifying this value (defaults to 873).  This is ignored if the daemon
@@ -101,12 +105,11 @@ who like to tune their systems to the utmost degree. You can set all
 sorts of socket options which may make transfers faster (or
 slower!). Read the man page for the code(setsockopt()) system call for
 details on some of the options you may be able to set. By default no
 sorts of socket options which may make transfers faster (or
 slower!). Read the man page for the code(setsockopt()) system call for
 details on some of the options you may be able to set. By default no
-special socket options are set.  These settings are superseded by the
-bf(--sockopts) command-line option.
+special socket options are set.  These settings can also be specified
+via the bf(--sockopts) command-line option.
 
 enddit()
 
 
 enddit()
 
-
 manpagesection(MODULE PARAMETERS)
 
 After the global parameters you should define a number of modules, each
 manpagesection(MODULE PARAMETERS)
 
 After the global parameters you should define a number of modules, each
@@ -256,10 +259,16 @@ the transfer.  If this value is set on a per-module basis instead of
 globally, the global log will still contain any authorization failures
 or config-file error messages.
 
 globally, the global log will still contain any authorization failures
 or config-file error messages.
 
-If the daemon fails to open to specified file, it will fall back to
+If the daemon fails to open the specified file, it will fall back to
 using syslog and output an error about the failure.  (Note that the
 failure to open the specified log file used to be a fatal error.)
 
 using syslog and output an error about the failure.  (Note that the
 failure to open the specified log file used to be a fatal error.)
 
+This setting can be overridden by using the bf(--log-file=FILE) or
+bf(--dparam=logfile=FILE) command-line options.  The former overrides
+all the log-file parameters of the daemon and all module settings.
+The latter sets the daemon's log file and the default for all the
+modules, which still allows modules to override the default setting.
+
 dit(bf(syslog facility)) This parameter allows you to
 specify the syslog facility name to use when logging messages from the
 rsync daemon. You may use any standard syslog facility name which is
 dit(bf(syslog facility)) This parameter allows you to
 specify the syslog facility name to use when logging messages from the
 rsync daemon. You may use any standard syslog facility name which is