commit be7d378: [Project] Utilize ev_stat in maps
Vsevolod Stakhov
vsevolod at highsecure.ru
Sat Jun 22 12:14:17 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-06-17 11:56:53 +0100
URL: https://github.com/rspamd/rspamd/commit/be7d3784b036dddaed2a2bf9aec8f870197aab48
[Project] Utilize ev_stat in maps
---
src/libutil/map.c | 41 ++++++++++++++++++++++++++++++++---------
src/libutil/map.h | 2 +-
src/libutil/map_private.h | 2 +-
3 files changed, 34 insertions(+), 11 deletions(-)
diff --git a/src/libutil/map.c b/src/libutil/map.c
index ffb58f8c2..1b3419a17 100644
--- a/src/libutil/map.c
+++ b/src/libutil/map.c
@@ -1698,21 +1698,21 @@ rspamd_map_file_check_callback (struct map_periodic_cbdata *periodic)
struct rspamd_map_backend *bk;
map = periodic->map;
-
bk = g_ptr_array_index (map->backends, periodic->cur_backend);
data = bk->data.fd;
- if (!data->processed) {
- /* File has never been read */
+ if (!data->need_modify) {
periodic->need_modify = TRUE;
periodic->cur_backend = 0;
+ data->need_modify = FALSE;
rspamd_map_process_periodic (periodic);
return;
}
- /* Switch to the next backend */
+ map = periodic->map;
+ /* Switch to the next backend as the rest is handled by ev_stat */
periodic->cur_backend ++;
rspamd_map_process_periodic (periodic);
}
@@ -1759,9 +1759,6 @@ rspamd_map_file_read_callback (struct map_periodic_cbdata *periodic)
if (!read_map_file (map, data, bk, periodic)) {
periodic->errored = TRUE;
}
- else {
- data->processed = TRUE;
- }
/* Switch to the next backend */
periodic->cur_backend ++;
@@ -1876,21 +1873,34 @@ rspamd_map_process_periodic (struct map_periodic_cbdata *cbd)
}
}
+static void
+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);
+
+ rspamd_map_schedule_periodic (map, FALSE, TRUE, FALSE);
+}
+
/* Start watching event for all maps */
void
rspamd_map_watch (struct rspamd_config *cfg,
- struct ev_loop *ev_base,
+ struct ev_loop *event_loop,
struct rspamd_dns_resolver *resolver,
struct rspamd_worker *worker,
gboolean active_http)
{
GList *cur = cfg->maps;
struct rspamd_map *map;
+ struct rspamd_map_backend *bk;
+ guint i;
/* First of all do synced read of data */
while (cur) {
map = cur->data;
- map->event_loop = ev_base;
+ map->event_loop = event_loop;
map->r = resolver;
map->wrk = worker;
@@ -1908,6 +1918,19 @@ rspamd_map_watch (struct rspamd_config *cfg,
}
}
+ PTR_ARRAY_FOREACH (map->backends, i, bk) {
+ if (bk->protocol == MAP_PROTO_FILE) {
+ struct file_map_data *data;
+
+ data = bk->data.fd;
+
+ ev_stat_init (&data->st_ev, rspamd_map_on_stat,
+ data->filename, map->poll_timeout * cfg->map_file_watch_multiplier);
+ data->st_ev.data = map;
+ ev_stat_start (event_loop, &data->st_ev);
+ }
+ }
+
rspamd_map_schedule_periodic (map, FALSE, TRUE, FALSE);
cur = g_list_next (cur);
diff --git a/src/libutil/map.h b/src/libutil/map.h
index 365f2cb4c..9f04d4c6c 100644
--- a/src/libutil/map.h
+++ b/src/libutil/map.h
@@ -79,7 +79,7 @@ struct rspamd_map* rspamd_map_add_from_ucl (struct rspamd_config *cfg,
* Start watching of maps by adding events to libevent event loop
*/
void rspamd_map_watch (struct rspamd_config *cfg,
- struct ev_loop *ev_base,
+ struct ev_loop *event_loop,
struct rspamd_dns_resolver *resolver,
struct rspamd_worker *worker,
gboolean active_http);
diff --git a/src/libutil/map_private.h b/src/libutil/map_private.h
index 71f05aee7..db5a72704 100644
--- a/src/libutil/map_private.h
+++ b/src/libutil/map_private.h
@@ -54,7 +54,7 @@ enum fetch_proto {
*/
struct file_map_data {
gchar *filename;
- gboolean processed;
+ gboolean need_modify;
ev_stat st_ev;
};
More information about the Commits
mailing list