]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Allways clear maps on exit
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 15 Mar 2016 09:22:07 +0000 (09:22 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 15 Mar 2016 09:22:07 +0000 (09:22 +0000)
src/libserver/worker_util.c
src/libutil/map.c
src/libutil/map_private.h

index 3d62e109641d09f967b6f7112118ca5b7122facd..740c4cd7afeb753e4bf361e216e8864818c5cbdc 100644 (file)
@@ -22,6 +22,8 @@
 #include "utlist.h"
 #include "ottery.h"
 #include "rspamd_control.h"
+#include "libutil/map.h"
+#include "libutil/map_private.h"
 
 #ifdef WITH_GPERF_TOOLS
 #include <gperftools/profiler.h>
@@ -295,6 +297,7 @@ rspamd_worker_stop_accept (struct rspamd_worker *worker)
        GHashTableIter it;
        struct rspamd_worker_signal_handler *sigh;
        gpointer k, v;
+       struct rspamd_map *map;
 
        /* Remove all events */
        cur = worker->accept_events;
@@ -310,6 +313,7 @@ rspamd_worker_stop_accept (struct rspamd_worker *worker)
        }
 
        g_hash_table_iter_init (&it, worker->signal_events);
+
        while (g_hash_table_iter_next (&it, &k, &v)) {
                sigh = (struct rspamd_worker_signal_handler *)v;
                g_hash_table_iter_steal (&it);
@@ -318,7 +322,17 @@ rspamd_worker_stop_accept (struct rspamd_worker *worker)
                }
                g_free (sigh);
        }
+
        g_hash_table_unref (worker->signal_events);
+
+       /* Cleanup maps */
+       for (cur = worker->srv->cfg->maps; cur != NULL; cur = g_list_next (cur)) {
+               map = cur->data;
+
+               if (map->dtor) {
+                       map->dtor (map->dtor_data);
+               }
+       }
 }
 
 void
index ac6d589970354c31aaf2bc560efcef27f64da07e..c1fc126905a84a933a1dfff7acb66b332720e3c4 100644 (file)
@@ -26,6 +26,8 @@
 #include "http_parser.h"
 
 static const gchar *hash_fill = "1";
+static void free_http_cbdata_common (struct http_callback_data *cbd);
+static void free_http_cbdata_dtor (gpointer p);
 static void free_http_cbdata (struct http_callback_data *cbd);
 /**
  * Write HTTP request
@@ -190,7 +192,7 @@ rspamd_map_check_file_sig (const char *fname,
  * Callback for destroying HTTP callback data
  */
 static void
-free_http_cbdata (struct http_callback_data *cbd)
+free_http_cbdata_common (struct http_callback_data *cbd)
 {
        char fpath[PATH_MAX];
        struct stat st;
@@ -235,6 +237,26 @@ free_http_cbdata (struct http_callback_data *cbd)
        g_slice_free1 (sizeof (struct http_callback_data), cbd);
 }
 
+static void
+free_http_cbdata (struct http_callback_data *cbd)
+{
+       cbd->map->dtor = NULL;
+       cbd->map->dtor_data = NULL;
+
+       free_http_cbdata_common (cbd);
+}
+
+static void
+free_http_cbdata_dtor (gpointer p)
+{
+       struct http_callback_data *cbd = p;
+       rspamd_mempool_t *pool;
+
+       pool = cbd->map->pool;
+       msg_warn_pool ("connection with http server is terminated: worker is stopping");
+       free_http_cbdata_common (cbd);
+}
+
 /*
  * HTTP callbacks
  */
@@ -681,7 +703,10 @@ http_callback (gint fd, short what, void *ud)
                                data->host, RDNS_REQUEST_AAAA)) {
                        REF_RETAIN (cbd);
                }
+
                jitter_timeout_event (map, FALSE, FALSE, FALSE);
+               map->dtor = free_http_cbdata_dtor;
+               map->dtor_data = cbd;
        }
        else {
                msg_warn_pool ("cannot load map: DNS resolver is not initialized");
@@ -732,8 +757,20 @@ rspamd_map_watch (struct rspamd_config *cfg,
 void
 rspamd_map_remove_all (struct rspamd_config *cfg)
 {
+       struct rspamd_map *map;
+       GList *cur;
+
+       for (cur = cfg->maps; cur != NULL; cur = g_list_next (cur)) {
+               map = cur->data;
+
+               if (map->dtor) {
+                       map->dtor (map->dtor_data);
+               }
+       }
+
        g_list_free (cfg->maps);
        cfg->maps = NULL;
+
        if (cfg->map_pool != NULL) {
                rspamd_mempool_delete (cfg->map_pool);
                cfg->map_pool = NULL;
index 85e468e4e2a1dc44b05591d3a9c76ff76b43e5cc..4350283c7f2cc827ff5b397df35afddfc4e1479c 100644 (file)
@@ -22,6 +22,8 @@
 #include "unix-std.h"
 #include "ref.h"
 
+typedef void (*rspamd_map_dtor) (gpointer p);
+
 enum fetch_proto {
        MAP_PROTO_FILE,
        MAP_PROTO_HTTP,
@@ -46,6 +48,8 @@ struct rspamd_map {
        guint32 checksum;
        /* Shared lock for temporary disabling of map reading (e.g. when this map is written by UI) */
        gint *locked;
+       rspamd_map_dtor dtor;
+       gpointer dtor_data;
 };
 
 /**