]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/lua: add thread_init
authorVictor Julien <vjulien@oisf.net>
Mon, 10 Jun 2024 18:34:40 +0000 (20:34 +0200)
committerVictor Julien <victor@inliniac.net>
Sun, 12 Jan 2025 19:02:35 +0000 (20:02 +0100)
Add optional `thread_init` function support. This function is called per
script, per thread to allow a user to initialize the lua state.

src/detect-lua.c

index 8db1d267a38dace93a71152daf248ba066466c53..bc01d6df28d46a16045c6ba5218290dde5f0c192 100644 (file)
@@ -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: