|
|
@ -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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g_run = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Signal handler for SIGUSR1 - backup the db. */
|
|
|
|
|
|
|
|
void handle_sigusr1(int signal)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
UNUSED(signal);
|
|
|
|
UNUSED(signal);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(signal == SIGINT || signal == SIGTERM){
|
|
|
|
|
|
|
|
g_run = 0;
|
|
|
|
|
|
|
|
#ifdef SIGHUP
|
|
|
|
|
|
|
|
}else if(signal == SIGHUP){
|
|
|
|
|
|
|
|
flag_reload = true;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}else if(signal == SIGUSR1){
|
|
|
|
#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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|