diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-08-28 16:08:36 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-08-28 16:08:36 +0100 |
commit | c6427acb2bac785a4c006cf64312dd534597cdad (patch) | |
tree | f200a05023c5b7177475e768b6d0612c6c9c6dd6 /src | |
parent | 83098d8daeb7444f14df39b3b4b29e13d56fdd0b (diff) | |
download | rspamd-c6427acb2bac785a4c006cf64312dd534597cdad.tar.gz rspamd-c6427acb2bac785a4c006cf64312dd534597cdad.zip |
Extended config logger.
Diffstat (limited to 'src')
-rw-r--r-- | src/libserver/cfg_file.h | 23 | ||||
-rw-r--r-- | src/libserver/cfg_rcl.c | 36 | ||||
-rw-r--r-- | src/libserver/cfg_utils.c | 80 |
3 files changed, 57 insertions, 82 deletions
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index 49d48033e..a889987fa 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -308,12 +308,6 @@ const ucl_object_t * rspamd_config_get_module_opt (struct rspamd_config *cfg, const gchar *module_name, const gchar *opt_name); -/** - * Parse limit - * @param limit string representation of limit (eg. 1M) - * @return numeric value of limit - */ -guint64 rspamd_config_parse_limit (const gchar *limit, guint len); /** * Parse flag @@ -454,6 +448,23 @@ gboolean rspamd_config_add_metric_symbol (struct rspamd_config *cfg, gboolean rspamd_config_is_module_enabled (struct rspamd_config *cfg, const gchar *module_name); +#define msg_err_config(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \ + cfg->cfg_pool->tag.tagname, cfg->cfg_pool->tag.uid, \ + G_STRFUNC, \ + __VA_ARGS__) +#define msg_warn_config(...) rspamd_default_log_function (G_LOG_LEVEL_WARNING, \ + cfg->cfg_pool->tag.tagname, cfg->cfg_pool->tag.uid, \ + G_STRFUNC, \ + __VA_ARGS__) +#define msg_info_config(...) rspamd_default_log_function (G_LOG_LEVEL_INFO, \ + cfg->cfg_pool->tag.tagname, cfg->cfg_pool->tag.uid, \ + G_STRFUNC, \ + __VA_ARGS__) +#define msg_debug_config(...) rspamd_default_log_function (G_LOG_LEVEL_DEBUG, \ + cfg->cfg_pool->tag.tagname, cfg->cfg_pool->tag.uid, \ + G_STRFUNC, \ + __VA_ARGS__) + #endif /* ifdef CFG_FILE_H */ /* * vi:ts=4 diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index ea9dc2ab9..be0243dc2 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -183,7 +183,7 @@ rspamd_rcl_logging_handler (rspamd_mempool_t *pool, const ucl_object_t *obj, } else { /* No type specified */ - msg_warn ( + msg_warn_config ( "logging type is not specified correctly, log output to the console"); } @@ -344,7 +344,7 @@ rspamd_rcl_symbol_handler (rspamd_mempool_t *pool, const ucl_object_t *obj, } } else { - msg_warn ("redefining symbol '%s' in metric '%s'", key, metric->name); + msg_warn_config ("redefining symbol '%s' in metric '%s'", key, metric->name); } if (!rspamd_rcl_section_parse_defaults (section, pool, obj, @@ -684,7 +684,7 @@ rspamd_rcl_lua_handler (rspamd_mempool_t *pool, const ucl_object_t *obj, lua_src, lua_tostring (L, -1)); if (chdir (cur_dir) == -1) { - msg_err ("cannot chdir to %s: %s", cur_dir, + msg_err_config ("cannot chdir to %s: %s", cur_dir, strerror (errno)); } g_free (cur_dir); @@ -701,7 +701,7 @@ rspamd_rcl_lua_handler (rspamd_mempool_t *pool, const ucl_object_t *obj, lua_src, lua_tostring (L, -1)); if (chdir (cur_dir) == -1) { - msg_err ("cannot chdir to %s: %s", cur_dir, + msg_err_config ("cannot chdir to %s: %s", cur_dir, strerror (errno)); } g_free (cur_dir); @@ -714,7 +714,7 @@ rspamd_rcl_lua_handler (rspamd_mempool_t *pool, const ucl_object_t *obj, g_set_error (err, CFG_RCL_ERROR, ENOENT, "cannot chdir to %s: %s", lua_src, strerror (errno)); if (chdir (cur_dir) == -1) { - msg_err ("cannot chdir to %s: %s", cur_dir, strerror (errno)); + msg_err_config ("cannot chdir to %s: %s", cur_dir, strerror (errno)); } g_free (cur_dir); g_free (tmp1); @@ -723,7 +723,7 @@ rspamd_rcl_lua_handler (rspamd_mempool_t *pool, const ucl_object_t *obj, } if (chdir (cur_dir) == -1) { - msg_err ("cannot chdir to %s: %s", cur_dir, strerror (errno)); + msg_err_config ("cannot chdir to %s: %s", cur_dir, strerror (errno)); } g_free (cur_dir); g_free (tmp1); @@ -905,7 +905,7 @@ rspamd_rcl_statfile_handler (rspamd_mempool_t *pool, const ucl_object_t *obj, val = ucl_object_find_key (obj, "spam"); if (val == NULL) { - msg_info ( + msg_info_config ( "statfile %s has no explicit 'spam' setting, trying to guess by symbol", st->symbol); if (rspamd_strncasestr (st->symbol, "spam", @@ -924,7 +924,7 @@ rspamd_rcl_statfile_handler (rspamd_mempool_t *pool, const ucl_object_t *obj, st->symbol); return FALSE; } - msg_info ("guessed that statfile with symbol %s is %s", + msg_info_config ("guessed that statfile with symbol %s is %s", st->symbol, st->is_spam ? "spam" : "ham"); @@ -1011,7 +1011,7 @@ rspamd_rcl_classifier_handler (rspamd_mempool_t *pool, } } else { - msg_err ("fatal configuration error, cannot parse statfile definition"); + msg_err_config ("fatal configuration error, cannot parse statfile definition"); } if (tkcf == NULL) { @@ -1048,7 +1048,7 @@ rspamd_rcl_composite_handler (rspamd_mempool_t *pool, composite_name = key; if (g_hash_table_lookup (cfg->composite_symbols, composite_name) != NULL) { - msg_warn ("composite %s is redefined", composite_name); + msg_warn_config ("composite %s is redefined", composite_name); new = FALSE; } @@ -1064,11 +1064,11 @@ rspamd_rcl_composite_handler (rspamd_mempool_t *pool, if (!rspamd_parse_expression (composite_expression, 0, &composite_expr_subr, NULL, cfg->cfg_pool, err, &expr)) { if (err && *err) { - msg_err ("cannot parse composite expression for %s: %e", + msg_err_config ("cannot parse composite expression for %s: %e", composite_name, *err); } else { - msg_err ("cannot parse composite expression for %s: unknown error", + msg_err_config ("cannot parse composite expression for %s: unknown error", composite_name); } @@ -2337,7 +2337,7 @@ rspamd_rcl_register_worker_option (struct rspamd_config *cfg, HASH_FIND_STR (nparser->parsers, name, nhandler); if (nhandler != NULL) { - msg_warn ( + msg_warn_config ( "handler for parameter %s is already registered for worker type %s", name, g_quark_to_string (type)); @@ -2388,18 +2388,18 @@ rspamd_config_read (struct rspamd_config *cfg, const gchar *filename, struct ucl_parser *parser; if (stat (filename, &st) == -1) { - msg_err ("cannot stat %s: %s", filename, strerror (errno)); + msg_err_config ("cannot stat %s: %s", filename, strerror (errno)); return FALSE; } if ((fd = open (filename, O_RDONLY)) == -1) { - msg_err ("cannot open %s: %s", filename, strerror (errno)); + msg_err_config ("cannot open %s: %s", filename, strerror (errno)); return FALSE; } /* Now mmap this file to simplify reading process */ if ((data = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) { - msg_err ("cannot mmap %s: %s", filename, strerror (errno)); + msg_err_config ("cannot mmap %s: %s", filename, strerror (errno)); close (fd); return FALSE; } @@ -2409,7 +2409,7 @@ rspamd_config_read (struct rspamd_config *cfg, const gchar *filename, rspamd_ucl_add_conf_variables (parser, vars); rspamd_ucl_add_conf_macros (parser, cfg); if (!ucl_parser_add_chunk (parser, data, st.st_size)) { - msg_err ("ucl parser error: %s", ucl_parser_get_error (parser)); + msg_err_config ("ucl parser error: %s", ucl_parser_get_error (parser)); ucl_parser_free (parser); munmap (data, st.st_size); return FALSE; @@ -2431,7 +2431,7 @@ rspamd_config_read (struct rspamd_config *cfg, const gchar *filename, } if (!rspamd_rcl_parse (top, cfg, cfg->cfg_pool, cfg->rcl_obj, &err)) { - msg_err ("rcl parse error: %e", err); + msg_err_config ("rcl parse error: %e", err); g_error_free (err); return FALSE; } diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index a1139d943..161ea9501 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -120,14 +120,14 @@ rspamd_parse_bind_line (struct rspamd_config *cfg, LL_PREPEND (cf->bind_conf, cnf); } else { - msg_err ("cannot parse bind line: %s", str); + msg_err_config ("cannot parse bind line: %s", str); ret = FALSE; } } else { if (!rspamd_parse_host_port_priority_strv (tokens, &cnf->addrs, NULL, &cnf->name, DEFAULT_BIND_PORT, cfg->cfg_pool)) { - msg_err ("cannot parse bind line: %s", str); + msg_err_config ("cannot parse bind line: %s", str); ret = FALSE; } else { @@ -213,43 +213,6 @@ rspamd_config_get_module_opt (struct rspamd_config *cfg, return res; } -guint64 -rspamd_config_parse_limit (const gchar *limit, guint len) -{ - guint64 result = 0; - const gchar *err_str; - - if (!limit || *limit == '\0' || len == 0) { - return 0; - } - - errno = 0; - result = strtoull (limit, (gchar **)&err_str, 10); - - if (*err_str != '\0') { - /* Megabytes */ - if (*err_str == 'm' || *err_str == 'M') { - result *= 1048576L; - } - /* Kilobytes */ - else if (*err_str == 'k' || *err_str == 'K') { - result *= 1024; - } - /* Gigabytes */ - else if (*err_str == 'g' || *err_str == 'G') { - result *= 1073741824L; - } - else if (len > 0 && err_str - limit != (gint)len) { - msg_warn ("invalid limit value '%s' at position '%s'", - limit, - err_str); - result = 0; - } - } - - return result; -} - gchar rspamd_config_parse_flag (const gchar *str, guint len) { @@ -313,12 +276,12 @@ rspamd_config_calculate_checksum (struct rspamd_config *cfg) /* Compute checksum for config file that should be used by xml dumper */ if ((fd = open (cfg->cfg_name, O_RDONLY)) == -1) { - msg_err ( + msg_err_config ( "config file %s is no longer available, cannot calculate checksum"); return FALSE; } if (stat (cfg->cfg_name, &st) == -1) { - msg_err ("cannot stat %s: %s", cfg->cfg_name, strerror (errno)); + msg_err_config ("cannot stat %s: %s", cfg->cfg_name, strerror (errno)); close (fd); return FALSE; } @@ -326,7 +289,7 @@ rspamd_config_calculate_checksum (struct rspamd_config *cfg) /* Now mmap this file to simplify reading process */ if ((map = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) { - msg_err ("cannot mmap %s: %s", cfg->cfg_name, strerror (errno)); + msg_err_config ("cannot mmap %s: %s", cfg->cfg_name, strerror (errno)); close (fd); return FALSE; } @@ -388,13 +351,13 @@ rspamd_config_post_load (struct rspamd_config *cfg) G_DIR_SEPARATOR, "effective_tld_names.dat"); if (access (fpath->str, R_OK)) { - msg_warn ("url_tld option is not specified but %s is available," + msg_warn_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 { - msg_err ("no url_tld option has been specified, URL's detection " + msg_err_config ("no url_tld option has been specified, URL's detection " "will be awfully broken"); } @@ -843,6 +806,7 @@ rspamd_ucl_fin_cb (rspamd_mempool_t * pool, struct map_cb_data *data) guint32 checksum; ucl_object_iter_t it = NULL; const ucl_object_t *cur; + struct rspamd_config *cfg = data->map->cfg; if (prev != NULL) { if (prev->buf != NULL) { @@ -852,7 +816,7 @@ rspamd_ucl_fin_cb (rspamd_mempool_t * pool, struct map_cb_data *data) } if (cbdata == NULL) { - msg_err ("map fin error: new data is NULL"); + msg_err_config ("map fin error: new data is NULL"); return; } @@ -862,7 +826,7 @@ rspamd_ucl_fin_cb (rspamd_mempool_t * pool, struct map_cb_data *data) parser = ucl_parser_new (0); if (!ucl_parser_add_chunk (parser, cbdata->buf->str, cbdata->buf->len)) { - msg_err ("cannot parse map %s: %s", + msg_err_config ("cannot parse map %s: %s", data->map->uri, ucl_parser_get_error (parser)); ucl_parser_free (parser); @@ -881,7 +845,7 @@ rspamd_ucl_fin_cb (rspamd_mempool_t * pool, struct map_cb_data *data) } } else { - msg_info ("do not reload map %s, checksum is the same: %d", + msg_info_config ("do not reload map %s, checksum is the same: %d", data->map->uri, checksum); } @@ -922,7 +886,7 @@ rspamd_init_filters (struct rspamd_config *cfg, bool reconfig) if (reconfig) { (void)mod->module_reconfig_func (cfg); - msg_debug ("reconfig of %s", mod->name); + msg_debug_config ("reconfig of %s", mod->name); } else { (void)mod->module_config_func (cfg); @@ -930,7 +894,7 @@ rspamd_init_filters (struct rspamd_config *cfg, bool reconfig) } if (mod_ctx == NULL) { - msg_warn ("requested unknown module %s", cur->data); + msg_warn_config ("requested unknown module %s", cur->data); } cur = g_list_next (cur); @@ -942,7 +906,7 @@ rspamd_init_filters (struct rspamd_config *cfg, bool reconfig) void rspamd_init_cfg (struct rspamd_config *cfg, gboolean init_lua) { - cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "config"); + cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "cfg"); rspamd_config_defaults (cfg); if (init_lua) { @@ -974,13 +938,13 @@ rspamd_config_add_metric_symbol (struct rspamd_config *cfg, metric = g_hash_table_lookup (cfg->metrics, metric_name); if (metric == NULL) { - msg_err ("metric %s has not been found", metric_name); + msg_err_config ("metric %s has not been found", metric_name); return FALSE; } if (g_hash_table_lookup (cfg->metrics_symbols, symbol) != NULL && !rewrite_existing) { - msg_debug ("symbol %s has been already registered, do not override"); + msg_debug_config ("symbol %s has been already registered, do not override"); return FALSE; } @@ -998,7 +962,7 @@ rspamd_config_add_metric_symbol (struct rspamd_config *cfg, sym_def->description = rspamd_mempool_strdup (cfg->cfg_pool, description); } - msg_debug ("registered symbol %s with weight %.2f in metric %s and group %s", + msg_debug_config ("registered symbol %s with weight %.2f in metric %s and group %s", sym_def->name, score, metric->name, group); g_hash_table_insert (metric->symbols, sym_def->name, sym_def); @@ -1066,7 +1030,7 @@ rspamd_config_is_module_enabled (struct rspamd_config *cfg, } if (!found) { - msg_info ("internal module %s is disable in `filters` line", + msg_info_config ("internal module %s is disable in `filters` line", module_name); return FALSE; @@ -1076,11 +1040,11 @@ rspamd_config_is_module_enabled (struct rspamd_config *cfg, conf = ucl_object_find_key (cfg->rcl_obj, module_name); if (conf == NULL) { - msg_info ("%s module %s is enabled but has not been configured", + msg_info_config ("%s module %s is enabled but has not been configured", is_c ? "internal" : "lua", module_name); if (!is_c) { - msg_info ("%s disabling unconfigured lua module", module_name); + msg_info_config ("%s disabling unconfigured lua module", module_name); return FALSE; } } @@ -1089,7 +1053,7 @@ rspamd_config_is_module_enabled (struct rspamd_config *cfg, if (enabled && ucl_object_type (enabled) == UCL_BOOLEAN) { if (!ucl_object_toboolean (enabled)) { - msg_info ("%s module %s is disabled in the configuration", + msg_info_config ("%s module %s is disabled in the configuration", is_c ? "internal" : "lua", module_name); return FALSE; } @@ -1101,7 +1065,7 @@ rspamd_config_is_module_enabled (struct rspamd_config *cfg, if (gr) { if (gr->disabled) { - msg_info ("%s module %s is disabled in the configuration as " + msg_info_config ("%s module %s is disabled in the configuration as " "its group has been disabled", is_c ? "internal" : "lua", module_name); return FALSE; |