mirror of
https://github.com/falcosecurity/falco.git
synced 2025-10-21 19:44:57 +00:00
Signal handlers and clean(er) exit
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -22,6 +23,13 @@ extern "C" {
|
||||
#include "fields.h"
|
||||
#include "utils.h"
|
||||
|
||||
static bool g_terminate = false;
|
||||
|
||||
static void signal_callback(int signal)
|
||||
{
|
||||
g_terminate = true;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Program help
|
||||
@@ -64,6 +72,12 @@ void do_inspect(sinsp* inspector,
|
||||
//
|
||||
while(1)
|
||||
{
|
||||
|
||||
if(g_terminate)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
res = inspector->next(&ev);
|
||||
|
||||
if(res == SCAP_TIMEOUT)
|
||||
@@ -197,6 +211,20 @@ int digwatch_init(int argc, char **argv)
|
||||
|
||||
}
|
||||
|
||||
if(signal(SIGINT, signal_callback) == SIG_ERR)
|
||||
{
|
||||
fprintf(stderr, "An error occurred while setting SIGINT signal handler.\n");
|
||||
result = EXIT_FAILURE;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if(signal(SIGTERM, signal_callback) == SIG_ERR)
|
||||
{
|
||||
fprintf(stderr, "An error occurred while setting SIGTERM signal handler.\n");
|
||||
result = EXIT_FAILURE;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
//
|
||||
char* env_lua_dir = getenv("DIGWATCH_LUA_DIR");
|
||||
if(env_lua_dir)
|
||||
|
Reference in New Issue
Block a user