43 lines
1.1 KiB
C
43 lines
1.1 KiB
C
#include <signal.h> /* signal */
|
|
#include <stdio.h> /* fprintf */
|
|
#include <string.h> /* memset */
|
|
#include "libircclient.h"
|
|
#include "threads.h" /* F_* */
|
|
#include "strings.h"
|
|
extern irc_session_t *irc_session;
|
|
static void SignalHandler(int sig) {
|
|
char buf[512];
|
|
const char *s = string_signal_unknown_fmt;
|
|
#define CASE(x) case x: s = #x; break
|
|
switch (sig) {
|
|
CASE(SIGTERM);
|
|
CASE(SIGINT);
|
|
#ifndef _WIN32
|
|
CASE(SIGQUIT);
|
|
CASE(SIGKILL);
|
|
CASE(SIGHUP);
|
|
#endif
|
|
default:
|
|
break;
|
|
}
|
|
#undef CASE
|
|
memset(&buf, 0, sizeof buf);
|
|
snprintf(buf, (sizeof buf) - 1, string_signal_fmt, s);
|
|
fprintf(stderr, "%s", buf);
|
|
F_IRC_THREAD = STOPPED;
|
|
F_MAIN_THREAD = STOPPED;
|
|
F_SPAM_THREADS = STOPPED;
|
|
if (NULL != irc_session)
|
|
irc_cmd_quit(irc_session, buf);
|
|
/* TODO: clean exit */
|
|
}
|
|
void install_signal_handler(void) {
|
|
signal(SIGTERM, SignalHandler);
|
|
signal(SIGINT, SignalHandler);
|
|
#ifndef _WIN32
|
|
signal(SIGQUIT, SignalHandler);
|
|
signal(SIGKILL, SignalHandler);
|
|
signal(SIGHUP, SignalHandler);
|
|
#endif
|
|
}
|