#include "util-cpu.h"
#include "util-affinity.h"
+#include "util-runmodes.h"
+
static const char *default_mode;
const char *RunModeErfFileGetDefaultMode(void)
int RunModeErfFileAutoFp(DetectEngineCtx *de_ctx)
{
SCEnter();
- char tname[12];
- char qname[12];
+ char tname[TM_THREAD_NAME_MAX];
+ char qname[TM_QUEUE_NAME_MAX];
uint16_t cpu = 0;
- char queues[2048] = "";
+ char *queues = NULL;
+ int thread;
RunModeInitialize();
+ char *file = NULL;
+ if (ConfGet("erf-file.file", &file) == 0) {
+ SCLogError(SC_ERR_RUNMODE,
+ "Failed retrieving erf-file.file from config");
+ exit(EXIT_FAILURE);
+ }
+
+ TimeModeSetOffline();
+
/* Available cpus */
uint16_t ncpus = UtilCpuGetNumProcessorsOnline();
if (thread_max < 1)
thread_max = 1;
- int thread;
- for (thread = 0; thread < thread_max; thread++) {
- if (strlen(queues) > 0)
- strlcat(queues, ",", sizeof(queues));
-
- snprintf(qname, sizeof(qname), "pickup%"PRIu16, thread+1);
- strlcat(queues, qname, sizeof(queues));
- }
- SCLogDebug("queues %s", queues);
-
- char *file = NULL;
- if (ConfGet("erf-file.file", &file) == 0) {
- SCLogError(SC_ERR_RUNMODE,
- "Failed retrieving erf-file.file from config");
+ queues = RunmodeAutoFpCreatePickupQueuesString(thread_max);
+ if (queues == NULL) {
+ SCLogError(SC_ERR_RUNMODE, "RunmodeAutoFpCreatePickupQueuesString failed");
exit(EXIT_FAILURE);
}
- TimeModeSetOffline();
-
/* create the threads */
ThreadVars *tv =
TmThreadCreatePacketHandler("ReceiveErfFile",
"packetpool", "packetpool",
queues, "flow",
"pktacqloop");
+ SCFree(queues);
+
if (tv == NULL) {
printf("ERROR: TmThreadsCreate failed\n");
exit(EXIT_FAILURE);
#include "util-cpu.h"
#include "util-affinity.h"
+#include "util-runmodes.h"
+
static const char *default_mode = NULL;
const char *RunModeFilePcapGetDefaultMode(void)
"packetpool", "packetpool",
"pktacqloop");
if (tv == NULL) {
- printf("ERROR: TmThreadsCreate failed\n");
+ SCLogError(SC_ERR_RUNMODE, "threading setup failed");
exit(EXIT_FAILURE);
}
TmModule *tm_module = TmModuleGetByName("ReceivePcapFile");
if (tm_module == NULL) {
- printf("ERROR: TmModuleGetByName failed for ReceivePcap\n");
+ SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName failed for ReceivePcap");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv, tm_module, file);
tm_module = TmModuleGetByName("DecodePcapFile");
if (tm_module == NULL) {
- printf("ERROR: TmModuleGetByName DecodePcap failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName DecodePcap failed");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv, tm_module, NULL);
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
- printf("ERROR: TmModuleGetByName StreamTcp failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName StreamTcp failed");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv, tm_module, NULL);
tm_module = TmModuleGetByName("Detect");
if (tm_module == NULL) {
- printf("ERROR: TmModuleGetByName Detect failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName Detect failed");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv, tm_module, (void *)de_ctx);
TmThreadSetCPU(tv, DETECT_CPU_SET);
if (TmThreadSpawn(tv) != TM_ECODE_OK) {
- printf("ERROR: TmThreadSpawn failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmThreadSpawn failed");
exit(EXIT_FAILURE);
}
int RunModeFilePcapAuto(DetectEngineCtx *de_ctx)
{
SCEnter();
- char tname[16];
+ char tname[TM_THREAD_NAME_MAX];
uint16_t cpu = 0;
TmModule *tm_module;
RunModeInitialize();
"detect-queue1", "simple",
"pktacqloop");
if (tv_receivepcap == NULL) {
- printf("ERROR: TmThreadsCreate failed\n");
+ SCLogError(SC_ERR_FATAL, "threading setup failed");
exit(EXIT_FAILURE);
}
tm_module = TmModuleGetByName("ReceivePcapFile");
if (tm_module == NULL) {
- printf("ERROR: TmModuleGetByName failed for ReceivePcap\n");
+ SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName failed for ReceivePcap");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_receivepcap, tm_module, file);
tm_module = TmModuleGetByName("DecodePcapFile");
if (tm_module == NULL) {
- printf("ERROR: TmModuleGetByName DecodePcap failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName DecodePcap failed");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_receivepcap, tm_module, NULL);
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
- printf("ERROR: TmModuleGetByName StreamTcp failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName StreamTcp failed");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_receivepcap, tm_module, (void *)de_ctx);
TmThreadSetCPU(tv_receivepcap, RECEIVE_CPU_SET);
if (TmThreadSpawn(tv_receivepcap) != TM_ECODE_OK) {
- printf("ERROR: TmThreadSpawn failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmThreadSpawn failed");
exit(EXIT_FAILURE);
}
char *thread_name = SCStrdup(tname);
if (unlikely(thread_name == NULL)) {
- printf("ERROR: Can not strdup thread name\n");
+ SCLogError(SC_ERR_RUNMODE, "failed to strdup thread name");
exit(EXIT_FAILURE);
}
SCLogDebug("Assigning %s affinity to cpu %u", thread_name, cpu);
"alert-queue1", "simple",
"1slot");
if (tv_detect_ncpu == NULL) {
- printf("ERROR: TmThreadsCreate failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmThreadsCreate failed");
exit(EXIT_FAILURE);
}
tm_module = TmModuleGetByName("Detect");
if (tm_module == NULL) {
- printf("ERROR: TmModuleGetByName Detect failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName Detect failed");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, (void *)de_ctx);
char *thread_group_name = SCStrdup("Detect");
if (unlikely(thread_group_name == NULL)) {
- printf("Error allocating memory\n");
+ SCLogError(SC_ERR_RUNMODE, "error allocating memory");
exit(EXIT_FAILURE);
}
tv_detect_ncpu->thread_group_name = thread_group_name;
TmThreadSetCPU(tv_detect_ncpu, DETECT_CPU_SET);
if (TmThreadSpawn(tv_detect_ncpu) != TM_ECODE_OK) {
- printf("ERROR: TmThreadSpawn failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmThreadSpawn failed");
exit(EXIT_FAILURE);
}
"packetpool", "packetpool",
"varslot");
if (tv_outputs == NULL) {
- printf("ERROR: TmThreadCreatePacketHandler for Outputs failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmThreadCreatePacketHandler for Outputs failed");
exit(EXIT_FAILURE);
}
TmThreadSetCPU(tv_outputs, OUTPUT_CPU_SET);
if (TmThreadSpawn(tv_outputs) != TM_ECODE_OK) {
- printf("ERROR: TmThreadSpawn failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmThreadSpawn failed");
exit(EXIT_FAILURE);
}
int RunModeFilePcapAutoFp(DetectEngineCtx *de_ctx)
{
SCEnter();
- char tname[12];
- char qname[12];
+ char tname[TM_THREAD_NAME_MAX];
+ char qname[TM_QUEUE_NAME_MAX];
uint16_t cpu = 0;
- char queues[2048] = "";
+ char *queues = NULL;
+ int thread;
RunModeInitialize();
+ char *file = NULL;
+ if (ConfGet("pcap-file.file", &file) == 0) {
+ SCLogError(SC_ERR_RUNMODE, "Failed retrieving pcap-file from Conf");
+ exit(EXIT_FAILURE);
+ }
+ SCLogDebug("file %s", file);
+
+ TimeModeSetOffline();
+
/* Available cpus */
uint16_t ncpus = UtilCpuGetNumProcessorsOnline();
if (thread_max < 1)
thread_max = 1;
- int thread;
- for (thread = 0; thread < thread_max; thread++) {
- if (strlen(queues) > 0)
- strlcat(queues, ",", sizeof(queues));
-
- snprintf(qname, sizeof(qname), "pickup%"PRIu16, thread+1);
- strlcat(queues, qname, sizeof(queues));
- }
- SCLogDebug("queues %s", queues);
-
- char *file = NULL;
- if (ConfGet("pcap-file.file", &file) == 0) {
- SCLogError(SC_ERR_RUNMODE, "Failed retrieving pcap-file from Conf");
+ queues = RunmodeAutoFpCreatePickupQueuesString(thread_max);
+ if (queues == NULL) {
+ SCLogError(SC_ERR_RUNMODE, "RunmodeAutoFpCreatePickupQueuesString failed");
exit(EXIT_FAILURE);
}
- SCLogDebug("file %s", file);
-
- TimeModeSetOffline();
/* create the threads */
ThreadVars *tv_receivepcap =
"packetpool", "packetpool",
queues, "flow",
"pktacqloop");
+ SCFree(queues);
+
if (tv_receivepcap == NULL) {
- printf("ERROR: TmThreadsCreate failed\n");
+ SCLogError(SC_ERR_FATAL, "threading setup failed");
exit(EXIT_FAILURE);
}
TmModule *tm_module = TmModuleGetByName("ReceivePcapFile");
if (tm_module == NULL) {
- printf("ERROR: TmModuleGetByName failed for ReceivePcap\n");
+ SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName failed for ReceivePcap");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_receivepcap, tm_module, file);
tm_module = TmModuleGetByName("DecodePcapFile");
if (tm_module == NULL) {
- printf("ERROR: TmModuleGetByName DecodePcap failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName DecodePcap failed");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_receivepcap, tm_module, NULL);
TmThreadSetCPU(tv_receivepcap, RECEIVE_CPU_SET);
if (TmThreadSpawn(tv_receivepcap) != TM_ECODE_OK) {
- printf("ERROR: TmThreadSpawn failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmThreadSpawn failed");
exit(EXIT_FAILURE);
}
char *thread_name = SCStrdup(tname);
if (unlikely(thread_name == NULL)) {
- printf("ERROR: Can not strdup thread name\n");
+ SCLogError(SC_ERR_RUNMODE, "failed to strdup thread name");
exit(EXIT_FAILURE);
}
SCLogDebug("Assigning %s affinity to cpu %u", thread_name, cpu);
"packetpool", "packetpool",
"varslot");
if (tv_detect_ncpu == NULL) {
- printf("ERROR: TmThreadsCreate failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmThreadsCreate failed");
exit(EXIT_FAILURE);
}
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
- printf("ERROR: TmModuleGetByName StreamTcp failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName StreamTcp failed");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, NULL);
tm_module = TmModuleGetByName("Detect");
if (tm_module == NULL) {
- printf("ERROR: TmModuleGetByName Detect failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName Detect failed");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, (void *)de_ctx);
char *thread_group_name = SCStrdup("Detect");
if (unlikely(thread_group_name == NULL)) {
- printf("Error allocating memory\n");
+ SCLogError(SC_ERR_RUNMODE, "error allocating memory");
exit(EXIT_FAILURE);
}
tv_detect_ncpu->thread_group_name = thread_group_name;
TmThreadSetCPU(tv_detect_ncpu, DETECT_CPU_SET);
if (TmThreadSpawn(tv_detect_ncpu) != TM_ECODE_OK) {
- printf("ERROR: TmThreadSpawn failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmThreadSpawn failed");
exit(EXIT_FAILURE);
}
int RunModeTileMpipeWorkers(DetectEngineCtx *de_ctx)
{
SCEnter();
- char tname[32];
+ char tname[TM_THREAD_NAME_MAX];
char *thread_name;
TmModule *tm_module;
int pipe;
return q;
error:
+ SCLogError(SC_ERR_THREAD_QUEUE, "too many thread queues %u, max is %u", tmq_id+1, TMQ_MAX_QUEUES);
return NULL;
}
for (i = 0; i < tmq_id; i++) {
SCMutexLock(&trans_q[tmqs[i].id].mutex_q);
if (tmqs[i].reader_cnt == 0) {
- printf("Error: Queue \"%s\" doesn't have a reader\n", tmqs[i].name);
+ SCLogError(SC_ERR_THREAD_QUEUE, "queue \"%s\" doesn't have a reader (id %d, max %u)", tmqs[i].name, i, tmq_id);
err = TRUE;
} else if (tmqs[i].writer_cnt == 0) {
- printf("Error: Queue \"%s\" doesn't have a writer\n", tmqs[i].name);
+ SCLogError(SC_ERR_THREAD_QUEUE, "queue \"%s\" doesn't have a writer (id %d, max %u)", tmqs[i].name, i, tmq_id);
err = TRUE;
}
SCMutexUnlock(&trans_q[tmqs[i].id].mutex_q);
return;
error:
+ SCLogError(SC_ERR_FATAL, "fatal error during threading setup");
exit(EXIT_FAILURE);
}
if (tmqh->OutHandlerCtxSetup != NULL) {
tv->outctx = tmqh->OutHandlerCtxSetup(outq_name);
+ if (tv->outctx == NULL)
+ goto error;
tv->outq = NULL;
} else {
tmq = TmqGetQueueByName(outq_name);
#include "tm-threads-common.h"
#include "tm-modules.h"
+#define TM_QUEUE_NAME_MAX 16
+#define TM_THREAD_NAME_MAX 16
+
typedef TmEcode (*TmSlotFunc)(ThreadVars *, Packet *, void *, PacketQueue *,
PacketQueue *);
if (queue_str == NULL || strlen(queue_str) == 0)
return NULL;
+ SCLogDebug("queue_str %s", queue_str);
+
TmqhFlowCtx *ctx = SCMalloc(sizeof(TmqhFlowCtx));
if (unlikely(ctx == NULL))
return NULL;
CASE_CODE (SC_ERR_DNS_LOG_GENERIC);
CASE_CODE (SC_WARN_OPTION_OBSOLETE);
CASE_CODE (SC_WARN_NO_UNITTESTS);
+ CASE_CODE (SC_ERR_THREAD_QUEUE);
}
return "UNKNOWN_ERROR";
SC_ERR_DNS_LOG_GENERIC,
SC_WARN_OPTION_OBSOLETE,
SC_WARN_NO_UNITTESTS,
+ SC_ERR_THREAD_QUEUE,
} SCError;
const char *SCErrorToString(SCError);
uint16_t ncpus = UtilCpuGetNumProcessorsOnline();
int nlive = LiveGetDeviceCount();
TmModule *tm_module;
- char tname[16];
+ char tname[TM_THREAD_NAME_MAX];
int thread;
if ((nlive <= 1) && (live_dev != NULL)) {
return 0;
}
+/** \brief create a queue string for autofp to pass to
+ * the flow queue handler.
+ *
+ * The string will be "pickup1,pickup2,pickup3\0"
+ */
+char *RunmodeAutoFpCreatePickupQueuesString(int n) {
+ char *queues = NULL;
+ /* 13 because pickup12345, = 12 + \0 */
+ size_t queues_size = n * 13;
+ int thread;
+ char qname[TM_QUEUE_NAME_MAX];
+
+ queues = SCMalloc(queues_size);
+ if (queues == NULL) {
+ SCLogError(SC_ERR_MEM_ALLOC, "failed to alloc queues buffer: %s", strerror(errno));
+ return NULL;
+ }
+ memset(queues, 0x00, queues_size);
+
+ for (thread = 0; thread < n; thread++) {
+ if (strlen(queues) > 0)
+ strlcat(queues, ",", queues_size);
+
+ snprintf(qname, sizeof(qname), "pickup%"PRIu16, thread+1);
+ strlcat(queues, qname, queues_size);
+ }
+
+ SCLogDebug("%d %"PRIuMAX", queues %s", n, (uintmax_t)queues_size, queues);
+ return queues;
+}
+
int RunModeSetLiveCaptureAutoFp(DetectEngineCtx *de_ctx,
ConfigIfaceParserFunc ConfigParser,
ConfigIfaceThreadsCountFunc ModThreadsCount,
char *decode_mod_name, char *thread_name,
const char *live_dev)
{
- char tname[12];
- char qname[12];
- char queues[2048] = "";
- int thread;
+ char tname[TM_THREAD_NAME_MAX];
+ char qname[TM_QUEUE_NAME_MAX];
+ char *queues = NULL;
+ int thread = 0;
/* Available cpus */
uint16_t ncpus = UtilCpuGetNumProcessorsOnline();
int nlive = LiveGetDeviceCount();
if (thread_max < 1)
thread_max = 1;
- for (thread = 0; thread < thread_max; thread++) {
- if (strlen(queues) > 0)
- strlcat(queues, ",", sizeof(queues));
-
- snprintf(qname, sizeof(qname),"pickup%"PRIu16, thread+1);
- strlcat(queues, qname, sizeof(queues));
+ queues = RunmodeAutoFpCreatePickupQueuesString(thread_max);
+ if (queues == NULL) {
+ SCLogError(SC_ERR_RUNMODE, "RunmodeAutoFpCreatePickupQueuesString failed");
+ exit(EXIT_FAILURE);
}
- SCLogDebug("queues %s", queues);
if ((nlive <= 1) && (live_dev != NULL)) {
void *aconf;
}
}
+ SCFree(queues);
return 0;
}
/* create the threads */
for (thread = 0; thread < threads_count; thread++) {
- char tname[20];
+ char tname[TM_THREAD_NAME_MAX];
char *n_thread_name = NULL;
ThreadVars *tv = NULL;
TmModule *tm_module = NULL;
char *decode_mod_name)
{
SCEnter();
- char tname[16];
+ char tname[TM_THREAD_NAME_MAX];
TmModule *tm_module ;
char *cur_queue = NULL;
/* create the threads */
cur_queue = LiveGetDeviceName(i);
if (cur_queue == NULL) {
- printf("ERROR: Invalid queue number\n");
+ SCLogError(SC_ERR_RUNMODE, "invalid queue number");
exit(EXIT_FAILURE);
}
memset(tname, 0, sizeof(tname));
char *thread_name = SCStrdup(tname);
if (unlikely(thread_name == NULL)) {
- printf("ERROR: Can't create thread name failed\n");
+ SCLogError(SC_ERR_RUNMODE, "failed to create thread name");
exit(EXIT_FAILURE);
}
ThreadVars *tv_receivenfq =
"pickup-queue", "simple",
"1slot_noinout");
if (tv_receivenfq == NULL) {
- printf("ERROR: TmThreadsCreate failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmThreadsCreate failed");
exit(EXIT_FAILURE);
}
tm_module = TmModuleGetByName(recv_mod_name);
if (tm_module == NULL) {
- printf("ERROR: TmModuleGetByName failed for %s\n", recv_mod_name);
+ SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName failed for %s", recv_mod_name);
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_receivenfq, tm_module, (void *) ConfigParser(i));
TmThreadSetCPU(tv_receivenfq, RECEIVE_CPU_SET);
if (TmThreadSpawn(tv_receivenfq) != TM_ECODE_OK) {
- printf("ERROR: TmThreadSpawn failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmThreadSpawn failed");
exit(EXIT_FAILURE);
}
}
"decode-queue", "simple",
"varslot");
if (tv_decode == NULL) {
- printf("ERROR: TmThreadsCreate failed for Decode1\n");
+ SCLogError(SC_ERR_RUNMODE, "TmThreadsCreate failed for Decode1");
exit(EXIT_FAILURE);
}
tm_module = TmModuleGetByName(decode_mod_name);
if (tm_module == NULL) {
- printf("ERROR: TmModuleGetByName %s failed\n", decode_mod_name);
+ SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName %s failed", decode_mod_name);
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_decode,tm_module,NULL);
tm_module = TmModuleGetByName("StreamTcp");
if (tm_module == NULL) {
- printf("ERROR: TmModuleGetByName StreamTcp failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName StreamTcp failed");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_decode, tm_module, NULL);
TmThreadSetCPU(tv_decode, DECODE_CPU_SET);
if (TmThreadSpawn(tv_decode) != TM_ECODE_OK) {
- printf("ERROR: TmThreadSpawn failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmThreadSpawn failed");
exit(EXIT_FAILURE);
}
char *thread_name = SCStrdup(tname);
if (unlikely(thread_name == NULL)) {
- printf("ERROR: thead name creation failed\n");
+ SCLogError(SC_ERR_RUNMODE, "thread name creation failed");
exit(EXIT_FAILURE);
}
SCLogDebug("Assigning %s affinity", thread_name);
"verdict-queue", "simple",
"1slot");
if (tv_detect_ncpu == NULL) {
- printf("ERROR: TmThreadsCreate failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmThreadsCreate failed");
exit(EXIT_FAILURE);
}
tm_module = TmModuleGetByName("Detect");
if (tm_module == NULL) {
- printf("ERROR: TmModuleGetByName Detect failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName Detect failed");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppendDelayed(tv_detect_ncpu, tm_module,
char *thread_group_name = SCStrdup("Detect");
if (unlikely(thread_group_name == NULL)) {
- printf("Error allocating memory\n");
+ SCLogError(SC_ERR_RUNMODE, "error allocating memory");
exit(EXIT_FAILURE);
}
tv_detect_ncpu->thread_group_name = thread_group_name;
if (TmThreadSpawn(tv_detect_ncpu) != TM_ECODE_OK) {
- printf("ERROR: TmThreadSpawn failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmThreadSpawn failed");
exit(EXIT_FAILURE);
}
}
char *thread_name = SCStrdup(tname);
if (unlikely(thread_name == NULL)) {
- printf("ERROR: thead name creation failed\n");
+ SCLogError(SC_ERR_RUNMODE, "thread name creation failed");
exit(EXIT_FAILURE);
}
ThreadVars *tv_verdict =
"alert-queue", "simple",
"varslot");
if (tv_verdict == NULL) {
- printf("ERROR: TmThreadsCreate failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmThreadsCreate failed");
exit(EXIT_FAILURE);
}
tm_module = TmModuleGetByName(verdict_mod_name);
if (tm_module == NULL) {
- printf("ERROR: TmModuleGetByName %s failed\n", verdict_mod_name);
+ SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName %s failed", verdict_mod_name);
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_verdict, tm_module, (void *)ConfigParser(i));
tm_module = TmModuleGetByName("RespondReject");
if (tm_module == NULL) {
- printf("ERROR: TmModuleGetByName for RespondReject failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName for RespondReject failed");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_verdict, tm_module, NULL);
TmThreadSetCPU(tv_verdict, VERDICT_CPU_SET);
if (TmThreadSpawn(tv_verdict) != TM_ECODE_OK) {
- printf("ERROR: TmThreadSpawn failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmThreadSpawn failed");
exit(EXIT_FAILURE);
}
};
"varslot");
if (tv_outputs == NULL) {
- printf("ERROR: TmThreadCreatePacketHandler for Outputs failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmThreadCreatePacketHandler for Outputs failed");
exit(EXIT_FAILURE);
}
SetupOutputs(tv_outputs);
if (TmThreadSpawn(tv_outputs) != TM_ECODE_OK) {
- printf("ERROR: TmThreadSpawn failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmThreadSpawn failed");
exit(EXIT_FAILURE);
}
char *decode_mod_name)
{
SCEnter();
- char tname[16];
- char qname[16];
+ char tname[TM_THREAD_NAME_MAX];
+ char qname[TM_QUEUE_NAME_MAX];
TmModule *tm_module ;
char *cur_queue = NULL;
- char queues[2048] = "";
+ char *queues = NULL;
int thread;
/* Available cpus */
if (thread_max < 1)
thread_max = 1;
- for (thread = 0; thread < thread_max; thread++) {
- if (strlen(queues) > 0)
- strlcat(queues, ",", sizeof(queues));
-
- snprintf(qname, sizeof(qname),"pickup%"PRIu16, thread+1);
- strlcat(queues, qname, sizeof(queues));
+ queues = RunmodeAutoFpCreatePickupQueuesString(thread_max);
+ if (queues == NULL) {
+ SCLogError(SC_ERR_RUNMODE, "RunmodeAutoFpCreatePickupQueuesString failed");
+ exit(EXIT_FAILURE);
}
- SCLogDebug("queues %s", queues);
for (int i = 0; i < nqueue; i++) {
/* create the threads */
cur_queue = LiveGetDeviceName(i);
if (cur_queue == NULL) {
- printf("ERROR: Invalid queue number\n");
+ SCLogError(SC_ERR_RUNMODE, "invalid queue number");
exit(EXIT_FAILURE);
}
memset(tname, 0, sizeof(tname));
char *thread_name = SCStrdup(tname);
if (unlikely(thread_name == NULL)) {
- printf("ERROR: thead name creation failed\n");
+ SCLogError(SC_ERR_RUNMODE, "thread name creation failed");
exit(EXIT_FAILURE);
}
ThreadVars *tv_receive =
"packetpool", "packetpool",
"varslot");
if (tv_verdict == NULL) {
- printf("ERROR: TmThreadsCreate failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmThreadsCreate failed");
exit(EXIT_FAILURE);
}
tm_module = TmModuleGetByName(verdict_mod_name);
if (tm_module == NULL) {
- printf("ERROR: TmModuleGetByName %s failed\n", verdict_mod_name);
+ SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName %s failed", verdict_mod_name);
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_verdict, tm_module, (void *)ConfigParser(i));
tm_module = TmModuleGetByName("RespondReject");
if (tm_module == NULL) {
- printf("ERROR: TmModuleGetByName for RespondReject failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName for RespondReject failed");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv_verdict, tm_module, NULL);
TmThreadSetCPU(tv_verdict, VERDICT_CPU_SET);
if (TmThreadSpawn(tv_verdict) != TM_ECODE_OK) {
- printf("ERROR: TmThreadSpawn failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmThreadSpawn failed");
exit(EXIT_FAILURE);
}
- };
+ }
+
+ SCFree(queues);
return 0;
}
char *verdict_mod_name,
char *decode_mod_name)
{
- char tname[16];
+ char tname[TM_THREAD_NAME_MAX];
ThreadVars *tv = NULL;
TmModule *tm_module = NULL;
char *cur_queue = NULL;
/* create the threads */
cur_queue = LiveGetDeviceName(i);
if (cur_queue == NULL) {
- printf("ERROR: Invalid queue number\n");
+ SCLogError(SC_ERR_RUNMODE, "invalid queue number");
exit(EXIT_FAILURE);
}
memset(tname, 0, sizeof(tname));
tm_module = TmModuleGetByName("RespondReject");
if (tm_module == NULL) {
- printf("ERROR: TmModuleGetByName for RespondReject failed\n");
+ SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName for RespondReject failed");
exit(EXIT_FAILURE);
}
TmSlotSetFuncAppend(tv, tm_module, NULL);
char *recv_mod_name,
char *verdict_mod_name,
char *decode_mod_name);
+
+char *RunmodeAutoFpCreatePickupQueuesString(int n);
+
#endif /* __UTIL_RUNMODES_H__ */