diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2014-09-17 11:32:29 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2014-09-17 11:32:29 +0200 |
commit | d693ea09b1cd42eb277fd69161f064aeee524080 (patch) | |
tree | 7382c8588efc77ded40a44902d4924f4945c4ddf | |
parent | b6846e94d613f2fedb5f26fd2595b328ca96137b (diff) | |
download | biruda-d693ea09b1cd42eb277fd69161f064aeee524080.tar.gz biruda-d693ea09b1cd42eb277fd69161f064aeee524080.tar.bz2 |
termination in foreground on Unix instead of sleep
-rw-r--r-- | INSTALL | 14 | ||||
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | src/biruda.c | 28 |
3 files changed, 42 insertions, 2 deletions
@@ -1,3 +1,17 @@ +Building on Linux +----------------- + +Archlinux +--------- + +Install the following packages from the official repos or build them +from the AUR: + * gengetopt + * confuse + * nanomsg + * json-c + * libdaemon + Building on Windows ------------------- @@ -29,6 +29,8 @@ Requirements http://sourceware.org/pthreads-win32/ * json-c: JSON for message payload https://github.com/json-c/json-c/wiki +* libdaemon: for daemonizing support on Unix + Other projects -------------- diff --git a/src/biruda.c b/src/biruda.c index 6511812..d95530e 100644 --- a/src/biruda.c +++ b/src/biruda.c @@ -4,6 +4,7 @@ #ifndef _WIN32 #include <errno.h> #include <unistd.h> +#include <signal.h> #endif #include "biruda_cmdline.h" @@ -146,6 +147,13 @@ static int create_coordinator( cfg_t *cfg ) return coordinator_init( control ); } +static volatile int got_terminate = 0; + +static void terminate_foreground_func( int sig ) +{ + got_terminate = 1; +} + int main( int argc, char *argv[] ) { struct gengetopt_args_info args_info; @@ -194,8 +202,24 @@ int main( int argc, char *argv[] ) exit( EXIT_FAILURE ); } } - - sleep( 10 ); + + if( args_info.foreground_given ) { +#ifdef _WIN32 +#else + struct sigaction sa; + + memset( &sa, 0, sizeof( struct sigaction ) ); + sa.sa_handler = terminate_foreground_func; + sa.sa_flags = SA_RESTART; + + (void)sigaction( SIGINT, &sa, NULL ); + (void)sigaction( SIGTERM, &sa, NULL ); + + while( !got_terminate ) { + sleep( 1 ); + } +#endif + } if( has_coordinator ) { coordinator_terminate( ); |