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();
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.
*
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)
{
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) {