]> source.dussan.org Git - rspamd.git/commitdiff
Init logging just after config is parsed by ucl.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 4 Dec 2013 16:11:54 +0000 (16:11 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 4 Dec 2013 16:11:54 +0000 (16:11 +0000)
src/cfg_file.h
src/cfg_rcl.c
src/cfg_rcl.h
src/cfg_utils.c
src/main.c

index d53829675306860160d15b8086f96ba1bcf666a4..40500539df981d4ecd255345972b6f2c8ff639f7 100644 (file)
@@ -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
index b27dedbdd3da9855d97db1dcca7fadc1e6b5340a..a33040bfe65ad37fdca7291844a56c881398dc50 100644 (file)
@@ -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;
index 272272ab40b75925e21295b40a64758e576ae35d..39ce2fc432647e93b904f7a1db35ae1eeda3af63 100644 (file)
@@ -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;
 };
 
 /**
index d015d60a0177d62d07bee771fb1c43833778c16c..5bea9230322eade48bbde3278c98850d9618b6bf 100644 (file)
@@ -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;
index 5f5058539f6d939fc2e2092295311a3c3215d688..11da41921c59829de172180a05dd0871afba02f6 100644 (file)
@@ -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);