Simplify signal handling.

pull/2346/head
Roger A. Light 4 years ago
parent 9d3f292b39
commit 7857e5cedb

@ -61,11 +61,6 @@ struct mosquitto_db db;
struct mosquitto__listener_sock *g_listensock = NULL; struct mosquitto__listener_sock *g_listensock = NULL;
int g_listensock_count = 0; int g_listensock_count = 0;
bool flag_reload = false;
#ifdef WITH_PERSISTENCE
bool flag_db_backup = false;
#endif
bool flag_tree_print = false;
int g_run = 0; int g_run = 0;
#ifdef WITH_WRAP #ifdef WITH_WRAP
#include <syslog.h> #include <syslog.h>
@ -168,24 +163,6 @@ static void mosquitto__daemonise(void)
} }
static void signal__setup(void)
{
signal(SIGINT, handle_sigint);
signal(SIGTERM, handle_sigint);
#ifdef SIGHUP
signal(SIGHUP, handle_sighup);
#endif
#ifndef WIN32
signal(SIGUSR1, handle_sigusr1);
signal(SIGUSR2, handle_sigusr2);
signal(SIGPIPE, SIG_IGN);
#endif
#ifdef WIN32
CreateThread(NULL, 0, SigThreadProc, NULL, 0, NULL);
#endif
}
static int pid__write(void) static int pid__write(void)
{ {
FILE *pid; FILE *pid;

@ -895,12 +895,7 @@ void session_expiry__send_all(void);
/* ============================================================ /* ============================================================
* Signals * Signals
* ============================================================ */ * ============================================================ */
void handle_sigint(int signal); void signal__setup(void);
void handle_sigusr1(int signal);
void handle_sigusr2(int signal);
#ifdef SIGHUP
void handle_sighup(int signal);
#endif
/* ============================================================ /* ============================================================
* Window service and signal related functions * Window service and signal related functions

@ -31,47 +31,49 @@ Contributors:
#include "mosquitto_broker_internal.h" #include "mosquitto_broker_internal.h"
#ifdef WITH_PERSISTENCE
extern bool flag_db_backup;
#endif
extern bool flag_reload;
extern bool flag_tree_print;
extern int g_run; extern int g_run;
#ifdef SIGHUP bool flag_reload = false;
/* Signal handler for SIGHUP - flag a config reload. */ #ifdef WITH_PERSISTENCE
void handle_sighup(int signal) bool flag_db_backup = false;
{
UNUSED(signal);
flag_reload = true;
}
#endif #endif
bool flag_tree_print = false;
/* Signal handler for SIGINT and SIGTERM - just stop gracefully. */ static void handle_signal(int signal)
void handle_sigint(int signal)
{ {
UNUSED(signal); UNUSED(signal);
if(signal == SIGINT || signal == SIGTERM){
g_run = 0; g_run = 0;
} #ifdef SIGHUP
}else if(signal == SIGHUP){
/* Signal handler for SIGUSR1 - backup the db. */ flag_reload = true;
void handle_sigusr1(int signal) #endif
{ }else if(signal == SIGUSR1){
UNUSED(signal);
#ifdef WITH_PERSISTENCE #ifdef WITH_PERSISTENCE
flag_db_backup = true; flag_db_backup = true;
#endif #endif
}else if(signal == SIGUSR2){
flag_tree_print = true;
}
} }
/* Signal handler for SIGUSR2 - print subscription / retained tree. */
void handle_sigusr2(int signal)
{
UNUSED(signal);
flag_tree_print = true; void signal__setup(void)
{
signal(SIGINT, handle_signal);
signal(SIGTERM, handle_signal);
#ifdef SIGHUP
signal(SIGHUP, handle_signal);
#endif
#ifndef WIN32
signal(SIGUSR1, handle_signal);
signal(SIGUSR2, handle_signal);
signal(SIGPIPE, SIG_IGN);
#endif
#ifdef WIN32
CreateThread(NULL, 0, SigThreadProc, NULL, 0, NULL);
#endif
} }
/* /*

Loading…
Cancel
Save