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.
pull/2871/merge
Giuseppe Longo 9 years ago committed by Victor Julien
parent 89c629a79d
commit 1567f84cd2

@ -626,7 +626,6 @@ void DetectBufferTypeFinalizeRegistration(void)
enum DetectEngineSyncState { enum DetectEngineSyncState {
IDLE, /**< ready to start a reload */ IDLE, /**< ready to start a reload */
RELOAD, /**< command main thread to do the 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 */ /* main thread sets done when it's done */
void DetectEngineReloadSetDone(void) void DetectEngineReloadSetIdle(void)
{ {
SCMutexLock(&detect_sync.m); SCMutexLock(&detect_sync.m);
detect_sync.state = DONE; detect_sync.state = IDLE;
SCMutexUnlock(&detect_sync.m); SCMutexUnlock(&detect_sync.m);
} }
/* caller loops this until it returns 1 */ /* caller loops this until it returns 1 */
int DetectEngineReloadIsDone(void) int DetectEngineReloadIsIdle(void)
{ {
int r = 0; int r = 0;
SCMutexLock(&detect_sync.m); SCMutexLock(&detect_sync.m);
if (detect_sync.state == DONE) { if (detect_sync.state == IDLE) {
r = 1; r = 1;
detect_sync.state = IDLE;
} }
SCMutexUnlock(&detect_sync.m); SCMutexUnlock(&detect_sync.m);
return r; return r;

@ -83,8 +83,8 @@ int DetectEngineMultiTenantSetup(void);
int DetectEngineReloadStart(void); int DetectEngineReloadStart(void);
int DetectEngineReloadIsStart(void); int DetectEngineReloadIsStart(void);
void DetectEngineReloadSetDone(void); void DetectEngineReloadSetIdle(void);
int DetectEngineReloadIsDone(void); int DetectEngineReloadIsIdle(void);
int DetectEngineLoadTenantBlocking(uint32_t tenant_id, const char *yaml); int DetectEngineLoadTenantBlocking(uint32_t tenant_id, const char *yaml);
int DetectEngineReloadTenantBlocking(uint32_t tenant_id, const char *yaml, int reload_cnt); int DetectEngineReloadTenantBlocking(uint32_t tenant_id, const char *yaml, int reload_cnt);

@ -2779,7 +2779,7 @@ static void SuricataMainLoop(SCInstance *suri)
if (!(DetectEngineReloadIsStart())) { if (!(DetectEngineReloadIsStart())) {
DetectEngineReloadStart(); DetectEngineReloadStart();
DetectEngineReload(suri); DetectEngineReload(suri);
DetectEngineReloadSetDone(); DetectEngineReloadSetIdle();
sigusr2_count--; sigusr2_count--;
} }
} }
@ -2788,10 +2788,10 @@ static void SuricataMainLoop(SCInstance *suri)
if (suri->sig_file != NULL) { if (suri->sig_file != NULL) {
SCLogWarning(SC_ERR_LIVE_RULE_SWAP, "Live rule reload not " SCLogWarning(SC_ERR_LIVE_RULE_SWAP, "Live rule reload not "
"possible if -s or -S option used at runtime."); "possible if -s or -S option used at runtime.");
DetectEngineReloadSetDone(); DetectEngineReloadSetIdle();
} else { } else {
DetectEngineReload(suri); DetectEngineReload(suri);
DetectEngineReloadSetDone(); DetectEngineReloadSetIdle();
} }
} }

@ -659,7 +659,7 @@ static TmEcode UnixManagerReloadRules(json_t *cmd, json_t *server_msg, void *dat
SCEnter(); SCEnter();
DetectEngineReloadStart(); DetectEngineReloadStart();
while (DetectEngineReloadIsDone() == 0) while (!DetectEngineReloadIsIdle())
usleep(100); usleep(100);
json_object_set_new(server_msg, "message", json_string("done")); json_object_set_new(server_msg, "message", json_string("done"));

Loading…
Cancel
Save