unix-socket: implement reload-rules

Implement the reload-rules unix socket command. The unix command
thread signals the main thread to do the reload and it waits for
it to complete.
pull/1389/head
Victor Julien 10 years ago
parent 71d01f06b9
commit 7c9e015748

@ -446,6 +446,69 @@ void DetectEngineRegisterAppInspectionEngine(uint8_t ipproto,
return;
}
/* code to control the main thread to do a reload */
enum DetectEngineSyncState {
IDLE, /**< ready to start a reload */
RELOAD, /**< command main thread to do the reload */
DONE, /**< main thread telling us reload is done */
};
typedef struct DetectEngineSyncer_ {
SCMutex m;
enum DetectEngineSyncState state;
} DetectEngineSyncer;
static DetectEngineSyncer detect_sync = { SCMUTEX_INITIALIZER, IDLE };
/* tell main to start reloading */
int DetectEngineReloadStart(void)
{
int r = 0;
SCMutexLock(&detect_sync.m);
if (detect_sync.state == IDLE) {
detect_sync.state = RELOAD;
} else {
r = -1;
}
SCMutexUnlock(&detect_sync.m);
return r;
}
/* main thread checks this to see if it should start */
int DetectEngineReloadIsStart(void)
{
int r = 0;
SCMutexLock(&detect_sync.m);
if (detect_sync.state == RELOAD) {
r = 1;
}
SCMutexUnlock(&detect_sync.m);
return r;
}
/* main thread sets done when it's done */
void DetectEngineReloadSetDone(void)
{
SCMutexLock(&detect_sync.m);
detect_sync.state = DONE;
SCMutexUnlock(&detect_sync.m);
}
/* caller loops this until it returns 1 */
int DetectEngineReloadIsDone(void)
{
int r = 0;
SCMutexLock(&detect_sync.m);
if (detect_sync.state == DONE) {
r = 1;
detect_sync.state = IDLE;
}
SCMutexUnlock(&detect_sync.m);
return r;
}
static int DetectEngineReloadThreads(DetectEngineCtx *new_de_ctx)
{
SCEnter();

@ -78,6 +78,12 @@ void DetectEngineDeReference(DetectEngineCtx **de_ctx);
int DetectEngineReload(const char *filename);
int DetectEngineEnabled(void);
int DetectEngineReloadStart(void);
int DetectEngineReloadIsStart(void);
void DetectEngineReloadSetDone(void);
int DetectEngineReloadIsDone(void);
/**
* \brief Registers an app inspection engine.
*

@ -2414,9 +2414,13 @@ int main(int argc, char **argv)
OutputNotifyFileRotation();
sighup_count--;
}
if (sigusr2_count > 0) {
DetectEngineReload(conf_filename);
sigusr2_count--;
} else if (DetectEngineReloadIsStart()) {
DetectEngineReload(conf_filename);
DetectEngineReloadSetDone();
}
usleep(10* 1000);

@ -647,6 +647,18 @@ TmEcode UnixManagerCaptureModeCommand(json_t *cmd,
SCReturnInt(TM_ECODE_OK);
}
TmEcode UnixManagerReloadRules(json_t *cmd, json_t *server_msg, void *data)
{
SCEnter();
DetectEngineReloadStart();
while (DetectEngineReloadIsDone() == 0)
usleep(100);
json_object_set_new(server_msg, "message", json_string("done"));
SCReturnInt(TM_ECODE_OK);
}
TmEcode UnixManagerConfGetCommand(json_t *cmd,
json_t *server_msg, void *data)
{
@ -870,9 +882,7 @@ void *UnixManagerThread(void *td)
UnixManagerRegisterCommand("capture-mode", UnixManagerCaptureModeCommand, &command, 0);
UnixManagerRegisterCommand("conf-get", UnixManagerConfGetCommand, &command, UNIX_CMD_TAKE_ARGS);
UnixManagerRegisterCommand("dump-counters", SCPerfOutputCounterSocket, NULL, 0);
#if 0
UnixManagerRegisterCommand("reload-rules", UnixManagerReloadRules, NULL, 0);
#endif
TmThreadsSetFlag(th_v, THV_INIT_DONE);
while (1) {

Loading…
Cancel
Save