mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 19:55:10 +00:00
[META] Actually start licensing
If anyone finds this to be bad, please let me know so that I can fix that out.
This commit is contained in:
parent
b820a441ed
commit
4de7227ee7
7 changed files with 896 additions and 50 deletions
74
src/Signal.c
Normal file
74
src/Signal.c
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
#include <Cytoplasm/HttpServer.h>
|
||||
#include <Cytoplasm/Log.h>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <XMPP.h>
|
||||
|
||||
static HttpServer *server = NULL;
|
||||
static pthread_t xmpp_thr;
|
||||
static XMPPComponent *jabber = NULL;
|
||||
|
||||
static void
|
||||
SignalHandler(int signal)
|
||||
{
|
||||
size_t i;
|
||||
XMLElement *message, *body, *data;
|
||||
char *from;
|
||||
|
||||
switch (signal)
|
||||
{
|
||||
case SIGPIPE:
|
||||
return;
|
||||
case SIGUSR1:
|
||||
/* TODO: Soft-restart everything */
|
||||
return;
|
||||
case SIGTERM:
|
||||
case SIGINT:
|
||||
if (!server)
|
||||
{
|
||||
return;
|
||||
}
|
||||
/* Create a loopback stanza, forcing the thread to die */
|
||||
Log(LOG_INFO, "Killing thread...");
|
||||
XMPPKillThread(jabber, "killer");
|
||||
pthread_join(xmpp_thr, NULL);
|
||||
HttpServerStop(server);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
ParseeInitialiseSignals(HttpServer *s, pthread_t xmpp, XMPPComponent *j)
|
||||
{
|
||||
struct sigaction sigAction;
|
||||
bool ret = true;
|
||||
|
||||
server = s;
|
||||
xmpp_thr = xmpp;
|
||||
jabber = j;
|
||||
|
||||
sigAction.sa_handler = SignalHandler;
|
||||
sigfillset(&sigAction.sa_mask);
|
||||
sigAction.sa_flags = SA_RESTART;
|
||||
|
||||
#define SIGACTION(sig, act, oact) \
|
||||
if (sigaction(sig, act, oact) < 0) \
|
||||
{ \
|
||||
Log(LOG_ERR, "Unable to install signal handler: %s", #sig); \
|
||||
ret = false; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
Log(LOG_DEBUG, "Installed signal handler: %s", #sig); \
|
||||
}
|
||||
|
||||
SIGACTION(SIGINT, &sigAction, NULL);
|
||||
SIGACTION(SIGTERM, &sigAction, NULL);
|
||||
SIGACTION(SIGPIPE, &sigAction, NULL);
|
||||
SIGACTION(SIGUSR1, &sigAction, NULL); /* Make USR1 do a softrestart */
|
||||
#undef SIGACTION
|
||||
|
||||
return ret;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue