From 6296080e41de1a8b39e43b6c1015d8fa15224a96 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 17 Feb 2024 13:19:26 +0000 Subject: [PATCH] [Fix] Fix initial maps load --- src/libserver/maps/map.c | 12 ++++++++---- src/libserver/maps/map_private.h | 7 ++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/libserver/maps/map.c b/src/libserver/maps/map.c index 7f6a48f8c..3efd5a501 100644 --- a/src/libserver/maps/map.c +++ b/src/libserver/maps/map.c @@ -1,5 +1,5 @@ /* - * Copyright 2023 Vsevolod Stakhov + * Copyright 2024 Vsevolod Stakhov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -995,7 +995,7 @@ rspamd_map_periodic_dtor(struct map_periodic_cbdata *periodic) struct rspamd_map *map; map = periodic->map; - msg_debug_map("periodic dtor %p", periodic); + msg_debug_map("periodic dtor %p; need_modify=%d", periodic, periodic->need_modify); if (periodic->need_modify || periodic->cbdata.errored) { /* Need to notify the real data structure */ @@ -1062,6 +1062,8 @@ rspamd_map_schedule_periodic(struct rspamd_map *map, int how) return; } + map->seen = true; + if (map->non_trivial && map->next_check != 0) { timeout = map->next_check - rspamd_get_calendar_ticks(); map->next_check = 0; @@ -1107,7 +1109,7 @@ rspamd_map_schedule_periodic(struct rspamd_map *map, int how) timeout = map->poll_timeout; if (how & RSPAMD_MAP_SCHEDULE_INIT) { - if (map->active_http) { + if (map->non_trivial && map->active_http) { /* Spill maps load to get better chances to hit ssl cache */ timeout = rspamd_time_jitter(0.0, 2.0); } @@ -2189,7 +2191,7 @@ void rspamd_map_watch(struct rspamd_config *cfg, data = bk->data.fd; - if (map->user_data == NULL || *map->user_data == NULL) { + if (!map->seen || map->user_data == NULL || *map->user_data == NULL) { /* Map has not been read, init it's reading if possible */ struct stat st; @@ -2317,6 +2319,8 @@ void rspamd_map_preload(struct rspamd_config *cfg) if (map->on_load_function) { map->on_load_function(map, map->on_load_ud); } + + map->seen = true; } else { msg_info_map("preload of %s failed", map->name); diff --git a/src/libserver/maps/map_private.h b/src/libserver/maps/map_private.h index 60751c0ac..b88a18e3f 100644 --- a/src/libserver/maps/map_private.h +++ b/src/libserver/maps/map_private.h @@ -1,11 +1,11 @@ -/*- - * Copyright 2016 Vsevolod Stakhov +/* + * Copyright 2024 Vsevolod Stakhov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -166,6 +166,7 @@ struct rspamd_map { bool file_only; /* No HTTP backends found */ bool static_only; /* No need to check */ bool no_file_read; /* Do not read files */ + bool seen; /* This map has already been watched or pre-loaded */ /* Shared lock for temporary disabling of map reading (e.g. when this map is written by UI) */ gint *locked; gchar tag[MEMPOOL_UID_LEN]; -- 2.39.5