dovecot-2.2: lib-settings: settings_read*() now returns an error...
dovecot at dovecot.org
dovecot at dovecot.org
Sat Oct 13 01:09:51 EEST 2012
details: http://hg.dovecot.org/dovecot-2.2/rev/444a9921205a
changeset: 15217:444a9921205a
user: Timo Sirainen <tss at iki.fi>
date: Sat Oct 13 01:03:13 2012 +0300
description:
lib-settings: settings_read*() now returns an error string instead of logging itself
diffstat:
src/auth/db-dict.c | 5 +++--
src/auth/db-ldap.c | 6 +++---
src/auth/db-sql.c | 5 +++--
src/lib-dict/dict-sql-settings.c | 5 ++++-
src/lib-settings/settings.c | 27 ++++++++-------------------
src/lib-settings/settings.h | 11 ++++++-----
6 files changed, 27 insertions(+), 32 deletions(-)
diffs (176 lines):
diff -r cea1d5504a84 -r 444a9921205a src/auth/db-dict.c
--- a/src/auth/db-dict.c Sat Oct 13 00:40:41 2012 +0300
+++ b/src/auth/db-dict.c Sat Oct 13 01:03:13 2012 +0300
@@ -62,6 +62,7 @@
struct dict_connection *db_dict_init(const char *config_path)
{
struct dict_connection *conn;
+ const char *error;
pool_t pool;
conn = dict_conn_find(config_path);
@@ -81,8 +82,8 @@
conn->config_path = p_strdup(pool, config_path);
conn->set = default_dict_settings;
- if (!settings_read_nosection(config_path, parse_setting, conn))
- exit(FATAL_DEFAULT);
+ if (!settings_read_nosection(config_path, parse_setting, conn, &error))
+ i_fatal("dict %s: %s", config_path, error);
if (conn->set.uri == NULL)
i_fatal("dict %s: Empty uri setting", config_path);
diff -r cea1d5504a84 -r 444a9921205a src/auth/db-ldap.c
--- a/src/auth/db-ldap.c Sat Oct 13 00:40:41 2012 +0300
+++ b/src/auth/db-ldap.c Sat Oct 13 01:03:13 2012 +0300
@@ -1376,7 +1376,7 @@
struct ldap_connection *db_ldap_init(const char *config_path, bool userdb)
{
struct ldap_connection *conn;
- const char *str;
+ const char *str, *error;
pool_t pool;
/* see if it already exists */
@@ -1402,8 +1402,8 @@
conn->fd = -1;
conn->config_path = p_strdup(pool, config_path);
conn->set = default_ldap_settings;
- if (!settings_read_nosection(config_path, parse_setting, conn))
- exit(FATAL_DEFAULT);
+ if (!settings_read_nosection(config_path, parse_setting, conn, &error))
+ i_fatal("ldap %s: %s", config_path, error);
if (conn->set.base == NULL)
i_fatal("LDAP: No base given");
diff -r cea1d5504a84 -r 444a9921205a src/auth/db-sql.c
--- a/src/auth/db-sql.c Sat Oct 13 00:40:41 2012 +0300
+++ b/src/auth/db-sql.c Sat Oct 13 01:03:13 2012 +0300
@@ -64,6 +64,7 @@
struct sql_connection *db_sql_init(const char *config_path, bool userdb)
{
struct sql_connection *conn;
+ const char *error;
pool_t pool;
conn = sql_conn_find(config_path);
@@ -86,8 +87,8 @@
conn->config_path = p_strdup(pool, config_path);
conn->set = default_sql_settings;
- if (!settings_read_nosection(config_path, parse_setting, conn))
- exit(FATAL_DEFAULT);
+ if (!settings_read_nosection(config_path, parse_setting, conn, &error))
+ i_fatal("sql %s: %s", config_path, error);
if (conn->set.password_query == default_sql_settings.password_query)
conn->default_password_query = TRUE;
diff -r cea1d5504a84 -r 444a9921205a src/lib-dict/dict-sql-settings.c
--- a/src/lib-dict/dict-sql-settings.c Sat Oct 13 00:40:41 2012 +0300
+++ b/src/lib-dict/dict-sql-settings.c Sat Oct 13 01:03:13 2012 +0300
@@ -213,6 +213,7 @@
struct dict_sql_settings *dict_sql_settings_read(pool_t pool, const char *path)
{
struct setting_parser_ctx ctx;
+ const char *error;
memset(&ctx, 0, sizeof(ctx));
ctx.pool = pool;
@@ -220,8 +221,10 @@
t_array_init(&ctx.cur_fields, 16);
p_array_init(&ctx.set->maps, pool, 8);
- if (!settings_read(path, NULL, parse_setting, parse_section, &ctx))
+ if (!settings_read(path, NULL, parse_setting, parse_section, &ctx, &error)) {
+ i_error("Error in configuration file %s: %s", path, error);
return NULL;
+ }
if (ctx.set->connect == NULL) {
i_error("Error in configuration file %s: "
diff -r cea1d5504a84 -r 444a9921205a src/lib-settings/settings.c
--- a/src/lib-settings/settings.c Sat Oct 13 00:40:41 2012 +0300
+++ b/src/lib-settings/settings.c Sat Oct 13 01:03:13 2012 +0300
@@ -167,10 +167,10 @@
#define IS_WHITE(c) ((c) == ' ' || (c) == '\t')
-static bool
-settings_read_real(const char *path, const char *section,
- settings_callback_t *callback,
- settings_section_callback_t *sect_callback, void *context)
+bool settings_read_i(const char *path, const char *section,
+ settings_callback_t *callback,
+ settings_section_callback_t *sect_callback, void *context,
+ const char **error_r)
{
/* pretty horrible code, but v2.0 will have this rewritten anyway.. */
struct input_stack root, *input;
@@ -182,7 +182,8 @@
fd = open(path, O_RDONLY);
if (fd < 0) {
- i_error("Can't open configuration file %s: %m", path);
+ *error_r = t_strdup_printf(
+ "Can't open configuration file %s: %m", path);
return FALSE;
}
@@ -371,7 +372,8 @@
}
if (errormsg != NULL) {
- i_error("Error in configuration file %s line %d: %s",
+ *error_r = t_strdup_printf(
+ "Error in configuration file %s line %d: %s",
input->path, input->linenum, errormsg);
break;
}
@@ -385,16 +387,3 @@
return errormsg == NULL;
}
-
-bool settings_read_i(const char *path, const char *section,
- settings_callback_t *callback,
- settings_section_callback_t *sect_callback, void *context)
-{
- bool ret;
-
- T_BEGIN {
- ret = settings_read_real(path, section, callback,
- sect_callback, context);
- } T_END;
- return ret;
-}
diff -r cea1d5504a84 -r 444a9921205a src/lib-settings/settings.h
--- a/src/lib-settings/settings.h Sat Oct 13 00:40:41 2012 +0300
+++ b/src/lib-settings/settings.h Sat Oct 13 01:03:13 2012 +0300
@@ -42,9 +42,10 @@
bool settings_read_i(const char *path, const char *section,
settings_callback_t *callback,
- settings_section_callback_t *sect_callback, void *context)
+ settings_section_callback_t *sect_callback, void *context,
+ const char **error_r)
ATTR_NULL(2, 4, 5);
-#define settings_read(path, section, callback, sect_callback, context) \
+#define settings_read(path, section, callback, sect_callback, context, error_r) \
settings_read_i(path + \
CALLBACK_TYPECHECK(callback, const char *(*)( \
const char *, const char *, typeof(context))) + \
@@ -52,11 +53,11 @@
const char *, const char *, typeof(context), \
const char **)), \
section, (settings_callback_t *)callback, \
- (settings_section_callback_t *)sect_callback, context)
-#define settings_read_nosection(path, callback, context) \
+ (settings_section_callback_t *)sect_callback, context, error_r)
+#define settings_read_nosection(path, callback, context, error_r) \
settings_read_i(path + \
CALLBACK_TYPECHECK(callback, const char *(*)( \
const char *, const char *, typeof(context))), \
- NULL, (settings_callback_t *)callback, NULL, context)
+ NULL, (settings_callback_t *)callback, NULL, context, error_r)
#endif
More information about the dovecot-cvs
mailing list