aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-03-15 09:22:07 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-03-15 09:22:07 +0000
commitd8723bd78760c0b0919bbfe50636edce09e80d91 (patch)
tree95d3b1131fa6f8e815447709a048e7fd920f308b /src/libutil
parent7a2f9b8137882da7301a02971d9910b579f6eff3 (diff)
downloadrspamd-d8723bd78760c0b0919bbfe50636edce09e80d91.tar.gz
rspamd-d8723bd78760c0b0919bbfe50636edce09e80d91.zip
[Feature] Allways clear maps on exit
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/map.c39
-rw-r--r--src/libutil/map_private.h4
2 files changed, 42 insertions, 1 deletions
diff --git a/src/libutil/map.c b/src/libutil/map.c
index ac6d58997..c1fc12690 100644
--- a/src/libutil/map.c
+++ b/src/libutil/map.c
@@ -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;
diff --git a/src/libutil/map_private.h b/src/libutil/map_private.h
index 85e468e4e..4350283c7 100644
--- a/src/libutil/map_private.h
+++ b/src/libutil/map_private.h
@@ -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;
};
/**