From: Victor Julien Date: Mon, 10 Jun 2024 18:34:40 +0000 (+0200) Subject: detect/lua: add thread_init X-Git-Tag: suricata-8.0.0-beta1~576 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e89ab4f88a0dbec01c2700f7ccbcedc33377e5f0;p=thirdparty%2Fsuricata.git detect/lua: add thread_init Add optional `thread_init` function support. This function is called per script, per thread to allow a user to initialize the lua state. --- diff --git a/src/detect-lua.c b/src/detect-lua.c index 8db1d267a3..bc01d6df28 100644 --- a/src/detect-lua.c +++ b/src/detect-lua.c @@ -523,6 +523,18 @@ static void *DetectLuaThreadInit(void *data) goto error; } + /* thread_init call */ + lua_getglobal(t->luastate, "thread_init"); + if (lua_isfunction(t->luastate, -1)) { + if (lua_pcall(t->luastate, 0, 0, 0) != 0) { + SCLogError("couldn't run script 'thread_init' function: %s", + lua_tostring(t->luastate, -1)); + goto error; + } + } else { + lua_pop(t->luastate, 1); + } + return (void *)t; error: