util-magic.c util-magic.h \
util-misc.c util-misc.h \
util-atomic.c util-atomic.h \
+util-signal.c util-signal.h \
util-print.c util-print.h \
util-fmemopen.c util-fmemopen.h \
util-cpu.c util-cpu.h \
#include "util-unittest.h"
#include "util-debug.h"
#include "util-privs.h"
+#include "util-signal.h"
/** \todo Get the default log directory from some global resource. */
#define SC_PERF_DEFAULT_LOG_FILENAME "stats.log"
static void *SCPerfMgmtThread(void *arg)
{
/* block usr2. usr2 to be handled by the main thread only */
- sigset_t x;
- sigemptyset(&x);
- sigaddset(&x, SIGUSR2);
- sigprocmask(SIG_BLOCK, &x, NULL);
+ UtilSignalBlock(SIGUSR2);
ThreadVars *tv_local = (ThreadVars *)arg;
uint8_t run = 1;
static void *SCPerfWakeupThread(void *arg)
{
/* block usr2. usr2 to be handled by the main thread only */
- sigset_t x;
- sigemptyset(&x);
- sigaddset(&x, SIGUSR2);
- sigprocmask(SIG_BLOCK, &x, NULL);
+ UtilSignalBlock(SIGUSR2);
ThreadVars *tv_local = (ThreadVars *)arg;
uint8_t run = 1;
#include "detect-uricontent.h"
#include "detect-engine-threshold.h"
-//#include "util-mpm.h"
#include "util-classification-config.h"
#include "util-reference-config.h"
#include "util-threshold-config.h"
#include "util-unittest.h"
#include "util-action.h"
#include "util-magic.h"
+#include "util-signal.h"
#include "util-var-name.h"
ThreadVars *tv_local = (ThreadVars *)arg;
/* block usr2. usr2 to be handled by the main thread only */
- sigset_t x;
- sigemptyset(&x);
- sigaddset(&x, SIGUSR2);
- sigprocmask(SIG_BLOCK, &x, NULL);
+ UtilSignalBlock(SIGUSR2);
ConfDeInit();
ConfInit();
exit(EXIT_FAILURE);
}
- //if (MagicInit() != 0)
- // exit(EXIT_FAILURE);
-
uint8_t local_need_htp_request_body = need_htp_request_body;
uint8_t local_need_htp_request_multipart_hdr = need_htp_request_multipart_hdr;
uint8_t local_need_htp_request_file = need_htp_request_file;
"can't be enabled at runtime. You will have to restart "
"engine to load the new ruleset =====");
DetectEngineCtxFree(de_ctx);
- SignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2);
+ UtilSignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2);
TmThreadsSetFlag(tv_local, THV_CLOSED);
SCLogInfo("===== Live rule swap premature exit, since "
"suricta_ctl_flags != 0 =====");
- SignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2EngineShutdown);
+ UtilSignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2EngineShutdown);
pthread_exit(NULL);
}
"swapping det_ctxs, since "
"suricta_ctl_flags != 0 =====");
- SignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2EngineShutdown);
+ UtilSignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2EngineShutdown);
pthread_exit(NULL);
}
SCLogInfo("===== Live rule swap done, but premature exit at "
"de-init phase, since suricta_ctl_flags != 0 =====");
- SignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2EngineShutdown);
+ UtilSignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2EngineShutdown);
pthread_exit(NULL);
}
SCLogInfo("===== Live rule swap done, but premature exit at "
"de-init phase, since suricta_ctl_flags != 0 =====");
- SignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2EngineShutdown);
+ UtilSignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2EngineShutdown);
pthread_exit(NULL);
}
}
DetectEngineCtxFree(old_de_ctx);
- SignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2);
+ UtilSignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2);
TmThreadsSetFlag(tv_local, THV_CLOSED);
#include "util-debug.h"
#include "util-privs.h"
+#include "util-signal.h"
#include "threads.h"
#include "detect.h"
void *FlowManagerThread(void *td)
{
/* block usr1. usr1 to be handled by the main thread only */
- sigset_t x;
- sigemptyset(&x);
- sigaddset(&x, SIGUSR2);
- sigprocmask(SIG_BLOCK, &x, NULL);
+ UtilSignalBlock(SIGUSR2);
ThreadVars *th_v = (ThreadVars *)td;
struct timeval ts;
#include "util-reference-config.h"
#include "util-profiling.h"
#include "util-magic.h"
+#include "util-signal.h"
#include "util-coredump-config.h"
return;
}
- SignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2Idle);
+ UtilSignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2Idle);
DetectEngineSpawnLiveRuleSwapMgmtThread();
#endif
#endif
-void SignalHandlerSetup(int sig, void (*handler)())
-{
-#if defined (OS_WIN32)
- signal(sig, handler);
-#else
- struct sigaction action;
- memset(&action, 0x00, sizeof(struct sigaction));
-
- action.sa_handler = handler;
- sigemptyset(&(action.sa_mask));
- sigaddset(&(action.sa_mask),sig);
- action.sa_flags = 0;
- sigaction(sig, &action, 0);
-#endif /* OS_WIN32 */
-}
-
void GlobalInits()
{
memset(trans_q, 0, sizeof(trans_q));
AppLayerHtpNeedFileInspection();
- SignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2Idle);
+ UtilSignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2Idle);
#ifdef UNITTESTS
#endif
/* registering signals we use */
- SignalHandlerSetup(SIGINT, SignalHandlerSigint);
- SignalHandlerSetup(SIGTERM, SignalHandlerSigterm);
- SignalHandlerSetup(SIGPIPE, SIG_IGN);
- SignalHandlerSetup(SIGSYS, SIG_IGN);
+ UtilSignalHandlerSetup(SIGINT, SignalHandlerSigint);
+ UtilSignalHandlerSetup(SIGTERM, SignalHandlerSigterm);
+ UtilSignalHandlerSetup(SIGPIPE, SIG_IGN);
+ UtilSignalHandlerSetup(SIGSYS, SIG_IGN);
#ifndef OS_WIN32
/* SIGHUP is not implemnetd on WIN32 */
- //SignalHandlerSetup(SIGHUP, SignalHandlerSighup);
+ //UtilSignalHandlerSetup(SIGHUP, SignalHandlerSighup);
/* Get the suricata user ID to given user ID */
if (do_setuid == TRUE) {
/* registering singal handlers we use. We register usr2 here, so that one
* can't call it during the first sig load phase */
- SignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2);
+ UtilSignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2);
#ifdef PROFILING
SCProfilingInitRuleCounters(de_ctx);
usleep(10* 1000);
}
- SignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2EngineShutdown);
+ UtilSignalHandlerSetup(SIGUSR2, SignalHandlerSigusr2EngineShutdown);
/* Update the engine stage/status flag */
SC_ATOMIC_CAS(&engine_stage, SURICATA_RUNTIME, SURICATA_DEINIT);
void EngineKill(void);
/* live rule swap required this to be made static */
-void SignalHandlerSetup(int, void (*handler)());
void SignalHandlerSigusr2(int);
void SignalHandlerSigusr2EngineShutdown(int);
#include "util-cpu.h"
#include "util-optimize.h"
#include "util-profiling.h"
+#include "util-signal.h"
#ifdef PROFILE_LOCKING
__thread uint64_t mutex_lock_contention;
void *TmThreadsSlot1NoIn(void *td)
{
/* block usr2. usr2 to be handled by the main thread only */
- sigset_t x;
- sigemptyset(&x);
- sigaddset(&x, SIGUSR2);
- sigprocmask(SIG_BLOCK, &x, NULL);
+ UtilSignalBlock(SIGUSR2);
ThreadVars *tv = (ThreadVars *)td;
TmSlot *s = (TmSlot *)tv->tm_slots;
void *TmThreadsSlot1NoOut(void *td)
{
/* block usr2. usr2 to be handled by the main thread only */
- sigset_t x;
- sigemptyset(&x);
- sigaddset(&x, SIGUSR2);
- sigprocmask(SIG_BLOCK, &x, NULL);
+ UtilSignalBlock(SIGUSR2);
ThreadVars *tv = (ThreadVars *)td;
TmSlot *s = (TmSlot *)tv->tm_slots;
void *TmThreadsSlot1NoInOut(void *td)
{
/* block usr2. usr2 to be handled by the main thread only */
- sigset_t x;
- sigemptyset(&x);
- sigaddset(&x, SIGUSR2);
- sigprocmask(SIG_BLOCK, &x, NULL);
+ UtilSignalBlock(SIGUSR2);
ThreadVars *tv = (ThreadVars *)td;
TmSlot *s = (TmSlot *)tv->tm_slots;
void *TmThreadsSlot1(void *td)
{
/* block usr2. usr2 to be handled by the main thread only */
- sigset_t x;
- sigemptyset(&x);
- sigaddset(&x, SIGUSR2);
- sigprocmask(SIG_BLOCK, &x, NULL);
+ UtilSignalBlock(SIGUSR2);
ThreadVars *tv = (ThreadVars *)td;
TmSlot *s = (TmSlot *)tv->tm_slots;
void *TmThreadsSlotPktAcqLoop(void *td) {
/* block usr2. usr2 to be handled by the main thread only */
- sigset_t x;
- sigemptyset(&x);
- sigaddset(&x, SIGUSR2);
- sigprocmask(SIG_BLOCK, &x, NULL);
+ UtilSignalBlock(SIGUSR2);
ThreadVars *tv = (ThreadVars *)td;
TmSlot *s = tv->tm_slots;
void *TmThreadsSlotVar(void *td)
{
/* block usr2. usr2 to be handled by the main thread only */
- sigset_t x;
- sigemptyset(&x);
- sigaddset(&x, SIGUSR2);
- sigprocmask(SIG_BLOCK, &x, NULL);
+ UtilSignalBlock(SIGUSR2);
ThreadVars *tv = (ThreadVars *)td;
TmSlot *s = (TmSlot *)tv->tm_slots;
#include "util-debug.h"
#include "util-unittest.h"
+/* size string parsing API */
+
static int ParseSizeString(const char *size, double *res)
{
#define PARSE_REGEX "^\\s*(\\d+(?:.\\d+)?)\\s*([a-zA-Z]{2})?\\s*$"
#ifndef __UTIL_MISC_H__
#define __UTIL_MISC_H__
+/* size string parsing API */
+
int ParseSizeStringU8(const char *, uint8_t *);
int ParseSizeStringU16(const char *, uint16_t *);
int ParseSizeStringU32(const char *, uint32_t *);
--- /dev/null
+/* Copyright (C) 2007-2012 Open Information Security Foundation
+ *
+ * You can copy, redistribute or modify this Program under the terms of
+ * the GNU General Public License version 2 as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/**
+ * \file
+ *
+ * \author Anoop Saldanha <anoopsaldanha@gmail.com>
+ */
+
+#include "suricata-common.h"
+#include "suricata.h"
+#include "util-debug.h"
+
+int UtilSignalBlock(int signum)
+{
+ sigset_t x;
+ if (sigemptyset(&x) < 0)
+ return -1;
+ if (sigaddset(&x, signum) < 0)
+ return -1;
+ if (sigprocmask(SIG_BLOCK, &x, NULL) < 0)
+ return -1;
+
+ return 0;
+}
+
+void UtilSignalHandlerSetup(int sig, void (*handler)())
+{
+#if defined (OS_WIN32)
+ signal(sig, handler);
+#else
+ struct sigaction action;
+ memset(&action, 0x00, sizeof(struct sigaction));
+
+ action.sa_handler = handler;
+ sigemptyset(&(action.sa_mask));
+ sigaddset(&(action.sa_mask),sig);
+ action.sa_flags = 0;
+ sigaction(sig, &action, 0);
+#endif /* OS_WIN32 */
+
+ return;
+}
--- /dev/null
+/* Copyright (C) 2007-2012 Open Information Security Foundation
+ *
+ * You can copy, redistribute or modify this Program under the terms of
+ * the GNU General Public License version 2 as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/**
+ * \file
+ *
+ * \author Anoop Saldanha <anoopsaldanha@gmail.com>
+ */
+
+#ifndef __UTIL_STRING_H__
+#define __UTIL_STRING_H__
+
+int UtilSignalBlock(int);
+void UtilSignalHandlerSetup(int, void (*handler)());;
+
+#endif /* __UTIL_STRING_H__ */