mirror of
https://github.com/kakwa/uts-server
synced 2024-12-04 15:05:54 +01:00
set signal handler also when running in foreground
This commit is contained in:
parent
0e0b11310d
commit
8fefcbaf6b
@ -7,6 +7,7 @@ typedef struct _code {
|
||||
|
||||
static void signal_handler_general(int sig_num);
|
||||
static void signal_handler_up(int sig_num);
|
||||
void set_sig_handler();
|
||||
void skeleton_daemon();
|
||||
int init_pid(char *pidfile_path);
|
||||
int write_pid(char *pidfile_path);
|
||||
|
@ -101,6 +101,8 @@ int main(int argc, char **argv) {
|
||||
|
||||
if (args.daemonize)
|
||||
skeleton_daemon();
|
||||
else
|
||||
set_sig_handler();
|
||||
|
||||
syslog(LOG_NOTICE,
|
||||
"uts-server daemon starting with conf '%s' from working dir '%s'",
|
||||
|
@ -67,6 +67,17 @@ int write_pid(char *pidfile_path) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void set_sig_handler() {
|
||||
g_uts_sig_up = 0;
|
||||
g_uts_sig = 0;
|
||||
/* Catch, ignore and handle signals */
|
||||
// TODO: Implement a working signal handler */
|
||||
signal(SIGTERM, signal_handler_general);
|
||||
signal(SIGINT, signal_handler_general);
|
||||
signal(SIGHUP, signal_handler_up);
|
||||
signal(SIGCHLD, SIG_IGN);
|
||||
}
|
||||
|
||||
void skeleton_daemon() {
|
||||
pid_t pid;
|
||||
|
||||
@ -85,14 +96,7 @@ void skeleton_daemon() {
|
||||
if (setsid() < 0)
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
g_uts_sig_up = 0;
|
||||
g_uts_sig = 0;
|
||||
/* Catch, ignore and handle signals */
|
||||
// TODO: Implement a working signal handler */
|
||||
signal(SIGTERM, signal_handler_general);
|
||||
signal(SIGINT, signal_handler_general);
|
||||
signal(SIGHUP, signal_handler_up);
|
||||
signal(SIGCHLD, SIG_IGN);
|
||||
set_sig_handler();
|
||||
|
||||
/* Fork off for the second time*/
|
||||
pid = fork();
|
||||
|
Loading…
Reference in New Issue
Block a user