1 This patch adds a daemon option, --dparam (-M), that lets you override
2 global/default items in the config file when starting the daemon up.
4 To use this patch, run these commands for a successful build:
6 patch -p1 <patches/dparam.diff
7 ./configure (optional if already run)
10 based-on: 40afd365cc8ca968fd16e161d24df5b8a8a520cc
11 diff --git a/clientserver.c b/clientserver.c
14 @@ -1055,6 +1055,7 @@ int daemon_main(void)
15 fprintf(stderr, "Failed to parse config file: %s\n", config_file);
16 exit_cleanup(RERR_SYNTAX);
22 diff --git a/loadparm.c b/loadparm.c
30 +extern item_list dparam_list;
32 #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((char *)(p1)) - (char *)(p2)))
33 #define strequal(a,b) (strcasecmp(a,b)==0)
34 #define BOOLSTR(b) ((b) ? "Yes" : "No")
35 @@ -778,8 +781,11 @@ static BOOL do_section(char *sectionname)
38 /* if we were in a global section then do the local inits */
39 - if (bInGlobalSection && !isglobal)
40 + if (bInGlobalSection && !isglobal) {
46 /* if we've just struck a global section, note the fact. */
47 bInGlobalSection = isglobal;
48 @@ -842,6 +848,29 @@ BOOL lp_load(char *pszFname, int globals_only)
52 +BOOL set_dparams(int syntax_check_only)
54 + char *equal, *val, **params = dparam_list.items;
57 + for (j = 0; j < dparam_list.count; j++) {
58 + equal = strchr(params[j], '='); /* options.c verified this */
60 + if (syntax_check_only) {
61 + if (map_parameter(params[j]) < 0) {
62 + rprintf(FCLIENT, "Unknown parameter \"%s\"\n", params[j]);
67 + for (val = equal+1; isSpace(val); val++) {}
68 + do_parameter(params[j], val);
76 /***************************************************************************
77 * return the max number of services
78 diff --git a/options.c b/options.c
81 @@ -122,6 +122,7 @@ int inplace = 0;
82 int delay_updates = 0;
83 long block_size = 0; /* "long" because popt can't set an int32. */
84 char *skip_compress = NULL;
85 +item_list dparam_list = EMPTY_ITEM_LIST;
87 /** Network address family. **/
89 @@ -651,6 +652,7 @@ static struct poptOption long_options[] = {
90 /* All the following options switch us into daemon-mode option-parsing. */
91 {"config", 0, POPT_ARG_STRING, 0, OPT_DAEMON, 0, 0 },
92 {"daemon", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
93 + {"dparam", 0, POPT_ARG_STRING, 0, OPT_DAEMON, 0, 0 },
94 {"detach", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
95 {"no-detach", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
97 @@ -665,6 +667,7 @@ static void daemon_usage(enum logcode F)
98 rprintf(F," --address=ADDRESS bind to the specified address\n");
99 rprintf(F," --bwlimit=KBPS limit I/O bandwidth; KBytes per second\n");
100 rprintf(F," --config=FILE specify alternate rsyncd.conf file\n");
101 + rprintf(F," -M, --dparam=OVERRIDE override global daemon config parameter\n");
102 rprintf(F," --no-detach do not detach from the parent\n");
103 rprintf(F," --port=PORT listen on alternate port number\n");
104 rprintf(F," --log-file=FILE override the \"log file\" setting\n");
105 @@ -686,6 +689,7 @@ static struct poptOption long_daemon_options[] = {
106 {"bwlimit", 0, POPT_ARG_INT, &daemon_bwlimit, 0, 0, 0 },
107 {"config", 0, POPT_ARG_STRING, &config_file, 0, 0, 0 },
108 {"daemon", 0, POPT_ARG_NONE, &daemon_opt, 0, 0, 0 },
109 + {"dparam", 'M', POPT_ARG_STRING, 0, 'M', 0, 0 },
110 {"ipv4", '4', POPT_ARG_VAL, &default_af_hint, AF_INET, 0, 0 },
111 {"ipv6", '6', POPT_ARG_VAL, &default_af_hint, AF_INET6, 0, 0 },
112 {"detach", 0, POPT_ARG_VAL, &no_detach, 0, 0, 0 },
113 @@ -969,11 +973,24 @@ int parse_arguments(int *argc_p, const char ***argv_p)
114 pc = poptGetContext(RSYNC_NAME, argc, argv,
115 long_daemon_options, 0);
116 while ((opt = poptGetNextOpt(pc)) != -1) {
124 + arg = poptGetOptArg(pc);
125 + if (!strchr(arg, '=')) {
127 + "--dparam value is missing an '=': %s\n",
131 + cpp = EXPAND_ITEM_LIST(&dparam_list, char *, 4);
132 + *cpp = strdup(arg);
138 @@ -987,6 +1004,9 @@ int parse_arguments(int *argc_p, const char ***argv_p)
142 + if (dparam_list.count && !set_dparams(1))
143 + exit_cleanup(RERR_SYNTAX);
145 if (tmpdir && strlen(tmpdir) >= MAXPATHLEN - 10) {
146 snprintf(err_buf, sizeof err_buf,
147 "the --temp-dir path is WAY too long.\n");
148 diff --git a/rsync.yo b/rsync.yo
151 @@ -452,6 +452,7 @@ accepted: verb(
152 --address=ADDRESS bind to the specified address
153 --bwlimit=KBPS limit I/O bandwidth; KBytes per second
154 --config=FILE specify alternate rsyncd.conf file
155 + -M, --dparam=OVERRIDE override global daemon config parameter
156 --no-detach do not detach from the parent
157 --port=PORT listen on alternate port number
158 --log-file=FILE override the "log file" setting
159 @@ -2271,6 +2272,14 @@ The default is /etc/rsyncd.conf unless the daemon is running over
160 a remote shell program and the remote user is not the super-user; in that case
161 the default is rsyncd.conf in the current directory (typically $HOME).
163 +dit(bf(-M, --dparam=OVERRIDE)) This option can be used to set a daemon-config
164 +parameter when starting up rsync in daemon mode. It is equivalent to adding
165 +the parameter at the end of the global settings prior to the first module's
166 +definition. The parameter names can be specified without spaces, if you so
167 +desire. For instance:
169 +verb( rsync --daemon -M pidfile=/path/rsync.pid )
171 dit(bf(--no-detach)) When running as a daemon, this option instructs
172 rsync to not detach itself and become a background process. This
173 option is required when running as a service on Cygwin, and may also
174 diff --git a/rsyncd.conf.yo b/rsyncd.conf.yo
177 @@ -83,10 +83,14 @@ dit(bf(motd file)) This parameter allows you to specify a
178 "message of the day" to display to clients on each connect. This
179 usually contains site information and any legal notices. The default
181 +This can be overridden by the bf(--dparam=motdfile=FILE)
182 +command-line option when starting the daemon.
184 dit(bf(pid file)) This parameter tells the rsync daemon to write
185 its process ID to that file. If the file already exists, the rsync
186 daemon will abort rather than overwrite the file.
187 +This can be overridden by the bf(--dparam=pidfile=FILE)
188 +command-line option when starting the daemon.
190 dit(bf(port)) You can override the default port the daemon will listen on
191 by specifying this value (defaults to 873). This is ignored if the daemon
192 @@ -266,6 +270,12 @@ If the daemon fails to open the specified file, it will fall back to
193 using syslog and output an error about the failure. (Note that the
194 failure to open the specified log file used to be a fatal error.)
196 +This setting can be overridden by using the bf(--log-file=FILE) or
197 +bf(--dparam=logfile=FILE) command-line options. The former overrides
198 +all the log-file parameters of the daemon and all module settings.
199 +The latter sets the daemon's log file and the default for all the
200 +modules, which still allows modules to override the default setting.
202 dit(bf(syslog facility)) This parameter allows you to
203 specify the syslog facility name to use when logging messages from the
204 rsync daemon. You may use any standard syslog facility name which is