diff --git a/apps/mosquitto_signal/signal_windows.c b/apps/mosquitto_signal/signal_windows.c index e8528933f..6a897e6a0 100644 --- a/apps/mosquitto_signal/signal_windows.c +++ b/apps/mosquitto_signal/signal_windows.c @@ -32,7 +32,25 @@ SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause #include "mosquitto_signal.h" -void signal_all(const char *eventname) +static const char *msig_to_string(enum mosq_sig sig) +{ + switch(sig){ + case MSIG_CONFIG_RELOAD: + return "reload"; + case MSIG_LOG_ROTATE: + return "log_rotate"; + case MSIG_SHUTDOWN: + return "shutdown"; + case MSIG_TREE_PRINT: + return "tree_print"; + case MSIG_XTREPORT: + return "xtreport"; + default: + return ""; + } +} + +void signal_all(enum mosq_signal sig) { DWORD processes[2048], cbneeded, count; int pid; @@ -54,7 +72,7 @@ void signal_all(const char *eventname) GetModuleBaseName(hproc, hmod, procname, sizeof(procname)); if(!strcasecmp(procname, "mosquitto.exe")){ pid = GetProcessId(hproc); - signal_one(pid, eventname); + signal_one(pid, sig); } } CloseHandle(hproc); @@ -63,13 +81,13 @@ void signal_all(const char *eventname) } } -void signal_one(int pid, const char *eventname) +void signal_one(int pid, enum mosq_signal sig) { HANDLE evt; char eventbuf[MAX_PATH+1]; BOOL res; - snprintf(eventbuf, sizeof(eventbuf), "mosq%d_%s", pid, eventname); + snprintf(eventbuf, sizeof(eventbuf), "mosq%d_%s", pid, msig_to_string(sig)); evt = OpenEvent(EVENT_MODIFY_STATE, FALSE, eventbuf); if(evt){ res = PulseEvent(evt); diff --git a/src/signals.c b/src/signals.c index 41028f935..8256d3991 100644 --- a/src/signals.c +++ b/src/signals.c @@ -39,6 +39,7 @@ static bool flag_log_rotate = false; static bool flag_db_backup = false; #endif static bool flag_tree_print = false; +static bool flag_xtreport = false; static void handle_signal(int signal) { @@ -59,6 +60,7 @@ static void handle_signal(int signal) #ifdef SIGUSR2 }else if(signal == SIGUSR2){ flag_tree_print = true; + flag_xtreport = true; #endif #ifdef SIGRTMIN }else if(signal == SIGRTMIN){ @@ -122,43 +124,57 @@ void signal__flag_check(void) sub__tree_print(db.normal_subs, 0); sub__tree_print(db.shared_subs, 0); flag_tree_print = false; + } #ifdef WITH_XTREPORT + if(flag_xtreport){ xtreport(); -#endif + flag_xtreport = false; } +#endif } /* * * Signalling mosquitto process on Win32. * - * On Windows we we can use named events to pass signals to the mosquitto process. + * On Windows we can use named events to pass signals to the mosquitto process. * List of events : * * mosqPID_shutdown * mosqPID_reload * mosqPID_backup + * mosqPID_log_rotate + * mosqPID_tree_print + * mosqPID_xtreport * * (where PID is the PID of the mosquitto process). */ #ifdef WIN32 + +#define MOSQ_MAX_EVTS 6 DWORD WINAPI SigThreadProc(void* data) { TCHAR evt_name[MAX_PATH]; - static HANDLE evt[3]; + static HANDLE evt[MOSQ_MAX_EVTS]; int pid = GetCurrentProcessId(); + const char *evt_names[MOSQ_MAX_EVTS] = { + "shutdown", + "reload", + "backup", + "log_rotate", + "tree_print", + "xtreport" + } UNUSED(data); - sprintf_s(evt_name, MAX_PATH, "mosq%d_shutdown", pid); - evt[0] = CreateEvent(NULL, TRUE, FALSE, evt_name); - sprintf_s(evt_name, MAX_PATH, "mosq%d_reload", pid); - evt[1] = CreateEvent(NULL, FALSE, FALSE, evt_name); - sprintf_s(evt_name, MAX_PATH, "mosq%d_backup", pid); - evt[2] = CreateEvent(NULL, FALSE, FALSE, evt_name); + for(int i=0; i