[FIX] Kill Parsee on unexcepted stream closure

This commit is contained in:
LDA 2024-10-20 12:53:07 +02:00
commit 02a89270c0
6 changed files with 49 additions and 15 deletions

View file

@ -6,39 +6,40 @@
#include <XMPP.h>
static HttpServer *server = NULL;
static ParseeData *data;
static pthread_t xmpp_thr;
static XMPPComponent *jabber = NULL;
static void
SignalHandler(int signal)
{
if (server && (signal == SIGTERM || signal == SIGINT))
if (data->server && (signal == SIGTERM || signal == SIGINT))
{
Log(LOG_INFO, "Killing thread...");
XMPPFinishCompStream(jabber);
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(server);
HttpServerStop(data->server);
return;
}
if (signal == SIGPIPE)
{
Log(LOG_DEBUG, "Caught a SIGPIPE...");
XMPPFinishCompStream(jabber);
pthread_join(xmpp_thr, NULL);
return;
}
}
bool
ParseeInitialiseSignals(HttpServer *s, pthread_t xmpp, XMPPComponent *j)
ParseeInitialiseSignals(ParseeData *d, pthread_t xmpp)
{
struct sigaction sa;
server = s;
data = d;
xmpp_thr = xmpp;
jabber = j;
sigfillset(&sa.sa_mask);
sa.sa_handler = SignalHandler;