Newer
Older
#include <signal.h>
#include <stdio.h>
#include <string.h>
static const char *l_pid_path;
static void clear_pid_file() {
FILE * f = fopen(l_pid_path, "w");
if (f == NULL)
log_it(L_WARNING, "Pid file not cleared");
else
fclose(f);
}
log_it(L_DEBUG, "Got exit code: %d", sig_code);
clear_pid_file();
int sig_unix_handler_init(const char *a_pid_path)
{
char * l_pid_dir = dap_path_get_dirname(a_pid_path);
dap_mkdir_with_parents(l_pid_dir);
DAP_DELETE(l_pid_dir);
l_pid_path = strdup(a_pid_path);
struct sigaction new_action, old_action;
new_action.sa_handler = sig_exit_handler;
new_action.sa_flags = 0;
sigaction(SIGTERM, &new_action, &old_action);
sigaction(SIGINT, &new_action, &old_action);
sigaction(SIGHUP, &new_action, &old_action);