mirror of
https://github.com/kakwa/uts-server
synced 2025-01-09 21:24:29 +01:00
implementing a somewhat proper signal handler
This commit is contained in:
parent
fa7dabcb81
commit
d91fbe377e
@ -5,3 +5,5 @@ void uts_logger(rfc3161_context *ct, int priority, char *fmt, ...);
|
|||||||
void log_hex(rfc3161_context *ct, int priority, char *id,
|
void log_hex(rfc3161_context *ct, int priority, char *id,
|
||||||
unsigned char *content, int content_length);
|
unsigned char *content, int content_length);
|
||||||
int set_params(rfc3161_context *ct, char *conf_file);
|
int set_params(rfc3161_context *ct, char *conf_file);
|
||||||
|
int g_uts_sig_up;
|
||||||
|
int g_uts_sig;
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <sys/syslog.h>
|
#include <sys/syslog.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include "http.h"
|
#include "http.h"
|
||||||
|
|
||||||
void log_request_debug(const struct mg_request_info *request_info,
|
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.
|
// Wait until user hits "enter". Server is running in separate thread.
|
||||||
// Navigating to http://localhost:8080 will invoke begin_request_handler().
|
// Navigating to http://localhost:8080 will invoke begin_request_handler().
|
||||||
getchar();
|
while ( g_uts_sig == 0 ){
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
// Stop the server.
|
// Stop the server.
|
||||||
mg_stop(ctx);
|
mg_stop(ctx);
|
||||||
|
@ -30,6 +30,14 @@ CODE prioritynames[] = {{"alert", LOG_ALERT},
|
|||||||
{"warning", LOG_WARNING},
|
{"warning", LOG_WARNING},
|
||||||
{NULL, -1}};
|
{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() {
|
void skeleton_daemon() {
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
@ -48,10 +56,14 @@ void skeleton_daemon() {
|
|||||||
if (setsid() < 0)
|
if (setsid() < 0)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
|
g_uts_sig_up = 0;
|
||||||
|
g_uts_sig = 0;
|
||||||
/* Catch, ignore and handle signals */
|
/* Catch, ignore and handle signals */
|
||||||
// TODO: Implement a working signal handler */
|
// 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(SIGCHLD, SIG_IGN);
|
||||||
signal(SIGHUP, SIG_IGN);
|
|
||||||
|
|
||||||
/* Fork off for the second time*/
|
/* Fork off for the second time*/
|
||||||
pid = fork();
|
pid = fork();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user