From: Eric Leblond Date: Fri, 16 Oct 2015 14:19:03 +0000 (+0200) Subject: unix-socket: add ruleset-reload-nonblocking command X-Git-Tag: suricata-4.1.0-beta1~488 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e17b9616ab4f0817139b5e3f62cf5b920d792198;p=thirdparty%2Fsuricata.git unix-socket: add ruleset-reload-nonblocking command Add a non blocking function to reload rules. It will be useful for remote system management to avoid to block them waiting the reload. And as we now have a last-reload command we can get the status of the current reload. --- diff --git a/src/unix-manager.c b/src/unix-manager.c index 865617d0a0..f5c372716a 100644 --- a/src/unix-manager.c +++ b/src/unix-manager.c @@ -654,18 +654,35 @@ static TmEcode UnixManagerCaptureModeCommand(json_t *cmd, SCReturnInt(TM_ECODE_OK); } -static TmEcode UnixManagerReloadRules(json_t *cmd, json_t *server_msg, void *data) +static TmEcode UnixManagerReloadRulesWrapper(json_t *cmd, json_t *server_msg, void *data, int do_wait) { SCEnter(); - DetectEngineReloadStart(); + int r = DetectEngineReloadStart(); - while (!DetectEngineReloadIsIdle()) - usleep(100); + if (r == 0 && do_wait) { + while (!DetectEngineReloadIsIdle()) + usleep(100); + } else { + if (r == -1) { + json_object_set_new(server_msg, "message", json_string("Reload already in progress")); + SCReturnInt(TM_ECODE_FAILED); + } + } json_object_set_new(server_msg, "message", json_string("done")); SCReturnInt(TM_ECODE_OK); } +static TmEcode UnixManagerReloadRules(json_t *cmd, json_t *server_msg, void *data) +{ + return UnixManagerReloadRulesWrapper(cmd, server_msg, data, 1); +} + +static TmEcode UnixManagerNonBlockingReloadRules(json_t *cmd, json_t *server_msg, void *data) +{ + return UnixManagerReloadRulesWrapper(cmd, server_msg, data, 0); +} + static TmEcode UnixManagerReloadTimeCommand(json_t *cmd, json_t *server_msg, void *data) { @@ -901,6 +918,7 @@ int UnixManagerInit(void) UnixManagerRegisterCommand("conf-get", UnixManagerConfGetCommand, &command, UNIX_CMD_TAKE_ARGS); UnixManagerRegisterCommand("dump-counters", StatsOutputCounterSocket, NULL, 0); UnixManagerRegisterCommand("reload-rules", UnixManagerReloadRules, NULL, 0); + UnixManagerRegisterCommand("ruleset-reload-nonblocking", UnixManagerNonBlockingReloadRules, NULL, 0); UnixManagerRegisterCommand("ruleset-reload-time", UnixManagerReloadTimeCommand, NULL, 0); UnixManagerRegisterCommand("ruleset-stats", UnixManagerRulesetStatsCommand, NULL, 0); UnixManagerRegisterCommand("register-tenant-handler", UnixSocketRegisterTenantHandler, &command, UNIX_CMD_TAKE_ARGS);