The patches for 3.0.9.
[rsync.git/patches.git] / dparam.diff
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.
3
4 To 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
10 based-on: 40afd365cc8ca968fd16e161d24df5b8a8a520cc
11 diff --git a/clientserver.c b/clientserver.c
12 --- a/clientserver.c
13 +++ 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);
17         }
18 +       set_dparams(0);
19  
20         if (no_detach)
21                 create_pid_file();
22 diff --git a/loadparm.c b/loadparm.c
23 --- a/loadparm.c
24 +++ b/loadparm.c
25 @@ -49,6 +49,9 @@
26  
27  #include "rsync.h"
28  #include "ifuncs.h"
29 +
30 +extern item_list dparam_list;
31 +
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)
36     bRetval = False;
37  
38     /* if we were in a global section then do the local inits */
39 -   if (bInGlobalSection && !isglobal)
40 +   if (bInGlobalSection && !isglobal) {
41 +     if (!iNumServices)
42 +       set_dparams(0);
43       init_locals();
44 +   }
45  
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)
49         return (bRetval);
50  }
51  
52 +BOOL set_dparams(int syntax_check_only)
53 +{
54 +       char *equal, *val, **params = dparam_list.items;
55 +       unsigned j;
56 +
57 +       for (j = 0; j < dparam_list.count; j++) {
58 +               equal = strchr(params[j], '='); /* options.c verified this */
59 +               *equal = '\0';
60 +               if (syntax_check_only) {
61 +                       if (map_parameter(params[j]) < 0) {
62 +                               rprintf(FCLIENT, "Unknown parameter \"%s\"\n", params[j]);
63 +                               *equal = '=';
64 +                               return False;
65 +                       }
66 +               } else {
67 +                       for (val = equal+1; isSpace(val); val++) {}
68 +                       do_parameter(params[j], val);
69 +               }
70 +               *equal = '=';
71 +       }
72 +
73 +       return True;
74 +}
75  
76  /***************************************************************************
77  * return the max number of services
78 diff --git a/options.c b/options.c
79 --- a/options.c
80 +++ 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;
86  
87  /** Network address family. **/
88  int default_af_hint
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 },
96    {0,0,0,0, 0, 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) {
117 +                               char **cpp;
118                                 switch (opt) {
119                                 case 'h':
120                                         daemon_usage(FINFO);
121                                         exit_cleanup(0);
122  
123 +                               case 'M':
124 +                                       arg = poptGetOptArg(pc);
125 +                                       if (!strchr(arg, '=')) {
126 +                                               rprintf(FERROR,
127 +                                                   "--dparam value is missing an '=': %s\n",
128 +                                                   arg);
129 +                                               goto daemon_error;
130 +                                       }
131 +                                       cpp = EXPAND_ITEM_LIST(&dparam_list, char *, 4);
132 +                                       *cpp = strdup(arg);
133 +                                       break;
134 +
135                                 case 'v':
136                                         verbose++;
137                                         break;
138 @@ -987,6 +1004,9 @@ int parse_arguments(int *argc_p, const char ***argv_p)
139                                 }
140                         }
141  
142 +                       if (dparam_list.count && !set_dparams(1))
143 +                               exit_cleanup(RERR_SYNTAX);
144 +
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
149 --- a/rsync.yo
150 +++ 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).
162  
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:
168 +
169 +verb(    rsync --daemon -M pidfile=/path/rsync.pid )
170 +
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
175 --- a/rsyncd.conf.yo
176 +++ 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
180  is no motd file.
181 +This can be overridden by the bf(--dparam=motdfile=FILE)
182 +command-line option when starting the daemon.
183  
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.
189  
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.)
195  
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.
201 +
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