#include #include #include #include #include static ParseeData *data; static pthread_t xmpp_thr; static void SignalHandler(int signal) { if (data->server && (signal == SIGTERM || signal == SIGINT)) { Log(LOG_INFO, "Killing thread..."); pthread_mutex_lock(&data->halt_lock); data->halted = true; pthread_mutex_unlock(&data->halt_lock); XMPPFinishCompStream(data->jabber); pthread_join(xmpp_thr, NULL); Log(LOG_INFO, "Stopping server..."); HttpServerStop(data->server); return; } } bool ParseeInitialiseSignals(ParseeData *d, pthread_t xmpp) { struct sigaction sa; data = d; xmpp_thr = xmpp; sigfillset(&sa.sa_mask); sa.sa_handler = SignalHandler; sa.sa_flags = SA_RESTART; #define Register(act) (sigaction(act, &sa, NULL) >= 0) if (!Register(SIGTERM) || !Register(SIGINT)) { Log(LOG_ERR, "Couldn't register signals..."); return false; } #undef Register return true; }