summaryrefslogtreecommitdiffstats
path: root/src/libutil/map.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-06-21 10:58:08 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-06-22 10:57:29 +0100
commitae4642de39f13a98265560621f840baa07fa3e2f (patch)
treea90f342c5d38f7b663aab4c78da943da75b2eb58 /src/libutil/map.c
parentd289a3e2e2050f0a17728fabf363409d9fa86b39 (diff)
downloadrspamd-ae4642de39f13a98265560621f840baa07fa3e2f.tar.gz
rspamd-ae4642de39f13a98265560621f840baa07fa3e2f.zip
[Minor] Fix file maps monitoring
Diffstat (limited to 'src/libutil/map.c')
-rw-r--r--src/libutil/map.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/libutil/map.c b/src/libutil/map.c
index 838c7c428..a68f212c2 100644
--- a/src/libutil/map.c
+++ b/src/libutil/map.c
@@ -16,6 +16,7 @@
/*
* Implementation of map files handling
*/
+#include <ev.h>
#include "config.h"
#include "map.h"
#include "map_private.h"
@@ -1240,7 +1241,7 @@ rspamd_map_schedule_periodic (struct rspamd_map *map,
cbd->cbdata.cur_data = NULL;
cbd->cbdata.map = map;
cbd->map = map;
- map->scheduled_check = TRUE;
+ map->scheduled_check = cbd;
REF_INIT_RETAIN (cbd, rspamd_map_periodic_dtor);
cbd->ev.data = cbd;
@@ -1722,7 +1723,7 @@ rspamd_map_file_check_callback (struct map_periodic_cbdata *periodic)
bk = g_ptr_array_index (map->backends, periodic->cur_backend);
data = bk->data.fd;
- if (!data->need_modify) {
+ if (data->need_modify) {
periodic->need_modify = TRUE;
periodic->cur_backend = 0;
data->need_modify = FALSE;
@@ -1816,7 +1817,7 @@ rspamd_map_process_periodic (struct map_periodic_cbdata *cbd)
struct rspamd_map *map;
map = cbd->map;
- map->scheduled_check = FALSE;
+ map->scheduled_check = NULL;
if (!cbd->locked) {
if (!g_atomic_int_compare_and_exchange (cbd->map->locked, 0, 1)) {
@@ -1899,10 +1900,33 @@ rspamd_map_on_stat (struct ev_loop *loop, ev_stat *w, int revents)
{
struct rspamd_map *map = (struct rspamd_map *)w->data;
- msg_info_map ("old mtime is %t, new mtime is %t for map file %s",
- w->prev.st_mtime, w->attr.st_mtime, w->path);
+ if (w->attr.st_nlink > 0) {
- rspamd_map_schedule_periodic (map, FALSE, TRUE, FALSE);
+ if (w->attr.st_mtime > w->prev.st_mtime) {
+ msg_info_map ("old mtime is %t, new mtime is %t for map file %s",
+ w->prev.st_mtime, w->attr.st_mtime, w->path);
+
+ /* Fire need modify flag */
+ struct rspamd_map_backend *bk;
+ guint i;
+
+ PTR_ARRAY_FOREACH (map->backends, i, bk) {
+ if (bk->protocol == MAP_PROTO_FILE) {
+ bk->data.fd->need_modify = TRUE;
+ }
+ }
+
+ map->next_check = 0;
+
+ if (map->scheduled_check) {
+ ev_timer_stop (map->event_loop, &map->scheduled_check->ev);
+ MAP_RELEASE (map->scheduled_check, "rspamd_map_on_stat");
+ map->scheduled_check = NULL;
+ }
+
+ rspamd_map_schedule_periodic (map, FALSE, TRUE, FALSE);
+ }
+ }
}
/* Start watching event for all maps */