mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 21:15:11 +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
53
src/Main.c
53
src/Main.c
|
|
@ -18,34 +18,6 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
Main(void)
|
||||
|
|
@ -54,7 +26,6 @@ Main(void)
|
|||
ParseeData *data = NULL;
|
||||
const ParseeConfig *parsee_conf;
|
||||
Stream *yaml;
|
||||
struct sigaction sigAction;
|
||||
|
||||
Log(LOG_INFO,
|
||||
"%s - v%s (Cytoplasm %s)",
|
||||
|
|
@ -111,29 +82,13 @@ Main(void)
|
|||
ParseeSendPresence(conf.handlerArgs);
|
||||
LogConfigUnindent(LogConfigGlobal());
|
||||
|
||||
sigAction.sa_handler = SignalHandler;
|
||||
sigfillset(&sigAction.sa_mask);
|
||||
sigAction.sa_flags = SA_RESTART;
|
||||
server = HttpServerCreate(&conf);
|
||||
|
||||
/* TODO: I stole that from Telodendria. Sorry, Jordan! */
|
||||
#define SIGACTION(sig, act, oact) \
|
||||
if (sigaction(sig, act, oact) < 0) \
|
||||
{ \
|
||||
Log(LOG_ERR, "Unable to install signal handler: %s", #sig); \
|
||||
goto end; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
Log(LOG_DEBUG, "Installed signal handler: %s", #sig); \
|
||||
if (!ParseeInitialiseSignals(server, xmpp_thr, jabber))
|
||||
{
|
||||
goto end;
|
||||
}
|
||||
|
||||
SIGACTION(SIGINT, &sigAction, NULL);
|
||||
SIGACTION(SIGTERM, &sigAction, NULL);
|
||||
SIGACTION(SIGPIPE, &sigAction, NULL);
|
||||
SIGACTION(SIGUSR1, &sigAction, NULL); /* Make USR1 do a softrestart */
|
||||
#undef SIGACTION
|
||||
|
||||
server = HttpServerCreate(&conf);
|
||||
HttpServerStart(server);
|
||||
LogConfigUnindent(LogConfigGlobal());
|
||||
Log(LOG_INFO, "=======================");
|
||||
|
|
|
|||
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;
|
||||
}
|
||||
|
|
@ -7,6 +7,8 @@
|
|||
#include <Cytoplasm/Stream.h>
|
||||
#include <Cytoplasm/Db.h>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include <XMPP.h>
|
||||
|
||||
typedef struct ParseeConfig {
|
||||
|
|
@ -147,4 +149,5 @@ extern bool ParseeVerifyStanza(ParseeData *, char *chat_id, char *stanza_id);
|
|||
/* Sends presence requests for every MUC around as a fake JID */
|
||||
extern void ParseeSendPresence(ParseeData *);
|
||||
|
||||
extern bool ParseeInitialiseSignals(HttpServer *, pthread_t, XMPPComponent *);
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue