1
0
mirror of https://github.com/kakwa/uts-server synced 2024-12-04 23:15:54 +01:00

implementing a somewhat proper signal handler

This commit is contained in:
kakwa 2016-08-31 07:57:51 +02:00
parent f3a950dc41
commit 93ead7ee99
3 changed files with 19 additions and 2 deletions

View File

@ -5,3 +5,5 @@ void uts_logger(rfc3161_context *ct, int priority, char *fmt, ...);
void log_hex(rfc3161_context *ct, int priority, char *id,
unsigned char *content, int content_length);
int set_params(rfc3161_context *ct, char *conf_file);
int g_uts_sig_up;
int g_uts_sig;

View File

@ -12,6 +12,7 @@
#include <string.h>
#include <stdbool.h>
#include <sys/syslog.h>
#include <unistd.h>
#include "http.h"
void log_request_debug(const struct mg_request_info *request_info,
@ -147,7 +148,9 @@ int http_server_start(char *conffile, bool stdout_dbg) {
// Wait until user hits "enter". Server is running in separate thread.
// Navigating to http://localhost:8080 will invoke begin_request_handler().
getchar();
while ( g_uts_sig == 0 ){
sleep(1);
}
// Stop the server.
mg_stop(ctx);

View File

@ -30,6 +30,14 @@ CODE prioritynames[] = {{"alert", LOG_ALERT},
{"warning", LOG_WARNING},
{NULL, -1}};
static void signal_handler_general(int sig_num) {
g_uts_sig = sig_num;
}
static void signal_handler_up(int sig_num) {
g_uts_sig_up = sig_num;
}
void skeleton_daemon() {
pid_t pid;
@ -48,10 +56,14 @@ 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);
signal(SIGHUP, SIG_IGN);
/* Fork off for the second time*/
pid = fork();