From 21e588394f034e9ebf1e6b7103ae63f15578b499 Mon Sep 17 00:00:00 2001 From: Leonardo Di Donato Date: Mon, 16 Sep 2019 05:22:14 +0000 Subject: [PATCH] new(userspace/falco): handle SIGHUP and SIGINT in the main process not in the spawned threads (grpc server) Signed-off-by: Leonardo Di Donato --- userspace/falco/grpc_server.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/userspace/falco/grpc_server.cpp b/userspace/falco/grpc_server.cpp index e5c004ba..b39c18e4 100644 --- a/userspace/falco/grpc_server.cpp +++ b/userspace/falco/grpc_server.cpp @@ -21,7 +21,8 @@ limitations under the License. #else #include #endif -#include // sleep +#include // pthread_sigmask +#include // sleep, _exit #include "logger.h" #include "grpc_server.h" @@ -188,8 +189,26 @@ void read(const std::string& filename, std::string& data) return; } +extern "C" void handle_signal(int signum) +{ + // todo > print "Got signal << sigenum << : exiting..."); + exit(1); +} + void falco_grpc_server::run() { + // Handle SIGHUP and SIGINT in the main process. + // Not in the spawned threads. + sigset_t set; + sigemptyset(&set); + sigaddset(&set, SIGHUP); + sigaddset(&set, SIGINT); + pthread_sigmask(SIG_UNBLOCK, &set, nullptr); + struct sigaction action; + action.sa_handler = handle_signal; + sigaction(SIGHUP, &action, nullptr); + sigaction(SIGINT, &action, nullptr); + string private_key; string cert_chain; string root_certs;