mirror of
https://github.com/falcosecurity/falco.git
synced 2025-07-06 19:29:09 +00:00
search for yaml config file
In order: 1) cmdline opt 2) in-tree path 3) /etc/digwatch.yaml
This commit is contained in:
parent
73ec593931
commit
42de0507fa
@ -4,7 +4,8 @@
|
||||
|
||||
#define DIGWATCH_LUA_DIR "/usr/share/digwatch/lua/"
|
||||
#define DIGWATCH_SOURCE_DIR "${PROJECT_SOURCE_DIR}"
|
||||
#define DIGWATCH_CONF_FILE "${PROJECT_SOURCE_DIR}/digwatch.yaml"
|
||||
#define DIGWATCH_SOURCE_CONF_FILE "${PROJECT_SOURCE_DIR}/digwatch.yaml"
|
||||
#define DIGWATCH_INSTALL_CONF_FILE "/etc/digwatch.yaml"
|
||||
#define DIGWATCH_SOURCE_LUA_DIR "${PROJECT_SOURCE_DIR}/userspace/digwatch/lua/"
|
||||
|
||||
|
||||
|
@ -173,6 +173,7 @@ int digwatch_init(int argc, char **argv)
|
||||
string lua_main_filename;
|
||||
string output_name = "stdout";
|
||||
string infile;
|
||||
string conf_filename;
|
||||
string lua_dir = DIGWATCH_LUA_DIR;
|
||||
lua_State* ls = NULL;
|
||||
|
||||
@ -192,7 +193,7 @@ int digwatch_init(int argc, char **argv)
|
||||
// Parse the args
|
||||
//
|
||||
while((op = getopt_long(argc, argv,
|
||||
"ho:r:",
|
||||
"c:ho:R:",
|
||||
long_options, &long_index)) != -1)
|
||||
{
|
||||
switch(op)
|
||||
@ -200,6 +201,9 @@ int digwatch_init(int argc, char **argv)
|
||||
case 'h':
|
||||
usage();
|
||||
goto exit;
|
||||
case 'c':
|
||||
conf_filename = optarg;
|
||||
break;
|
||||
case 'o':
|
||||
valid = std::find(valid_output_names.begin(), valid_output_names.end(), optarg) != valid_output_names.end();
|
||||
if (!valid)
|
||||
@ -250,8 +254,49 @@ int digwatch_init(int argc, char **argv)
|
||||
|
||||
}
|
||||
|
||||
ifstream* conf_stream;
|
||||
if (conf_filename.size())
|
||||
{
|
||||
conf_stream = new ifstream(conf_filename);
|
||||
if (!conf_stream->good())
|
||||
{
|
||||
fprintf(stderr, "Could not find configuration file at %s \n", conf_filename.c_str());
|
||||
result = EXIT_FAILURE;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
conf_stream = new ifstream(DIGWATCH_SOURCE_CONF_FILE);
|
||||
if (conf_stream->good())
|
||||
{
|
||||
conf_filename = DIGWATCH_SOURCE_CONF_FILE;
|
||||
}
|
||||
else
|
||||
{
|
||||
conf_stream = new ifstream(DIGWATCH_INSTALL_CONF_FILE);
|
||||
if (conf_stream->good())
|
||||
{
|
||||
conf_filename = DIGWATCH_INSTALL_CONF_FILE;
|
||||
}
|
||||
else
|
||||
{
|
||||
conf_filename = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
digwatch_configuration config;
|
||||
config.init();
|
||||
if (conf_filename.size())
|
||||
{
|
||||
cout << "Using configuration file " + conf_filename + "\n";
|
||||
config.init(conf_filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "No configuration file found, proceeding with defaults\n";
|
||||
config.init();
|
||||
}
|
||||
|
||||
if(signal(SIGINT, signal_callback) == SIG_ERR)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user