From 1567f84cd246b5d97e99df34e5cec361ac1cf011 Mon Sep 17 00:00:00 2001 From: Giuseppe Longo Date: Wed, 4 May 2016 17:13:39 +0200 Subject: [PATCH] detect-engine: remove DONE state Remove the DONE state to fix a problem with state not being changed correctly when multiple reload were done. As DONE was not really useful, we can remove it. --- src/detect-engine.c | 10 ++++------ src/detect-engine.h | 4 ++-- src/suricata.c | 6 +++--- src/unix-manager.c | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/detect-engine.c b/src/detect-engine.c index 3bd758b0ab..87f944e77d 100644 --- a/src/detect-engine.c +++ b/src/detect-engine.c @@ -626,7 +626,6 @@ void DetectBufferTypeFinalizeRegistration(void) enum DetectEngineSyncState { IDLE, /**< ready to start a reload */ RELOAD, /**< command main thread to do the reload */ - DONE, /**< main thread telling us reload is done */ }; @@ -664,21 +663,20 @@ int DetectEngineReloadIsStart(void) } /* main thread sets done when it's done */ -void DetectEngineReloadSetDone(void) +void DetectEngineReloadSetIdle(void) { SCMutexLock(&detect_sync.m); - detect_sync.state = DONE; + detect_sync.state = IDLE; SCMutexUnlock(&detect_sync.m); } /* caller loops this until it returns 1 */ -int DetectEngineReloadIsDone(void) +int DetectEngineReloadIsIdle(void) { int r = 0; SCMutexLock(&detect_sync.m); - if (detect_sync.state == DONE) { + if (detect_sync.state == IDLE) { r = 1; - detect_sync.state = IDLE; } SCMutexUnlock(&detect_sync.m); return r; diff --git a/src/detect-engine.h b/src/detect-engine.h index 4470421014..bd738550d5 100644 --- a/src/detect-engine.h +++ b/src/detect-engine.h @@ -83,8 +83,8 @@ int DetectEngineMultiTenantSetup(void); int DetectEngineReloadStart(void); int DetectEngineReloadIsStart(void); -void DetectEngineReloadSetDone(void); -int DetectEngineReloadIsDone(void); +void DetectEngineReloadSetIdle(void); +int DetectEngineReloadIsIdle(void); int DetectEngineLoadTenantBlocking(uint32_t tenant_id, const char *yaml); int DetectEngineReloadTenantBlocking(uint32_t tenant_id, const char *yaml, int reload_cnt); diff --git a/src/suricata.c b/src/suricata.c index d3fea4bab6..d978622a2d 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -2779,7 +2779,7 @@ static void SuricataMainLoop(SCInstance *suri) if (!(DetectEngineReloadIsStart())) { DetectEngineReloadStart(); DetectEngineReload(suri); - DetectEngineReloadSetDone(); + DetectEngineReloadSetIdle(); sigusr2_count--; } } @@ -2788,10 +2788,10 @@ static void SuricataMainLoop(SCInstance *suri) if (suri->sig_file != NULL) { SCLogWarning(SC_ERR_LIVE_RULE_SWAP, "Live rule reload not " "possible if -s or -S option used at runtime."); - DetectEngineReloadSetDone(); + DetectEngineReloadSetIdle(); } else { DetectEngineReload(suri); - DetectEngineReloadSetDone(); + DetectEngineReloadSetIdle(); } } diff --git a/src/unix-manager.c b/src/unix-manager.c index b07417b4d8..865617d0a0 100644 --- a/src/unix-manager.c +++ b/src/unix-manager.c @@ -659,7 +659,7 @@ static TmEcode UnixManagerReloadRules(json_t *cmd, json_t *server_msg, void *dat SCEnter(); DetectEngineReloadStart(); - while (DetectEngineReloadIsDone() == 0) + while (!DetectEngineReloadIsIdle()) usleep(100); json_object_set_new(server_msg, "message", json_string("done"));