]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fix file maps monitoring
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 21 Jun 2019 09:58:08 +0000 (10:58 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 22 Jun 2019 09:57:29 +0000 (10:57 +0100)
src/libutil/map.c
src/libutil/map_private.h

index 838c7c428ef31445702f261cc350d0ed73299327..a68f212c27ef025fa4cb2aa6d4c39faa83b3f77e 100644 (file)
@@ -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 */
index 946fc476de4719ce7afd9e4618498e7545fbda55..e08c2dce3c2ef6338764f86bd362a085f71a1ac1 100644 (file)
@@ -124,6 +124,8 @@ struct rspamd_map_backend {
        ref_entry_t ref;
 };
 
+struct map_periodic_cbdata;
+
 struct rspamd_map {
        struct rspamd_dns_resolver *r;
        struct rspamd_config *cfg;
@@ -138,7 +140,7 @@ struct rspamd_map {
        gchar *description;
        gchar *name;
        guint32 id;
-       gboolean scheduled_check;
+       struct map_periodic_cbdata *scheduled_check;
        rspamd_map_tmp_dtor tmp_dtor;
        gpointer tmp_dtor_data;
        rspamd_map_traverse_function traverse_function;