mirror of
https://github.com/falcosecurity/falco.git
synced 2025-06-27 07:07:23 +00:00
Set Lua cpath along with path
This commit is contained in:
parent
cc4837312e
commit
8c6bb8a236
@ -33,8 +33,6 @@ $ make
|
|||||||
|
|
||||||
as a result, you should have a digwatch executable `build/userspace/digwatch/digwatch`.
|
as a result, you should have a digwatch executable `build/userspace/digwatch/digwatch`.
|
||||||
|
|
||||||
Still not quite done yet! we need to install the [lpeg](http://www.inf.puc-rio.br/~roberto/lpeg/) Lua library. (This should be done automatically as part of the build of course...). To install it, just do: `luarocks install lpeg`.
|
|
||||||
|
|
||||||
|
|
||||||
### Running
|
### Running
|
||||||
|
|
||||||
|
@ -125,6 +125,37 @@ void do_inspect(sinsp* inspector,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void add_lua_path(lua_State *ls, string path)
|
||||||
|
{
|
||||||
|
string cpath = string(path);
|
||||||
|
path += "?.lua";
|
||||||
|
cpath += "?.so";
|
||||||
|
|
||||||
|
lua_getglobal(ls, "package");
|
||||||
|
|
||||||
|
lua_getfield(ls, -1, "path");
|
||||||
|
string cur_path = lua_tostring(ls, -1 );
|
||||||
|
cur_path += ';';
|
||||||
|
lua_pop(ls, 1);
|
||||||
|
|
||||||
|
cur_path.append(path.c_str());
|
||||||
|
|
||||||
|
lua_pushstring(ls, cur_path.c_str());
|
||||||
|
lua_setfield(ls, -2, "path");
|
||||||
|
|
||||||
|
lua_getfield(ls, -1, "cpath");
|
||||||
|
string cur_cpath = lua_tostring(ls, -1 );
|
||||||
|
cur_cpath += ';';
|
||||||
|
lua_pop(ls, 1);
|
||||||
|
|
||||||
|
cur_cpath.append(cpath.c_str());
|
||||||
|
|
||||||
|
lua_pushstring(ls, cur_cpath.c_str());
|
||||||
|
lua_setfield(ls, -2, "cpath");
|
||||||
|
|
||||||
|
lua_pop(ls, 1);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// ARGUMENT PARSING AND PROGRAM SETUP
|
// ARGUMENT PARSING AND PROGRAM SETUP
|
||||||
//
|
//
|
||||||
@ -241,8 +272,9 @@ int digwatch_init(int argc, char **argv)
|
|||||||
// Initialize Lua interpreter
|
// Initialize Lua interpreter
|
||||||
ls = lua_open();
|
ls = lua_open();
|
||||||
luaL_openlibs(ls);
|
luaL_openlibs(ls);
|
||||||
|
add_lua_path(ls, lua_dir);
|
||||||
|
|
||||||
rules = new digwatch_rules(inspector, ls, lua_main_filename, lua_dir);
|
rules = new digwatch_rules(inspector, ls, lua_main_filename);
|
||||||
|
|
||||||
digwatch_formats::init(inspector, ls);
|
digwatch_formats::init(inspector, ls);
|
||||||
digwatch_fields::init(inspector, ls);
|
digwatch_fields::init(inspector, ls);
|
||||||
|
@ -7,33 +7,15 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
digwatch_rules::digwatch_rules(sinsp* inspector, lua_State *ls, string lua_main_filename, string lua_dir)
|
digwatch_rules::digwatch_rules(sinsp* inspector, lua_State *ls, string lua_main_filename)
|
||||||
{
|
{
|
||||||
m_ls = ls;
|
m_ls = ls;
|
||||||
|
|
||||||
m_lua_parser = new lua_parser(inspector, m_ls);
|
m_lua_parser = new lua_parser(inspector, m_ls);
|
||||||
|
|
||||||
add_lua_path(lua_dir);
|
|
||||||
load_compiler(lua_main_filename);
|
load_compiler(lua_main_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
void digwatch_rules::add_lua_path(string path)
|
|
||||||
{
|
|
||||||
path += "?.lua";
|
|
||||||
|
|
||||||
lua_getglobal(m_ls, "package");
|
|
||||||
lua_getfield(m_ls, -1, "path");
|
|
||||||
|
|
||||||
string cur_path = lua_tostring(m_ls, -1 );
|
|
||||||
cur_path += ';';
|
|
||||||
|
|
||||||
cur_path.append(path.c_str());
|
|
||||||
lua_pop(m_ls, 1);
|
|
||||||
|
|
||||||
lua_pushstring(m_ls, cur_path.c_str());
|
|
||||||
lua_setfield(m_ls, -2, "path");
|
|
||||||
lua_pop(m_ls, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void digwatch_rules::load_compiler(string lua_main_filename)
|
void digwatch_rules::load_compiler(string lua_main_filename)
|
||||||
{
|
{
|
||||||
|
@ -6,13 +6,12 @@
|
|||||||
class digwatch_rules
|
class digwatch_rules
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
digwatch_rules(sinsp* inspector, lua_State *ls, string lua_main_filename, string lua_dir);
|
digwatch_rules(sinsp* inspector, lua_State *ls, string lua_main_filename);
|
||||||
~digwatch_rules();
|
~digwatch_rules();
|
||||||
void load_rules(string rules_filename);
|
void load_rules(string rules_filename);
|
||||||
sinsp_filter* get_filter();
|
sinsp_filter* get_filter();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void add_lua_path(string path);
|
|
||||||
void load_compiler(string lua_main_filename);
|
void load_compiler(string lua_main_filename);
|
||||||
|
|
||||||
lua_parser* m_lua_parser;
|
lua_parser* m_lua_parser;
|
||||||
|
Loading…
Reference in New Issue
Block a user