Commit 6e845cf8 authored by Colomban Wendling's avatar Colomban Wendling
Browse files

Bot: handle SIGQUIT, SIGTERM and SIGINT

This change introduces a build system change that may require you to
re-run autogen.sh and configure.
parent 86e58010
......@@ -50,8 +50,16 @@ have -r autoconf
have -r autoheader
have -r autoreconf
mkdir -p build/aux || exit 1
mkdir -p build/m4 || exit 1
autoreconf -vfi || exit 1
# Try to find extra aclocal directories that may not be included by default,
# e.g. /usr/local/share/aclocal
AUTORECONF_FLAGS=
for d in /usr/share/aclocal \
/usr/local/share/aclocal; do
[ -d $d ] && AUTORECONF_FLAGS="$AUTORECONF_FLAGS -I $d"
done
mkdir -p build/aux || exit 1
mkdir -p build/m4 || exit 1
autoreconf -vfi $AUTORECONF_FLAGS || exit 1
#~ ./configure "$@"
......@@ -29,6 +29,9 @@ CFLAGS="${CFLAGS} ${OVCCBOT_CFLAGS} -Werror-implicit-function-declaration"
LIBS="${LIBS} ${OVCCBOT_LIBS}"
VALAFLAGS="--pkg glib-2.0 --pkg gio-2.0 --pkg ovcc --pkg ovccclient"
# check for posix
VALA_CHECK_PACKAGES([posix], [VALAFLAGS="$VALAFLAGS --pkg posix -D HAVE_POSIX"])
# get the correct VAPI directory for ovcc
AC_MSG_CHECKING([for OVCC VAPI dir])
ovcc_vapidir="$($PKG_CONFIG --variable prefix ovcc)/share/vala/vapi"
......
......@@ -122,11 +122,47 @@ public class Bot
}
}
#if HAVE_POSIX
private static void signal_handler (int sig)
{
debug ("Caught signal %d, exiting", sig);
try {
server.disconnect_from ();
} catch (Error e) {
warning ("Error disconnecting from server: %s", e.message);
}
loop.quit ();
Posix.exit (2);
}
private static void setup_signal_handlers ()
{
Posix.sigaction_t s = {};
s.sa_handler = signal_handler;
Posix.sigemptyset (s.sa_mask);
s.sa_flags = 0;
Posix.sigaction (Posix.SIGQUIT, s, null);
Posix.sigaction (Posix.SIGTERM, s, null);
Posix.sigaction (Posix.SIGINT, s, null);
}
#endif
MainLoop loop = null;
Bot bot = null;
OVCCClient.Server server = null;
public int main (string[] args)
{
var loop = new MainLoop ();
var bot = new Bot (loop);
var server = new OVCCClient.Server ("localhost", 0xdead);
loop = new MainLoop ();
bot = new Bot (loop);
server = new OVCCClient.Server ("localhost", 0xdead);
#if HAVE_POSIX
setup_signal_handlers ();
#endif
try {
bot.join (server);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment