aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2013-12-04 16:11:54 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2013-12-04 16:11:54 +0000
commitea3c69a103647377d662edb3b59486466352945c (patch)
tree8fadbfdaa38809515320d6d5e8cb4277a342133b
parent4ce9f550f52f0656ce4ae5a8cda2caaf6b553aa7 (diff)
downloadrspamd-ea3c69a103647377d662edb3b59486466352945c.tar.gz
rspamd-ea3c69a103647377d662edb3b59486466352945c.zip
Init logging just after config is parsed by ucl.
-rw-r--r--src/cfg_file.h4
-rw-r--r--src/cfg_rcl.c3
-rw-r--r--src/cfg_rcl.h9
-rw-r--r--src/cfg_utils.c12
-rw-r--r--src/main.c25
5 files changed, 34 insertions, 19 deletions
diff --git a/src/cfg_file.h b/src/cfg_file.h
index d53829675..40500539d 100644
--- a/src/cfg_file.h
+++ b/src/cfg_file.h
@@ -502,7 +502,9 @@ gboolean parse_normalizer (struct config_file *cfg, struct statfile *st, const g
/*
* Read XML configuration file
*/
-gboolean read_rspamd_config (struct config_file *cfg, const gchar *filename, const gchar *convert_to);
+gboolean read_rspamd_config (struct config_file *cfg,
+ const gchar *filename, const gchar *convert_to,
+ rspamd_rcl_section_fin_t logger_fin, gpointer logger_ud);
/*
* Register symbols of classifiers inside metrics
diff --git a/src/cfg_rcl.c b/src/cfg_rcl.c
index b27dedbdd..a33040bfe 100644
--- a/src/cfg_rcl.c
+++ b/src/cfg_rcl.c
@@ -1198,6 +1198,9 @@ rspamd_read_rcl_config (struct rspamd_rcl_section *top,
}
}
}
+ if (cur->fin) {
+ cur->fin (cfg, cur->fin_ud);
+ }
}
cfg->rcl_obj = obj;
diff --git a/src/cfg_rcl.h b/src/cfg_rcl.h
index 272272ab4..39ce2fc43 100644
--- a/src/cfg_rcl.h
+++ b/src/cfg_rcl.h
@@ -66,6 +66,13 @@ struct rspamd_rcl_struct_parser {
typedef gboolean (*rspamd_rcl_handler_t) (struct config_file *cfg, ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err);
+/**
+ * A handler type that is called at the end of section parsing
+ * @param cfg configuration
+ * @param ud user data
+ */
+typedef void (*rspamd_rcl_section_fin_t)(struct config_file *cfg, gpointer ud);
+
struct rspamd_rcl_default_handler_data {
struct rspamd_rcl_struct_parser pd;
const gchar *key;
@@ -82,6 +89,8 @@ struct rspamd_rcl_section {
UT_hash_handle hh; /** hash handle */
struct rspamd_rcl_section *subsections; /**< hash table of subsections */
struct rspamd_rcl_default_handler_data *default_parser; /**< generic parsing fields */
+ rspamd_rcl_section_fin_t fin; /** called at the end of section parsing */
+ gpointer fin_ud;
};
/**
diff --git a/src/cfg_utils.c b/src/cfg_utils.c
index d015d60a0..5bea92303 100644
--- a/src/cfg_utils.c
+++ b/src/cfg_utils.c
@@ -778,7 +778,9 @@ rspamd_ucl_add_conf_variables (struct ucl_parser *parser)
}
gboolean
-read_rspamd_config (struct config_file *cfg, const gchar *filename, const gchar *convert_to)
+read_rspamd_config (struct config_file *cfg, const gchar *filename,
+ const gchar *convert_to, rspamd_rcl_section_fin_t logger_fin,
+ gpointer logger_ud)
{
struct stat st;
gint fd;
@@ -786,7 +788,7 @@ read_rspamd_config (struct config_file *cfg, const gchar *filename, const gchar
const gchar *ext;
GMarkupParseContext *ctx;
GError *err = NULL;
- struct rspamd_rcl_section *top;
+ struct rspamd_rcl_section *top, *logger;
gboolean res, is_xml = FALSE;
struct rspamd_xml_userdata ud;
struct ucl_parser *parser;
@@ -868,6 +870,12 @@ read_rspamd_config (struct config_file *cfg, const gchar *filename, const gchar
top = rspamd_rcl_config_init ();
err = NULL;
+ HASH_FIND_STR(top, "log", logger);
+ if (logger != NULL) {
+ logger->fin = logger_fin;
+ logger->fin_ud = logger_ud;
+ }
+
if (!rspamd_read_rcl_config (top, cfg, cfg->rcl_obj, &err)) {
msg_err ("rcl parse error: %s", err->message);
return FALSE;
diff --git a/src/main.c b/src/main.c
index 5f5058539..11da41921 100644
--- a/src/main.c
+++ b/src/main.c
@@ -299,17 +299,14 @@ drop_priv (struct rspamd_main *rspamd)
}
static void
-config_logger (struct rspamd_main *rspamd, GQuark type, gboolean is_fatal)
+config_logger (struct config_file *cfg, gpointer ud)
{
- rspamd_set_logger (rspamd->cfg->log_type, type, rspamd);
- if (open_log_priv (rspamd->logger, rspamd->workers_uid, rspamd->workers_gid) == -1) {
- if (is_fatal) {
- fprintf (stderr, "Fatal error, cannot open logfile, exiting\n");
- exit (EXIT_FAILURE);
- }
- else {
- msg_err ("cannot log to file, logfile unaccessable");
- }
+ struct rspamd_main *rm = ud;
+
+ rspamd_set_logger (cfg->log_type, g_quark_try_string ("main"), rm);
+ if (open_log_priv (rm->logger, rm->workers_uid, rm->workers_gid) == -1) {
+ fprintf (stderr, "Fatal error, cannot open logfile, exiting\n");
+ exit (EXIT_FAILURE);
}
}
@@ -366,7 +363,6 @@ reread_config (struct rspamd_main *rspamd)
gchar *cfg_file;
GList *l;
struct filter *filt;
- GQuark type;
tmp_cfg = (struct config_file *)g_malloc (sizeof (struct config_file));
if (tmp_cfg) {
@@ -393,8 +389,6 @@ reread_config (struct rspamd_main *rspamd)
if (is_debug) {
rspamd->cfg->log_level = G_LOG_LEVEL_DEBUG;
}
- type = g_quark_try_string ("main");
- config_logger (rspamd, type, FALSE);
/* Pre-init of cache */
rspamd->cfg->cache = g_new0 (struct symbols_cache, 1);
rspamd->cfg->cache->static_pool = memory_pool_new (memory_pool_get_size ());
@@ -723,7 +717,8 @@ load_rspamd_config (struct config_file *cfg, gboolean init_modules)
struct filter *filt;
struct module_ctx *cur_module = NULL;
- if (! read_rspamd_config (cfg, cfg->cfg_name, convert_config)) {
+ if (! read_rspamd_config (cfg, cfg->cfg_name, convert_config,
+ config_logger, rspamd_main)) {
return FALSE;
}
@@ -1159,8 +1154,6 @@ main (gint argc, gchar **argv, gchar **env)
rlim.rlim_cur = 100 * 1024 * 1024;
setrlimit (RLIMIT_STACK, &rlim);
- config_logger (rspamd_main, type, TRUE);
-
/* Create rolling history */
rspamd_main->history = rspamd_roll_history_new (rspamd_main->server_pool);