From dcbae750c8214919b99c471fe77a361e09de9540 Mon Sep 17 00:00:00 2001 From: Henri DF Date: Wed, 6 Apr 2016 16:04:44 -0700 Subject: [PATCH] Remove the need for DIGWATCH_LUA_DIR env var --- README.md | 7 +------ userspace/digwatch/config_digwatch.h.in | 2 ++ userspace/digwatch/digwatch.cpp | 17 ++++++++++++----- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 3bdef216..6127845a 100644 --- a/README.md +++ b/README.md @@ -34,12 +34,7 @@ $ make as a result, you should have a digwatch executable `build/userspace/digwatch/digwatch`. -### Running - -Set the path of the digwatch lua directory in the env var `DIGWATCH_LUA_DIR`: - -`export DIGWATCH_LUA_DIR=/userspace/digwatch/lua/` - +### Running locally-built sysdig Create a file with some [digwatch rules](Rule-syntax-and-design). For example: diff --git a/userspace/digwatch/config_digwatch.h.in b/userspace/digwatch/config_digwatch.h.in index c29ede36..ad40da3a 100644 --- a/userspace/digwatch/config_digwatch.h.in +++ b/userspace/digwatch/config_digwatch.h.in @@ -3,6 +3,8 @@ #define DIGWATCH_VERSION "${DIGWATCH_VERSION}" #define DIGWATCH_LUA_DIR "/usr/share/digwatch/lua/" +#define DIGWATCH_SOURCE_LUA_DIR "${PROJECT_SOURCE_DIR}/userspace/digwatch/lua/" + #define DIGWATCH_LUA_MAIN "${DIGWATCH_LUA_MAIN}" diff --git a/userspace/digwatch/digwatch.cpp b/userspace/digwatch/digwatch.cpp index 2b0c75e8..686a353a 100644 --- a/userspace/digwatch/digwatch.cpp +++ b/userspace/digwatch/digwatch.cpp @@ -262,14 +262,21 @@ int digwatch_init(int argc, char **argv) goto exit; } - // - char* env_lua_dir = getenv("DIGWATCH_LUA_DIR"); - if(env_lua_dir) + lua_main_filename = lua_dir + DIGWATCH_LUA_MAIN; + if (!std::ifstream(lua_main_filename)) { - lua_dir = string(env_lua_dir); + lua_dir = DIGWATCH_SOURCE_LUA_DIR; + lua_main_filename = lua_dir + DIGWATCH_LUA_MAIN; + if (!std::ifstream(lua_main_filename)) + { + fprintf(stderr, "Could not find Digwatch Lua libraries (tried %s, %s). \n", + DIGWATCH_LUA_DIR DIGWATCH_LUA_MAIN, + lua_main_filename.c_str()); + result = EXIT_FAILURE; + goto exit; + } } - lua_main_filename = lua_dir + DIGWATCH_LUA_MAIN; // Initialize Lua interpreter ls = lua_open();