Newer
Older
#include <signal.h>
#include <stdio.h>
#include <string.h>
static const char *s_pid_path = NULL;
FILE * f = fopen(s_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);
//sleep(1); // Don't know why but without it it crashes O_o
//dap_mkdir_with_parents(l_pid_dir);
//DAP_DELETE(l_pid_dir);
s_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);
return 0;
}
int sig_unix_handler_deinit() {
if( s_pid_path )
DAP_DELETE(s_pid_path);
signal(SIGTERM, SIG_DFL);
signal(SIGINT, SIG_DFL);
signal(SIGHUP, SIG_DFL);
return 0;
}