* Perform post load actions
*/
gboolean
-rspamd_config_post_load (struct rspamd_config *cfg, gboolean validate_cache)
+rspamd_config_post_load (struct rspamd_config *cfg,
+ enum rspamd_post_load_options opts)
{
#ifdef HAVE_CLOCK_GETTIME
struct timespec ts;
def_metric->actions[METRIC_ACTION_REJECT].score = DEFAULT_SCORE;
}
- if (cfg->tld_file == NULL) {
- /* Try to guess tld file */
- GString *fpath = g_string_new (NULL);
+ if (opts & RSPAMD_CONFIG_INIT_URL) {
+ if (cfg->tld_file == NULL) {
+ /* Try to guess tld file */
+ GString *fpath = g_string_new (NULL);
- rspamd_printf_gstring (fpath, "%s%c%s", RSPAMD_PLUGINSDIR,
- G_DIR_SEPARATOR, "effective_tld_names.dat");
+ rspamd_printf_gstring (fpath, "%s%c%s", RSPAMD_PLUGINSDIR,
+ G_DIR_SEPARATOR, "effective_tld_names.dat");
- if (access (fpath->str, R_OK) != -1) {
- msg_debug_config ("url_tld option is not specified but %s is available,"
- " therefore this file is assumed as TLD file for URL"
- " extraction", fpath->str);
- cfg->tld_file = rspamd_mempool_strdup (cfg->cfg_pool, fpath->str);
+ if (access (fpath->str, R_OK) != -1) {
+ msg_debug_config ("url_tld option is not specified but %s is available,"
+ " therefore this file is assumed as TLD file for URL"
+ " extraction", fpath->str);
+ cfg->tld_file = rspamd_mempool_strdup (cfg->cfg_pool, fpath->str);
+ }
+ else {
+ if (opts & RSPAMD_CONFIG_INIT_VALIDATE) {
+ msg_err_config ("no url_tld option has been specified");
+ ret = FALSE;
+ }
+ }
+
+ g_string_free (fpath, TRUE);
}
else {
- if (validate_cache) {
- msg_err_config ("no url_tld option has been specified");
- ret = FALSE;
+ if (access (cfg->tld_file, R_OK) == -1) {
+ if (opts & RSPAMD_CONFIG_INIT_VALIDATE) {
+ ret = FALSE;
+ msg_err_config ("cannot access tld file %s: %s", cfg->tld_file,
+ strerror (errno));
+ }
+ else {
+ msg_debug_config ("cannot access tld file %s: %s", cfg->tld_file,
+ strerror (errno));
+ cfg->tld_file = NULL;
+ }
}
}
- g_string_free (fpath, TRUE);
- }
- else {
- if (access (cfg->tld_file, R_OK) == -1) {
- if (validate_cache) {
- ret = FALSE;
- msg_err_config ("cannot access tld file %s: %s", cfg->tld_file,
- strerror (errno));
- }
- else {
- msg_debug_config ("cannot access tld file %s: %s", cfg->tld_file,
- strerror (errno));
- cfg->tld_file = NULL;
- }
- }
+ rspamd_url_init (cfg->tld_file);
}
init_dynamic_config (cfg);
- rspamd_url_init (cfg->tld_file);
-
/* Insert classifiers symbols */
rspamd_config_insert_classify_symbols (cfg);
msg_err_config ("cannot parse log format, task logging will not be available");
}
- /* Init config cache */
- rspamd_symbols_cache_init (cfg->cache);
+ if (opts & RSPAMD_CONFIG_INIT_SYMCACHE) {
+ /* Init config cache */
+ rspamd_symbols_cache_init (cfg->cache);
- /* Init re cache */
- rspamd_re_cache_init (cfg->re_cache, cfg);
+ /* Init re cache */
+ rspamd_re_cache_init (cfg->re_cache, cfg);
+ }
- /* Config other libraries */
- rspamd_config_libs (cfg->libs_ctx, cfg);
+ if (opts & RSPAMD_CONFIG_INIT_LIBS) {
+ /* Config other libraries */
+ rspamd_config_libs (cfg->libs_ctx, cfg);
+ }
/* Execute post load scripts */
LL_FOREACH (cfg->on_load, sc) {
}
/* Validate cache */
- if (validate_cache) {
+ if (opts & RSPAMD_CONFIG_INIT_VALIDATE) {
return rspamd_symbols_cache_validate (cfg->cache, cfg, FALSE) && ret;
}
static gboolean load_rspamd_config (struct rspamd_main *rspamd_main,
struct rspamd_config *cfg,
gboolean init_modules,
- gboolean validate);
+ enum rspamd_post_load_options opts);
/* Control socket */
static gint control_fd;
/* Save some variables */
tmp_cfg->cfg_name = cfg_file;
- if (!load_rspamd_config (rspamd_main, tmp_cfg, FALSE, TRUE)) {
+ if (!load_rspamd_config (rspamd_main, tmp_cfg, FALSE, RSPAMD_CONFIG_INIT_VALIDATE)) {
rspamd_set_logger (rspamd_main->cfg, g_quark_try_string (
"main"), rspamd_main);
msg_err_main ("cannot parse new config file, revert to old one");
static gboolean
load_rspamd_config (struct rspamd_main *rspamd_main,
- struct rspamd_config *cfg, gboolean init_modules, gboolean validate)
+ struct rspamd_config *cfg, gboolean init_modules,
+ enum rspamd_post_load_options opts)
{
cfg->compiled_modules = modules;
cfg->compiled_workers = workers;
}
/* Do post-load actions */
- rspamd_config_post_load (cfg, validate);
+ rspamd_config_post_load (cfg, opts);
return TRUE;
}
}
if (config_test || dump_cache) {
- if (!load_rspamd_config (rspamd_main, rspamd_main->cfg, FALSE, FALSE)) {
+ if (!load_rspamd_config (rspamd_main, rspamd_main->cfg, FALSE, 0)) {
exit (EXIT_FAILURE);
}
}
/* Load config */
- if (!load_rspamd_config (rspamd_main, rspamd_main->cfg, TRUE, TRUE)) {
+ if (!load_rspamd_config (rspamd_main, rspamd_main->cfg, TRUE,
+ RSPAMD_CONFIG_LOAD_ALL)) {
exit (EXIT_FAILURE);
}