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();
exit(0);
}
int sig_unix_handler_init(const char *pid_path) {
l_pid_path = strdup(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);