]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Reload file maps more frequently 1734/head
authorAndrew Lewis <nerf@judo.za.org>
Fri, 7 Jul 2017 10:14:28 +0000 (12:14 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Fri, 7 Jul 2017 10:14:28 +0000 (12:14 +0200)
conf/options.inc
src/libserver/cfg_file.h
src/libserver/cfg_rcl.c
src/libserver/cfg_utils.c
src/libutil/map.c

index 5cb913cc702e511f62cd6ca7196788bc96c69a33..fa974e6817f015340d2dc8f1e570b147053c719d 100644 (file)
@@ -6,6 +6,8 @@ one_shot = false;
 cache_file = "$DBDIR/symbols.cache";
 # How often maps are checked (
 map_watch_interval = 5min;
+# Multiplier for watch interval for files
+map_file_watch_multiplier = 0.1;
 dynamic_conf = "$DBDIR/rspamd_dynamic";
 history_file = "$DBDIR/rspamd.history";
 check_all_filters = false;
index 2932bdd894991eb8b08135c8c806b06b46671d46..44b8dd85a0d6aa39c28eeff07af9ef9703fed94e 100644 (file)
@@ -377,6 +377,7 @@ struct rspamd_config {
 
        GList *maps;                                    /**< maps active                                                                                */
        gdouble map_timeout;                            /**< maps watch timeout                                                                 */
+       gdouble map_file_watch_multiplier;              /**< multiplier for watch timeout when maps are files */
 
        struct symbols_cache *cache;                    /**< symbols cache object                                                               */
        gchar *cache_filename;                          /**< filename of cache file                                                             */
index ddc9ca06647e8a0a465522d13f9d5f6c9c4785d7..67f91ab9b4e67f434f79086e58a1f9f635187aaa 100644 (file)
@@ -1983,6 +1983,12 @@ rspamd_rcl_config_init (struct rspamd_config *cfg)
                        G_STRUCT_OFFSET (struct rspamd_config, map_timeout),
                        RSPAMD_CL_FLAG_TIME_FLOAT,
                        "Interval for checking maps");
+       rspamd_rcl_add_default_handler (sub,
+                       "map_file_watch_multiplier",
+                       rspamd_rcl_parse_struct_double,
+                       G_STRUCT_OFFSET (struct rspamd_config, map_file_watch_multiplier),
+                       0,
+                       "Multiplier for map watch interval when map is file");
        rspamd_rcl_add_default_handler (sub,
                        "dynamic_conf",
                        rspamd_rcl_parse_struct_string,
index dce0e0bac631fee08961d7b8ab4d0d113e740ca2..7bc8994b495dc2ec3affdfb3b1645155741d649b 100644 (file)
@@ -36,6 +36,7 @@
 #define DEFAULT_RLIMIT_NOFILE 2048
 #define DEFAULT_RLIMIT_MAXCORE 0
 #define DEFAULT_MAP_TIMEOUT 60.0 * 5
+#define DEFAULT_MAP_FILE_WATCH_MULTIPLIER 1
 #define DEFAULT_MIN_WORD 4
 #define DEFAULT_MAX_WORD 40
 #define DEFAULT_WORDS_DECAY 200
@@ -137,6 +138,7 @@ rspamd_config_new (void)
                                rspamd_str_equal);
 
        cfg->map_timeout = DEFAULT_MAP_TIMEOUT;
+       cfg->map_file_watch_multiplier = DEFAULT_MAP_FILE_WATCH_MULTIPLIER;
 
        cfg->log_level = G_LOG_LEVEL_WARNING;
        cfg->log_extended = TRUE;
index c0953c90f2303ed88afdfb1e18cd1b0a323db9cb..4402a79103e7ca4253e20d70ac7d69022c32bd26 100644 (file)
@@ -1756,7 +1756,12 @@ rspamd_map_add (struct rspamd_config *cfg,
                        map->backends);
        g_ptr_array_add (map->backends, bk);
        map->name = rspamd_mempool_strdup (cfg->cfg_pool, map_line);
-       map->poll_timeout = cfg->map_timeout;
+
+       if (bk->protocol == MAP_PROTO_FILE) {
+               map->poll_timeout = (cfg->map_timeout * cfg->map_file_watch_multiplier);
+       } else {
+               map->poll_timeout = cfg->map_timeout;
+       }
 
        if (description != NULL) {
                map->description = rspamd_mempool_strdup (cfg->cfg_pool, description);
@@ -1820,6 +1825,9 @@ rspamd_map_add_from_ucl (struct rspamd_config *cfg,
                                bk = rspamd_map_parse_backend (cfg, ucl_object_tostring (cur));
 
                                if (bk != NULL) {
+                                       if (bk->protocol == MAP_PROTO_FILE) {
+                                               map->poll_timeout = (map->poll_timeout * cfg->map_file_watch_multiplier);
+                                       }
                                        g_ptr_array_add (map->backends, bk);
 
                                        if (!map->name) {
@@ -1873,6 +1881,9 @@ rspamd_map_add_from_ucl (struct rspamd_config *cfg,
                                        bk = rspamd_map_parse_backend (cfg, ucl_object_tostring (cur));
 
                                        if (bk != NULL) {
+                                               if (bk->protocol == MAP_PROTO_FILE) {
+                                                       map->poll_timeout = (map->poll_timeout * cfg->map_file_watch_multiplier);
+                                               }
                                                g_ptr_array_add (map->backends, bk);
 
                                                if (!map->name) {
@@ -1900,6 +1911,9 @@ rspamd_map_add_from_ucl (struct rspamd_config *cfg,
                        bk = rspamd_map_parse_backend (cfg, ucl_object_tostring (elt));
 
                        if (bk != NULL) {
+                               if (bk->protocol == MAP_PROTO_FILE) {
+                                       map->poll_timeout = (map->poll_timeout * cfg->map_file_watch_multiplier);
+                               }
                                g_ptr_array_add (map->backends, bk);
 
                                if (!map->name) {