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 1e863ee7..686a353a 100644 --- a/userspace/digwatch/digwatch.cpp +++ b/userspace/digwatch/digwatch.cpp @@ -190,7 +190,7 @@ int digwatch_init(int argc, char **argv) // Parse the args // while((op = getopt_long(argc, argv, - "hm:No:", + "hNo:", long_options, &long_index)) != -1) { switch(op) @@ -198,9 +198,6 @@ int digwatch_init(int argc, char **argv) case 'h': usage(); goto exit; - case 'm': - lua_main_filename = optarg; - break; case 'N': inspector->set_hostname_and_port_resolution_mode(false); break; @@ -265,18 +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; + } } - trim(lua_main_filename); - if(lua_main_filename.size() == 0) - { - lua_main_filename = lua_dir + DIGWATCH_LUA_MAIN; - } // Initialize Lua interpreter ls = lua_open();