mirror of
https://github.com/falcosecurity/falco.git
synced 2025-09-11 03:29:33 +00:00
Move falco engine to its own library.
Move the c++ and lua code implementing falco engine/falco common to its own directory userspace/engine. It's compiled as a static library libfalco_engine.a, and has its own CMakeLists.txt so it can be included by other projects. The engine's CMakeLists.txt has a add_subdirectory for the falco rules directory, so including the engine also builds the rules. The variables you need to set to use the engine's CMakeLists.txt are: - CMAKE_INSTALL_PREFIX: the root directory below which everything is installed. - FALCO_ETC_DIR: where to install the rules file. - FALCO_SHARE_DIR: where to install lua code, relative to the - install/package root. - LUAJIT_INCLUDE: where to find header files for lua. - FALCO_SINSP_LIBRARY: the library containing sinsp code. It will be - considered a dependency of the engine. - LPEG_LIB/LYAML_LIB/LIBYAML_LIB: locations for third-party libraries. - FALCO_COMPONENT: if set, will be included as a part of any install() commands. Instead of specifying /usr/share/falco in config_falco_*.h.in, use CMAKE_INSTALL_PREFIX and FALCO_SHARE_DIR. The lua code for the engine has also moved, so the two lua source directories (userspace/engine/lua and userspace/falco/lua) need to be available separately via falco_common, so make it an argument to falco_common::init. As a part of making it easy to include in another project, also clean up LPEG build/defs. Modify build-lpeg to add a PREFIX argument to allow for object files/libraries being in an alternate location, and when building lpeg, put object files in a build/ subdirectory.
This commit is contained in:
69
userspace/engine/falco_common.h
Normal file
69
userspace/engine/falco_common.h
Normal file
@@ -0,0 +1,69 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <exception>
|
||||
|
||||
extern "C" {
|
||||
#include "lua.h"
|
||||
#include "lualib.h"
|
||||
#include "lauxlib.h"
|
||||
}
|
||||
|
||||
#include <sinsp.h>
|
||||
|
||||
//
|
||||
// Most falco_* classes can throw exceptions. Unless directly related
|
||||
// to low-level failures like inability to open file, etc, they will
|
||||
// be of this type.
|
||||
//
|
||||
|
||||
struct falco_exception : std::exception
|
||||
{
|
||||
falco_exception()
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~falco_exception() throw()
|
||||
{
|
||||
}
|
||||
|
||||
falco_exception(std::string error_str)
|
||||
{
|
||||
m_error_str = error_str;
|
||||
}
|
||||
|
||||
char const* what() const throw()
|
||||
{
|
||||
return m_error_str.c_str();
|
||||
}
|
||||
|
||||
std::string m_error_str;
|
||||
};
|
||||
|
||||
//
|
||||
// This is the base class of falco_engine/falco_output. It is
|
||||
// responsible for managing a lua state and associated inspector and
|
||||
// loading a single "main" lua file into that state.
|
||||
//
|
||||
|
||||
class falco_common
|
||||
{
|
||||
public:
|
||||
falco_common();
|
||||
virtual ~falco_common();
|
||||
|
||||
void init(const char *lua_main_filename, const char *source_dir);
|
||||
|
||||
void set_inspector(sinsp *inspector);
|
||||
|
||||
protected:
|
||||
lua_State *m_ls;
|
||||
|
||||
sinsp *m_inspector;
|
||||
|
||||
private:
|
||||
void add_lua_path(std::string &path);
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user