mirror of https://github.com/OISF/suricata
lua/util: move SCThreadInfo into suricata.util lib
Move the SCThreadInfo global function into the suricata.util library as thread_info(). This is the last global function to be registered, so remove the supporting functions.pull/13361/head
parent
778a699622
commit
e5faedf7e6
@ -0,0 +1,34 @@
|
||||
Util
|
||||
####
|
||||
|
||||
The ``suricata.util`` library provides utility functions for Lua
|
||||
scripts.
|
||||
|
||||
Setup
|
||||
*****
|
||||
|
||||
The library must be loaded prior to use::
|
||||
|
||||
local util = require("suricata.util")
|
||||
|
||||
Functions
|
||||
=========
|
||||
|
||||
.. function:: thread_info()
|
||||
|
||||
Get information about the current thread.
|
||||
|
||||
:returns: Table containing thread information with the following fields:
|
||||
|
||||
- ``id`` (number): Thread ID
|
||||
- ``name`` (string): Thread name
|
||||
- ``group_name`` (string): Thread group name
|
||||
|
||||
Example::
|
||||
|
||||
local util = require("suricata.util")
|
||||
|
||||
local info = util.thread_info()
|
||||
print("Thread ID: " .. info.id)
|
||||
print("Thread Name: " .. info.name)
|
||||
print("Thread Group: " .. info.group_name)
|
||||
@ -0,0 +1,67 @@
|
||||
/* Copyright (C) 2025 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.
|
||||
*/
|
||||
|
||||
#include "suricata-common.h"
|
||||
#include "threads.h"
|
||||
#include "threadvars.h"
|
||||
|
||||
#include "util-lua.h"
|
||||
#include "util-lua-common.h"
|
||||
#include "util-lua-util.h"
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
/**
|
||||
* \brief Get thread information and return as a table
|
||||
* \retval 1 table with thread info fields: id, name, thread_group_name
|
||||
*/
|
||||
static int LuaUtilThreadInfo(lua_State *luastate)
|
||||
{
|
||||
const ThreadVars *tv = LuaStateGetThreadVars(luastate);
|
||||
if (tv == NULL)
|
||||
return LuaCallbackError(luastate, "internal error: no tv");
|
||||
|
||||
unsigned long tid = SCGetThreadIdLong();
|
||||
|
||||
lua_newtable(luastate);
|
||||
|
||||
lua_pushstring(luastate, "id");
|
||||
lua_pushinteger(luastate, (lua_Integer)tid);
|
||||
lua_settable(luastate, -3);
|
||||
|
||||
lua_pushstring(luastate, "name");
|
||||
lua_pushstring(luastate, tv->name);
|
||||
lua_settable(luastate, -3);
|
||||
|
||||
lua_pushstring(luastate, "group_name");
|
||||
lua_pushstring(luastate, tv->thread_group_name);
|
||||
lua_settable(luastate, -3);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const struct luaL_Reg utillib[] = {
|
||||
{ "thread_info", LuaUtilThreadInfo },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
int SCLuaLoadUtilLib(lua_State *L)
|
||||
{
|
||||
luaL_newlib(L, utillib);
|
||||
return 1;
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
/* Copyright (C) 2025 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.
|
||||
*/
|
||||
|
||||
#ifndef SURICATA_UTIL_LUA_UTIL_H
|
||||
#define SURICATA_UTIL_LUA_UTIL_H
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
int SCLuaLoadUtilLib(lua_State *L);
|
||||
|
||||
#endif /* SURICATA_UTIL_LUA_UTIL_H */
|
||||
Loading…
Reference in New Issue