dovecot-2.0: Binaries now take -o key=value parameters to overri...
dovecot at dovecot.org
dovecot at dovecot.org
Wed May 6 22:01:58 EEST 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/1cb45d4389d4
changeset: 9239:1cb45d4389d4
user: Timo Sirainen <tss at iki.fi>
date: Wed May 06 15:01:49 2009 -0400
description:
Binaries now take -o key=value parameters to override settings.
diffstat:
5 files changed, 59 insertions(+), 15 deletions(-)
src/lib-master/master-service-private.h | 1
src/lib-master/master-service-settings.c | 28 +++++++++++++++++++++++++
src/lib-master/master-service.c | 10 ++++++++-
src/lib-settings/settings-parser.c | 33 +++++++++++++++++-------------
src/lib-settings/settings-parser.h | 2 +
diffs (157 lines):
diff -r c57038025171 -r 1cb45d4389d4 src/lib-master/master-service-private.h
--- a/src/lib-master/master-service-private.h Wed May 06 14:58:31 2009 -0400
+++ b/src/lib-master/master-service-private.h Wed May 06 15:01:49 2009 -0400
@@ -23,6 +23,7 @@ struct master_service {
const char *version_string;
const char *config_path;
int syslog_facility;
+ ARRAY_TYPE(const_string) config_overrides;
unsigned int socket_count, ssl_socket_count;
struct master_service_listener *listeners;
diff -r c57038025171 -r 1cb45d4389d4 src/lib-master/master-service-settings.c
--- a/src/lib-master/master-service-settings.c Wed May 06 14:58:31 2009 -0400
+++ b/src/lib-master/master-service-settings.c Wed May 06 15:01:49 2009 -0400
@@ -121,6 +121,28 @@ master_service_read_config(struct master
return fd;
}
+static int
+master_service_apply_config_overrides(struct master_service *service,
+ struct setting_parser_context *parser,
+ const char **error_r)
+{
+ const char *const *overrides;
+ unsigned int i, count;
+
+ overrides = array_get(&service->config_overrides, &count);
+ for (i = 0; i < count; i++) {
+ if (settings_parse_line(parser, overrides[i]) < 0) {
+ *error_r = t_strdup_printf(
+ "Invalid -o parameter %s: %s", overrides[i],
+ settings_parser_get_error(parser));
+ return -1;
+ }
+ settings_parse_set_key_expandeded(parser, service->set_pool,
+ t_strcut(overrides[i], '='));
+ }
+ return 0;
+}
+
int master_service_settings_read(struct master_service *service,
const struct setting_parser_info *roots[],
const struct dynamic_settings_parser *dyn_parsers,
@@ -187,6 +209,12 @@ int master_service_settings_read(struct
keys);
}
+ if (array_is_created(&service->config_overrides)) {
+ if (master_service_apply_config_overrides(service, parser,
+ error_r) < 0)
+ return -1;
+ }
+
if (!settings_parser_check(parser, service->set_pool, &error)) {
*error_r = t_strdup_printf("Invalid settings: %s", error);
return -1;
diff -r c57038025171 -r 1cb45d4389d4 src/lib-master/master-service.c
--- a/src/lib-master/master-service.c Wed May 06 14:58:31 2009 -0400
+++ b/src/lib-master/master-service.c Wed May 06 15:01:49 2009 -0400
@@ -3,6 +3,7 @@
#include "lib.h"
#include "lib-signals.h"
#include "ioloop.h"
+#include "array.h"
#include "env-util.h"
#include "home-expand.h"
#include "restrict-access.h"
@@ -30,7 +31,7 @@ static void master_status_update(struct
const char *master_service_getopt_string(void)
{
- return "c:ks:L";
+ return "c:ko:s:L";
}
static void sig_die(const siginfo_t *si, void *context)
@@ -182,6 +183,11 @@ bool master_service_parse_option(struct
break;
case 'k':
service->keep_environment = TRUE;
+ break;
+ case 'o':
+ if (!array_is_created(&service->config_overrides))
+ i_array_init(&service->config_overrides, 16);
+ array_append(&service->config_overrides, &arg, 1);
break;
case 's':
if ((i = atoi(arg)) < 0)
@@ -420,6 +426,8 @@ void master_service_deinit(struct master
io_remove(&service->io_status_error);
if (service->io_status_write != NULL)
io_remove(&service->io_status_write);
+ if (array_is_created(&service->config_overrides))
+ array_free(&service->config_overrides);
lib_signals_deinit();
io_loop_destroy(&service->ioloop);
diff -r c57038025171 -r 1cb45d4389d4 src/lib-settings/settings-parser.c
--- a/src/lib-settings/settings-parser.c Wed May 06 14:58:31 2009 -0400
+++ b/src/lib-settings/settings-parser.c Wed May 06 15:01:49 2009 -0400
@@ -765,25 +765,30 @@ settings_var_expand_info(const struct se
}
}
-void settings_parse_set_keys_expandeded(struct setting_parser_context *ctx,
- pool_t pool, const char *const *keys)
+void settings_parse_set_key_expandeded(struct setting_parser_context *ctx,
+ pool_t pool, const char *key)
{
const struct setting_define *def;
struct setting_link *link;
const char **val;
- for (; *keys != NULL; keys++) {
- if (!settings_find_key(ctx, *keys, &def, &link))
- continue;
-
- val = PTR_OFFSET(link->set_struct, def->offset);
- if (def->type == SET_STR_VARS && *val != NULL) {
- i_assert(**val == SETTING_STRVAR_UNEXPANDED[0] ||
- **val == SETTING_STRVAR_EXPANDED[0]);
- *val = p_strconcat(pool, SETTING_STRVAR_EXPANDED,
- *val + 1, NULL);
- }
- }
+ if (!settings_find_key(ctx, key, &def, &link))
+ return;
+
+ val = PTR_OFFSET(link->set_struct, def->offset);
+ if (def->type == SET_STR_VARS && *val != NULL) {
+ i_assert(**val == SETTING_STRVAR_UNEXPANDED[0] ||
+ **val == SETTING_STRVAR_EXPANDED[0]);
+ *val = p_strconcat(pool, SETTING_STRVAR_EXPANDED,
+ *val + 1, NULL);
+ }
+}
+
+void settings_parse_set_keys_expandeded(struct setting_parser_context *ctx,
+ pool_t pool, const char *const *keys)
+{
+ for (; *keys != NULL; keys++)
+ settings_parse_set_key_expandeded(ctx, pool, *keys);
}
void settings_var_expand(const struct setting_parser_info *info,
diff -r c57038025171 -r 1cb45d4389d4 src/lib-settings/settings-parser.h
--- a/src/lib-settings/settings-parser.h Wed May 06 14:58:31 2009 -0400
+++ b/src/lib-settings/settings-parser.h Wed May 06 15:01:49 2009 -0400
@@ -129,6 +129,8 @@ void settings_parse_set_expanded(struct
void settings_parse_set_expanded(struct setting_parser_context *ctx,
bool is_expanded);
/* Mark all the parsed settings with given keys as being already expanded. */
+void settings_parse_set_key_expandeded(struct setting_parser_context *ctx,
+ pool_t pool, const char *key);
void settings_parse_set_keys_expandeded(struct setting_parser_context *ctx,
pool_t pool, const char *const *keys);
/* Expand all unexpanded variables using the given table. Update the string
More information about the dovecot-cvs
mailing list