From 6fc45dbe2cc946fdd6fd6d350b93d106ec91b4f3 Mon Sep 17 00:00:00 2001 From: "Russ Combs (rucombs)" Date: Mon, 5 Dec 2016 10:56:06 -0500 Subject: [PATCH] Merge pull request #736 in SNORT/snort3 from exec_swap to master Squashed commit of the following: commit 8d68ca38e3e0a8bf7d66b1bb7805c1cbf0329ea7 Author: Russ Combs Date: Fri Dec 2 13:40:28 2016 -0500 issue asynchronous swaps --- src/main.cc | 54 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/main.cc b/src/main.cc index 5e592b8c7..879c37051 100644 --- a/src/main.cc +++ b/src/main.cc @@ -82,6 +82,7 @@ std::mutex Swapper::mutex; static Swapper* swapper = NULL; +static bool swap_requested = false; static bool exit_requested = false; static int main_exit_code = 0; static bool paused = false; @@ -378,14 +379,6 @@ int main_rotate_stats(lua_State*) return 0; } -static void main_load(Swapper* ps) -{ - std::lock_guard lock(Swapper::mutex); - - for ( unsigned idx = 0; idx < max_pigs; ++idx ) - pigs[idx].swap(ps); -} - int main_reload_config(lua_State* L) { if ( swapper ) @@ -410,12 +403,12 @@ int main_reload_config(lua_State* L) request.respond("== reload failed\n"); return 0; } - request.respond(".. swapping configuration\n"); snort_conf = sc; proc_stats.conf_reloads++; - swapper = new Swapper(old, sc); - main_load(swapper); + swap_requested = true; + request.respond(".. swapping configuration\n"); + return 0; } @@ -449,7 +442,9 @@ int main_reload_hosts(lua_State* L) return 0; } swapper = new Swapper(old, tc); - main_load(swapper); + swap_requested = true; + request.respond(".. swapping hosts table\n"); + return 0; } @@ -737,14 +732,27 @@ static bool service_users() } return false; } - #endif -static bool check_response() +static bool issue_swap() { - if ( !swapper ) - return false; + for ( unsigned idx = 0; idx < max_pigs; ++idx ) + { + if ( !pigs[idx].attentive() ) + return false; + } + + std::lock_guard lock(Swapper::mutex); + + for ( unsigned idx = 0; idx < max_pigs; ++idx ) + pigs[idx].swap(swapper); + + swap_requested = false; + return true; +} +static bool check_swap() +{ for ( unsigned idx = 0; idx < max_pigs; ++idx ) { if ( pigs[idx].analyzer and pigs[idx].analyzer->swap_pending() ) @@ -765,8 +773,18 @@ static void service_check() return; #endif - if ( check_response() ) - return; + if ( swapper ) + { + bool done; + + if ( swap_requested ) + done = issue_swap(); + else + done = check_swap(); + + if ( done ) + return; + } if ( house_keeping() ) return; -- 2.47.2