summaryrefslogtreecommitdiff
path: root/src/biruda.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/biruda.c')
-rw-r--r--src/biruda.c28
1 files changed, 26 insertions, 2 deletions
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( );