From: Jason Ish Date: Tue, 4 Mar 2014 16:34:33 +0000 (-0600) Subject: Registration for SIGHUP notification - for loggers interested X-Git-Tag: suricata-2.0.2~22 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=698a0f7f48e9163a6781aed5fa8be8a3fe65fcaa;p=thirdparty%2Fsuricata.git Registration for SIGHUP notification - for loggers interested in file rotation on SIGHUP. --- diff --git a/src/output.c b/src/output.c index eb005651d5..c29f4d9103 100644 --- a/src/output.c +++ b/src/output.c @@ -34,6 +34,18 @@ static TAILQ_HEAD(, OutputModule_) output_modules = TAILQ_HEAD_INITIALIZER(output_modules); +/** + * Registry of flags to be updated on file rotation notification. + */ +typedef struct OutputFileRolloverFlag_ { + int *flag; + + TAILQ_ENTRY(OutputFileRolloverFlag_) entries; +} OutputFileRolloverFlag; + +TAILQ_HEAD(, OutputFileRolloverFlag_) output_file_rotation_flags = + TAILQ_HEAD_INITIALIZER(output_file_rotation_flags); + /** * \brief Register an output module. * @@ -416,3 +428,23 @@ void OutputSshLoggerDisable(void) { if (ssh_loggers) ssh_loggers--; } + +void OutputRegisterFileRotationFlag(int *flag) +{ + OutputFileRolloverFlag *flag_entry = SCCalloc(1, sizeof(*flag_entry)); + if (unlikely(flag_entry == NULL)) { + SCLogError(SC_ERR_MEM_ALLOC, + "Failed to allocate memory to register file rotation flag"); + return; + } + flag_entry->flag = flag; + TAILQ_INSERT_TAIL(&output_file_rotation_flags, flag_entry, entries); +} + +void OutputNotifyFileRotation(void) +{ + OutputFileRolloverFlag *flag; + TAILQ_FOREACH(flag, &output_file_rotation_flags, entries) { + *(flag->flag) = 1; + } +} diff --git a/src/output.h b/src/output.h index e62e2b1882..75c18da7e6 100644 --- a/src/output.h +++ b/src/output.h @@ -92,4 +92,7 @@ void OutputTlsLoggerDisable(void); int OutputSshLoggerEnable(void); void OutputSshLoggerDisable(void); +void OutputRegisterFileRotationFlag(int *flag); +void OutputNotifyFileRotation(void); + #endif /* ! __OUTPUT_H__ */ diff --git a/src/suricata.c b/src/suricata.c index b1691cfc17..19be3ddaec 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -313,6 +313,14 @@ void SignalHandlerSigusr2(int sig) return; } +/** + * SIGHUP handler. Just set sighup_count. The main loop will act on + * it. + */ +static void SignalHandlerSigHup(/*@unused@*/ int sig) { + sighup_count = 1; +} + #ifdef DBG_MEM_ALLOC #ifndef _GLOBAL_MEM_ #define _GLOBAL_MEM_ @@ -1725,7 +1733,7 @@ static int InitSignalHandler(SCInstance *suri) #ifndef OS_WIN32 /* SIGHUP is not implemented on WIN32 */ - UtilSignalHandlerSetup(SIGHUP, SIG_IGN); + UtilSignalHandlerSetup(SIGHUP, SignalHandlerSigHup); /* Try to get user/group to run suricata as if command line as not decide of that */ @@ -2333,6 +2341,11 @@ int main(int argc, char **argv) TmThreadCheckThreadState(); + if (sighup_count > 0) { + OutputNotifyFileRotation(); + sighup_count--; + } + usleep(10* 1000); }