code cleanup for live swap

remotes/origin/master
Anoop Saldanha 13 years ago committed by Victor Julien
parent 452114a859
commit 0c24bbab0c

@ -231,7 +231,7 @@ static void *DetectEngineLiveRuleSwap(void *arg)
for (i = 0; i < no_of_detect_tvs; i++) { for (i = 0; i < no_of_detect_tvs; i++) {
int break_out = 0; int break_out = 0;
while (new_det_ctx[i]->so_far_used_by_detect != 1) { while (SC_ATOMIC_GET(new_det_ctx[i]->so_far_used_by_detect) != 1) {
if (suricata_ctl_flags != 0) { if (suricata_ctl_flags != 0) {
break_out = 1; break_out = 1;
break; break;
@ -244,6 +244,11 @@ static void *DetectEngineLiveRuleSwap(void *arg)
SCLogDebug("new_det_ctx - %p used by detect engine", new_det_ctx[i]); SCLogDebug("new_det_ctx - %p used by detect engine", new_det_ctx[i]);
} }
/* this is to make sure that if someone initiated shutdown during a live
* rule swap, the live rule swap won't clean up the old det_ctx and
* de_ctx, till all detect threads have stopped working and sitting
* silently after setting RUNNING_DONE flag and while waiting for
* THV_DEINIT flag */
if (i != no_of_detect_tvs) { if (i != no_of_detect_tvs) {
ThreadVars *tv = tv_root[TVT_PPT]; ThreadVars *tv = tv_root[TVT_PPT];
while (tv) { while (tv) {
@ -742,6 +747,8 @@ TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data) {
return TM_ECODE_FAILED; return TM_ECODE_FAILED;
} }
SC_ATOMIC_INIT(det_ctx->so_far_used_by_detect);
*data = (void *)det_ctx; *data = (void *)det_ctx;
return TM_ECODE_OK; return TM_ECODE_OK;
@ -820,6 +827,8 @@ static TmEcode DetectEngineThreadCtxInitForLiveRuleSwap(ThreadVars *tv, void *in
return TM_ECODE_FAILED; return TM_ECODE_FAILED;
} }
SC_ATOMIC_INIT(det_ctx->so_far_used_by_detect);
*data = (void *)det_ctx; *data = (void *)det_ctx;
return TM_ECODE_OK; return TM_ECODE_OK;

@ -1938,8 +1938,8 @@ TmEcode Detect(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, PacketQue
goto error; goto error;
} }
if (det_ctx->so_far_used_by_detect == 0) { if (SC_ATOMIC_GET(det_ctx->so_far_used_by_detect) == 0) {
det_ctx->so_far_used_by_detect = 1; SC_ATOMIC_SET(det_ctx->so_far_used_by_detect, 1);
SCLogDebug("Detect Engine using new det_ctx - %p and de_ctx - %p", SCLogDebug("Detect Engine using new det_ctx - %p and de_ctx - %p",
det_ctx, de_ctx); det_ctx, de_ctx);
} }

@ -736,7 +736,7 @@ typedef struct DetectionEngineThreadCtx_ {
/** ID of the transaction currently being inspected. */ /** ID of the transaction currently being inspected. */
uint16_t tx_id; uint16_t tx_id;
uint16_t so_far_used_by_detect; SC_ATOMIC_DECLARE(uint16_t, so_far_used_by_detect);
/* holds the current recursion depth on content inspection */ /* holds the current recursion depth on content inspection */
int inspection_recursion_counter; int inspection_recursion_counter;

@ -26,6 +26,8 @@
#include "util-atomic.h" #include "util-atomic.h"
#include "util-unittest.h" #include "util-unittest.h"
#ifdef UNITTESTS
static int SCAtomicTest01(void) static int SCAtomicTest01(void)
{ {
int result = 0; int result = 0;
@ -59,9 +61,13 @@ static int SCAtomicTest01(void)
return result; return result;
} }
#endif /* UNITTESTS */
void SCAtomicRegisterTests(void) void SCAtomicRegisterTests(void)
{ {
#ifdef UNITTESTS
UtRegisterTest("SCAtomicTest01", SCAtomicTest01, 1); UtRegisterTest("SCAtomicTest01", SCAtomicTest01, 1);
#endif
return; return;
} }

@ -123,8 +123,14 @@ int SCClassConfInitContextAndLocalResources(DetectEngineCtx *de_ctx)
fd = NULL; fd = NULL;
} }
regex = NULL; if (regex != NULL) {
regex_study = NULL; pcre_free(regex);
regex = NULL;
}
if (regex_study != NULL) {
//pcre_free_study(regex_study);
regex_study = NULL;
}
return -1; return -1;
} }
@ -159,8 +165,14 @@ static void SCClassConfDeInitLocalResources(DetectEngineCtx *de_ctx)
fclose(fd); fclose(fd);
default_file_path = SC_CLASS_CONF_DEF_CONF_FILEPATH; default_file_path = SC_CLASS_CONF_DEF_CONF_FILEPATH;
fd = NULL; fd = NULL;
regex = NULL; if (regex != NULL) {
regex_study = NULL; pcre_free(regex_study);
regex = NULL;
}
if (regex_study != NULL) {
//pcre_free_study(regex_study);
regex_study = NULL;
}
return; return;
} }
@ -530,7 +542,7 @@ SCClassConfClasstype *SCClassConfGetClasstype(const char *ct_name,
SCClassConfClasstype *ct_info = SCClassConfAllocClasstype(0, ct_name, NULL, SCClassConfClasstype *ct_info = SCClassConfAllocClasstype(0, ct_name, NULL,
0); 0);
if (ct_info == NULL) if (ct_info == NULL)
exit(EXIT_FAILURE); return NULL;
SCClassConfClasstype *lookup_ct_info = HashTableLookup(de_ctx->class_conf_ht, SCClassConfClasstype *lookup_ct_info = HashTableLookup(de_ctx->class_conf_ht,
ct_info, 0); ct_info, 0);

@ -124,8 +124,14 @@ static int SCRConfInitContextAndLocalResources(DetectEngineCtx *de_ctx)
fd = NULL; fd = NULL;
} }
regex = NULL; if (regex != NULL) {
regex_study = NULL; pcre_free(regex);
regex = NULL;
}
if (regex_study != NULL) {
//pcre_free_study(regex_study);
regex_study = NULL;
}
return -1; return -1;
} }
@ -156,8 +162,15 @@ static void SCRConfDeInitLocalResources(DetectEngineCtx *de_ctx)
fclose(fd); fclose(fd);
file_path = SC_RCONF_DEFAULT_FILE_PATH; file_path = SC_RCONF_DEFAULT_FILE_PATH;
fd = NULL; fd = NULL;
regex = NULL;
regex_study = NULL; if (regex != NULL) {
pcre_free(regex);
regex = NULL;
}
if (regex_study != NULL) {
//pcre_free_study(regex_study);
regex_study = NULL;
}
return; return;
} }

@ -21,11 +21,11 @@
* \author Anoop Saldanha <anoopsaldanha@gmail.com> * \author Anoop Saldanha <anoopsaldanha@gmail.com>
*/ */
#ifndef __UTIL_STRING_H__ #ifndef __UTIL_SIGNAL_H__
#define __UTIL_STRING_H__ #define __UTIL_SIGNAL_H__
int UtilSignalBlock(int); int UtilSignalBlock(int);
void UtilSignalHandlerSetup(int, void (*handler)());; void UtilSignalHandlerSetup(int, void (*handler)());;
int UtilSignalIsHandler(int sig, void (*handler)()); int UtilSignalIsHandler(int sig, void (*handler)());
#endif /* __UTIL_STRING_H__ */ #endif /* __UTIL_SIGNAL_H__ */

@ -211,17 +211,41 @@ void SCThresholdConfDeInitContext(DetectEngineCtx *de_ctx, FILE *fd)
if (fd != NULL) if (fd != NULL)
fclose(fd); fclose(fd);
regex_base = NULL; if (regex_base != NULL) {
regex_base_study = NULL; pcre_free(regex_base);
regex_base = NULL;
}
if (regex_base_study != NULL) {
//pcre_free_study(regex_base_study);
regex_base_study = NULL;
}
regex_threshold = NULL; if (regex_threshold != NULL) {
regex_threshold_study = NULL; pcre_free(regex_threshold);
regex_threshold = NULL;
}
if (regex_threshold_study != NULL) {
//pcre_free_study(regex_threshold_study);
regex_threshold_study = NULL;
}
regex_rate = NULL; if (regex_rate != NULL) {
regex_rate_study = NULL; pcre_free(regex_rate);
regex_rate = NULL;
}
if (regex_rate_study != NULL) {
//pcre_free_study(regex_rate_study);
regex_rate_study = NULL;
}
regex_suppress = NULL; if (regex_suppress != NULL) {
regex_suppress_study = NULL; pcre_free(regex_suppress);
regex_suppress = NULL;
}
if (regex_suppress_study != NULL) {
//pcre_free_study(regex_suppress_study);
regex_suppress_study = NULL;
}
return; return;
} }

Loading…
Cancel
Save