Skip to content
Snippets Groups Projects
Commit 9c1de9b6 authored by Fredrik Thulin's avatar Fredrik Thulin
Browse files

Graceful shutdown on SIGTERM.

Helps find resource leaks, if nothing else.
parent c847c5c6
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <signal.h>
#include <dlfcn.h> #include <dlfcn.h>
#include <pthread.h> #include <pthread.h>
...@@ -111,6 +112,7 @@ static int install_syscall_filter(void) ...@@ -111,6 +112,7 @@ static int install_syscall_filter(void)
ALLOW_SYSCALL(set_robust_list), ALLOW_SYSCALL(set_robust_list),
ALLOW_SYSCALL(recvfrom), ALLOW_SYSCALL(recvfrom),
ALLOW_SYSCALL(madvise), ALLOW_SYSCALL(madvise),
ALLOW_SYSCALL(rt_sigaction),
KILL_PROCESS, KILL_PROCESS,
}; };
struct sock_fprog prog = { struct sock_fprog prog = {
...@@ -154,6 +156,11 @@ static int usage(void) ...@@ -154,6 +156,11 @@ static int usage(void)
exit(2); exit(2);
} }
void termination_handler (int signum)
{
is_running = 0;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
CK_C_GetFunctionList func_get_list; CK_C_GetFunctionList func_get_list;
...@@ -225,6 +232,10 @@ int main(int argc, char *argv[]) ...@@ -225,6 +232,10 @@ int main(int argc, char *argv[])
if (sock == -1) if (sock == -1)
exit(1); exit(1);
/* Shut down gracefully on SIGTERM. */
if (signal (SIGTERM, termination_handler) == SIG_IGN)
signal (SIGTERM, SIG_IGN);
is_running = 1; is_running = 1;
while (is_running) { while (is_running) {
FD_ZERO(&read_fds); FD_ZERO(&read_fds);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment