lib: remove global worker id variable

Update ThreadVars creation in lib mode to have the worker_id provided
by the user.

Ticket: #7240
pull/12891/head
Jason Ish 1 year ago committed by Victor Julien
parent 201b3a6001
commit 60860e43ac

@ -22,6 +22,8 @@
#include "source-lib.h"
#include "threadvars.h"
static int worker_id = 1;
/**
* Suricata worker thread in library mode.
* The functions should be wrapped in an API layer.
@ -31,7 +33,7 @@ static void *SimpleWorker(void *arg)
char *pcap_file = (char *)arg;
/* Create worker. */
ThreadVars *tv = SCRunModeLibCreateThreadVars();
ThreadVars *tv = SCRunModeLibCreateThreadVars(worker_id++);
if (!tv) {
pthread_exit(NULL);
}

@ -25,9 +25,6 @@
#include "runmode-lib.h"
#include "runmodes.h"
#include "tm-threads.h"
#include "util-device.h"
static int g_thread_id = 0;
/** \brief register runmodes for suricata as a library */
void RunModeIdsLibRegister(void)
@ -59,11 +56,11 @@ const char *RunModeLibGetDefaultMode(void)
return "live";
}
ThreadVars *SCRunModeLibCreateThreadVars(void)
ThreadVars *SCRunModeLibCreateThreadVars(int worker_id)
{
char tname[TM_THREAD_NAME_MAX];
TmModule *tm_module = NULL;
snprintf(tname, sizeof(tname), "%s#%02d", thread_name_workers, ++g_thread_id);
snprintf(tname, sizeof(tname), "%s#%02d", thread_name_workers, worker_id);
ThreadVars *tv = TmThreadCreatePacketHandler(
tname, "packetpool", "packetpool", "packetpool", "packetpool", "lib");
@ -142,7 +139,6 @@ void RunModeDestroyWorker(void *td)
}
tv->stream_pq = NULL;
--g_thread_id;
SCLogDebug("%s ending", tv->name);
TmThreadsSetFlag(tv, THV_CLOSED);
}

@ -45,9 +45,11 @@ const char *RunModeLibGetDefaultMode(void);
* Unlike other runmodes, this does not spawn a thread, as the threads
* are controlled by the application using Suricata as a library.
*
* \param worker_id an ID to give this ThreadVars instance
*
* \return Pointer to allocated ThreadVars or NULL on failure
*/
ThreadVars *SCRunModeLibCreateThreadVars(void);
ThreadVars *SCRunModeLibCreateThreadVars(int worker_id);
/** \brief start the "fake" worker.
*

Loading…
Cancel
Save