diff --git a/userspace/digwatch/digwatch.cpp b/userspace/digwatch/digwatch.cpp index fd0c47d9..f73e56e1 100644 --- a/userspace/digwatch/digwatch.cpp +++ b/userspace/digwatch/digwatch.cpp @@ -52,7 +52,6 @@ string lua_on_event = "on_event"; // void do_inspect(sinsp* inspector, digwatch_rules* rules, - digwatch_formats* formats, lua_State* ls) { int32_t res; @@ -119,7 +118,6 @@ int digwatch_init(int argc, char **argv) int result = EXIT_SUCCESS; sinsp* inspector = NULL; digwatch_rules* rules = NULL; - digwatch_formats* formats = NULL; int op; sinsp_evt::param_fmt event_buffer_format = sinsp_evt::PF_NORMAL; int long_index = 0; @@ -216,7 +214,9 @@ int digwatch_init(int argc, char **argv) luaL_openlibs(ls); rules = new digwatch_rules(inspector, ls, lua_main_filename, lua_dir); - formats = new digwatch_formats(inspector, ls); + + digwatch_formats::init(inspector, ls); + digwatch_fields::init(inspector, ls); rules->load_rules(rules_file); inspector->set_filter(rules->get_filter()); @@ -224,7 +224,6 @@ int digwatch_init(int argc, char **argv) do_inspect(inspector, rules, - formats, ls); inspector->close(); diff --git a/userspace/digwatch/formats.cpp b/userspace/digwatch/formats.cpp index c2670960..b6063f16 100644 --- a/userspace/digwatch/formats.cpp +++ b/userspace/digwatch/formats.cpp @@ -1,7 +1,7 @@ #include "formats.h" -sinsp* g_inspector; +sinsp* digwatch_formats::s_inspector = NULL; const static struct luaL_reg ll_digwatch [] = { @@ -10,13 +10,11 @@ const static struct luaL_reg ll_digwatch [] = {NULL,NULL} }; -digwatch_formats::digwatch_formats(sinsp* inspector, lua_State *ls) +void digwatch_formats::init(sinsp* inspector, lua_State *ls) { - g_inspector = inspector; + s_inspector = inspector; - m_ls = ls; - - luaL_openlib(m_ls, "digwatch", ll_digwatch, 0); + luaL_openlib(ls, "digwatch", ll_digwatch, 0); } int digwatch_formats::formatter(lua_State *ls) @@ -25,7 +23,7 @@ int digwatch_formats::formatter(lua_State *ls) sinsp_evt_formatter* formatter; try { - formatter = new sinsp_evt_formatter(g_inspector, format); + formatter = new sinsp_evt_formatter(s_inspector, format); } catch(sinsp_exception& e) { diff --git a/userspace/digwatch/formats.h b/userspace/digwatch/formats.h index 1108c094..3f9fc7cc 100644 --- a/userspace/digwatch/formats.h +++ b/userspace/digwatch/formats.h @@ -13,7 +13,7 @@ class sinsp_evt_formatter; class digwatch_formats { public: - digwatch_formats(sinsp* inspector, lua_State *ls); + static void init(sinsp* inspector, lua_State *ls); // formatter = digwatch.formatter(format_string) static int formatter(lua_State *ls); @@ -21,6 +21,8 @@ class digwatch_formats // formatted_string = digwatch.format_event(evt, formatter) static int format_event(lua_State *ls); + static sinsp* s_inspector; + private: lua_State* m_ls; };