Use "use warnings" rather than -w on the #! line.
[rsync/rsync-patches.git] / dparam.diff
CommitLineData
3215b7e1
WD
1This patch adds a daemon option, --dparam (-M), that lets you override
2global/default items in the config file when starting the daemon up.
3
4To use this patch, run these commands for a successful build:
5
6 patch -p1 <patches/dparam.diff
7 ./configure (optional if already run)
8 make
9
10diff --git a/clientserver.c b/clientserver.c
11--- a/clientserver.c
12+++ b/clientserver.c
abd3adb8 13@@ -1045,6 +1045,7 @@ int daemon_main(void)
3215b7e1
WD
14 fprintf(stderr, "Failed to parse config file: %s\n", config_file);
15 exit_cleanup(RERR_SYNTAX);
16 }
17+ set_dparams(0);
18
19 if (no_detach)
20 create_pid_file();
21diff --git a/loadparm.c b/loadparm.c
22--- a/loadparm.c
23+++ b/loadparm.c
24@@ -51,6 +51,9 @@
25
26 #include "rsync.h"
27 #include "ifuncs.h"
28+
29+extern item_list dparam_list;
30+
31 #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((char *)(p1)) - (char *)(p2)))
32 #define strequal(a,b) (strcasecmp(a,b)==0)
33 #define BOOLSTR(b) ((b) ? "Yes" : "No")
34@@ -780,8 +783,11 @@ static BOOL do_section(char *sectionname)
35 bRetval = False;
36
37 /* if we were in a global section then do the local inits */
38- if (bInGlobalSection && !isglobal)
39+ if (bInGlobalSection && !isglobal) {
40+ if (!iNumServices)
41+ set_dparams(0);
42 init_locals();
43+ }
44
45 /* if we've just struck a global section, note the fact. */
46 bInGlobalSection = isglobal;
47@@ -844,6 +850,29 @@ BOOL lp_load(char *pszFname, int globals_only)
48 return (bRetval);
49 }
50
51+BOOL set_dparams(int syntax_check_only)
52+{
53+ char *equal, *val, **params = dparam_list.items;
54+ unsigned j;
55+
56+ for (j = 0; j < dparam_list.count; j++) {
57+ equal = strchr(params[j], '='); /* options.c verified this */
58+ *equal = '\0';
59+ if (syntax_check_only) {
60+ if (map_parameter(params[j]) < 0) {
61+ rprintf(FCLIENT, "Unknown parameter \"%s\"\n", params[j]);
62+ *equal = '=';
63+ return False;
64+ }
65+ } else {
66+ for (val = equal+1; isSpace(val); val++) {}
67+ do_parameter(params[j], val);
68+ }
69+ *equal = '=';
70+ }
71+
72+ return True;
73+}
74
75 /***************************************************************************
76 * return the max number of services
77diff --git a/options.c b/options.c
78--- a/options.c
79+++ b/options.c
80@@ -124,6 +124,7 @@ int inplace = 0;
81 int delay_updates = 0;
82 long block_size = 0; /* "long" because popt can't set an int32. */
83 char *skip_compress = NULL;
84+item_list dparam_list = EMPTY_ITEM_LIST;
85
86 /** Network address family. **/
87 int default_af_hint
abd3adb8 88@@ -653,6 +654,7 @@ static struct poptOption long_options[] = {
3215b7e1
WD
89 /* All the following options switch us into daemon-mode option-parsing. */
90 {"config", 0, POPT_ARG_STRING, 0, OPT_DAEMON, 0, 0 },
91 {"daemon", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
92+ {"dparam", 0, POPT_ARG_STRING, 0, OPT_DAEMON, 0, 0 },
93 {"detach", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
94 {"no-detach", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
95 {0,0,0,0, 0, 0, 0}
abd3adb8 96@@ -667,6 +669,7 @@ static void daemon_usage(enum logcode F)
3215b7e1
WD
97 rprintf(F," --address=ADDRESS bind to the specified address\n");
98 rprintf(F," --bwlimit=KBPS limit I/O bandwidth; KBytes per second\n");
99 rprintf(F," --config=FILE specify alternate rsyncd.conf file\n");
100+ rprintf(F," -M, --dparam=OVERRIDE override global daemon config parameter\n");
101 rprintf(F," --no-detach do not detach from the parent\n");
102 rprintf(F," --port=PORT listen on alternate port number\n");
103 rprintf(F," --log-file=FILE override the \"log file\" setting\n");
abd3adb8 104@@ -688,6 +691,7 @@ static struct poptOption long_daemon_options[] = {
3215b7e1
WD
105 {"bwlimit", 0, POPT_ARG_INT, &daemon_bwlimit, 0, 0, 0 },
106 {"config", 0, POPT_ARG_STRING, &config_file, 0, 0, 0 },
107 {"daemon", 0, POPT_ARG_NONE, &daemon_opt, 0, 0, 0 },
108+ {"dparam", 'M', POPT_ARG_STRING, 0, 'M', 0, 0 },
109 {"ipv4", '4', POPT_ARG_VAL, &default_af_hint, AF_INET, 0, 0 },
110 {"ipv6", '6', POPT_ARG_VAL, &default_af_hint, AF_INET6, 0, 0 },
111 {"detach", 0, POPT_ARG_VAL, &no_detach, 0, 0, 0 },
abd3adb8 112@@ -971,11 +975,24 @@ int parse_arguments(int *argc_p, const char ***argv_p)
3215b7e1
WD
113 pc = poptGetContext(RSYNC_NAME, argc, argv,
114 long_daemon_options, 0);
115 while ((opt = poptGetNextOpt(pc)) != -1) {
116+ char **cpp;
117 switch (opt) {
118 case 'h':
119 daemon_usage(FINFO);
120 exit_cleanup(0);
121
122+ case 'M':
123+ arg = poptGetOptArg(pc);
124+ if (!strchr(arg, '=')) {
125+ rprintf(FERROR,
126+ "--dparam value is missing an '=': %s\n",
127+ arg);
128+ goto daemon_error;
129+ }
130+ cpp = EXPAND_ITEM_LIST(&dparam_list, char *, 4);
131+ *cpp = strdup(arg);
132+ break;
133+
134 case 'v':
135 verbose++;
136 break;
abd3adb8 137@@ -989,6 +1006,9 @@ int parse_arguments(int *argc_p, const char ***argv_p)
3215b7e1
WD
138 }
139 }
140
141+ if (dparam_list.count && !set_dparams(1))
142+ exit_cleanup(RERR_SYNTAX);
143+
144 if (tmpdir && strlen(tmpdir) >= MAXPATHLEN - 10) {
145 snprintf(err_buf, sizeof err_buf,
146 "the --temp-dir path is WAY too long.\n");
147diff --git a/rsync.yo b/rsync.yo
148--- a/rsync.yo
149+++ b/rsync.yo
abd3adb8 150@@ -439,6 +439,7 @@ accepted: verb(
3215b7e1
WD
151 --address=ADDRESS bind to the specified address
152 --bwlimit=KBPS limit I/O bandwidth; KBytes per second
153 --config=FILE specify alternate rsyncd.conf file
154+ -M, --dparam=OVERRIDE override global daemon config parameter
155 --no-detach do not detach from the parent
156 --port=PORT listen on alternate port number
157 --log-file=FILE override the "log file" setting
abd3adb8 158@@ -2147,6 +2148,14 @@ The default is /etc/rsyncd.conf unless the daemon is running over
3215b7e1
WD
159 a remote shell program and the remote user is not the super-user; in that case
160 the default is rsyncd.conf in the current directory (typically $HOME).
161
162+dit(bf(-M, --dparam=OVERRIDE)) This option can be used to set a daemon-config
163+parameter when starting up rsync in daemon mode. It is equivalent to adding
164+the parameter at the end of the global settings prior to the first module's
165+definition. The parameter names can be specified without spaces, if you so
166+desire. For instance:
167+
168+verb( rsync --daemon -M pidfile=/path/rsync.pid )
169+
170 dit(bf(--no-detach)) When running as a daemon, this option instructs
171 rsync to not detach itself and become a background process. This
172 option is required when running as a service on Cygwin, and may also
173diff --git a/rsyncd.conf.yo b/rsyncd.conf.yo
174--- a/rsyncd.conf.yo
175+++ b/rsyncd.conf.yo
176@@ -83,10 +83,14 @@ dit(bf(motd file)) This parameter allows you to specify a
177 "message of the day" to display to clients on each connect. This
178 usually contains site information and any legal notices. The default
179 is no motd file.
180+This can be overridden by the bf(--dparam=motdfile=FILE)
181+command-line option when starting the daemon.
182
183 dit(bf(pid file)) This parameter tells the rsync daemon to write
184 its process ID to that file. If the file already exists, the rsync
185 daemon will abort rather than overwrite the file.
186+This can be overridden by the bf(--dparam=pidfile=FILE)
187+command-line option when starting the daemon.
188
189 dit(bf(port)) You can override the default port the daemon will listen on
190 by specifying this value (defaults to 873). This is ignored if the daemon
ae306a29 191@@ -260,6 +264,12 @@ If the daemon fails to open the specified file, it will fall back to
3215b7e1
WD
192 using syslog and output an error about the failure. (Note that the
193 failure to open the specified log file used to be a fatal error.)
194
195+This setting can be overridden by using the bf(--log-file=FILE) or
196+bf(--dparam=logfile=FILE) command-line options. The former overrides
197+all the log-file parameters of the daemon and all module settings.
198+The latter sets the daemon's log file and the default for all the
199+modules, which still allows modules to override the default setting.
200+
201 dit(bf(syslog facility)) This parameter allows you to
202 specify the syslog facility name to use when logging messages from the
203 rsync daemon. You may use any standard syslog facility name which is