Merge pull request #12 from draios/build-lpeg

Build lpeg
This commit is contained in:
Henri DF 2016-03-04 17:55:58 -08:00
commit 79e4af09ca
7 changed files with 55 additions and 25 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
build*
/build*

View File

@ -40,6 +40,16 @@ set(LUAJIT_INCLUDE_DIR "${sysdig_BINARY_DIR}/luajit-prefix/src/luajit/src")
message(STATUS "Using bundled curl in '${CURL_BUNDLE_DIR}'")
message(STATUS "Using SSL for curl in '${CURL_SSL_OPTION}'")
include(ExternalProject)
ExternalProject_Add(lpeg
URL "https://s3.amazonaws.com/download.draios.com/dependencies/lpeg-1.0.0.tar.gz"
URL_MD5 "0aec64ccd13996202ad0c099e2877ece"
BUILD_COMMAND LUA_INCLUDE=/sysdig/digwatch/build-ubuntu/sysdig/luajit-prefix/src/luajit/src ${PROJECT_SOURCE_DIR}/scripts/build-lpeg.sh
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ""
INSTALL_COMMAND cp lpeg.so re.lua ${PROJECT_SOURCE_DIR}/userspace/digwatch/lua)
add_subdirectory(userspace/digwatch)

View File

@ -33,8 +33,6 @@ $ make
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

9
scripts/build-lpeg.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/sh
gcc -O2 -fPIC -I$LUA_INCLUDE -c lpcap.c -o lpcap.o
gcc -O2 -fPIC -I$LUA_INCLUDE -c lpcode.c -o lpcode.o
gcc -O2 -fPIC -I$LUA_INCLUDE -c lpprint.c -o lpprint.o
gcc -O2 -fPIC -I$LUA_INCLUDE -c lptree.c -o lptree.o
gcc -O2 -fPIC -I$LUA_INCLUDE -c lpvm.c -o lpvm.o
gcc -shared -o lpeg.so -L/usr/local/lib lpcap.o lpcode.o lpprint.o lptree.o lpvm.o

View File

@ -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
//
@ -241,8 +272,9 @@ int digwatch_init(int argc, char **argv)
// Initialize Lua interpreter
ls = lua_open();
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_fields::init(inspector, ls);

View File

@ -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_lua_parser = new lua_parser(inspector, m_ls);
add_lua_path(lua_dir);
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)
{

View File

@ -6,13 +6,12 @@
class digwatch_rules
{
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();
void load_rules(string rules_filename);
sinsp_filter* get_filter();
private:
void add_lua_path(string path);
void load_compiler(string lua_main_filename);
lua_parser* m_lua_parser;