diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2014-09-17 11:40:55 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2014-09-17 11:40:55 +0200 |
commit | 6a996a2fcb97578a60142d5c9c36b867d24b7c56 (patch) | |
tree | 9277568ccbfc050845737dde7b0ff4736b8375e3 /src/biruda.c | |
parent | d693ea09b1cd42eb277fd69161f064aeee524080 (diff) | |
download | biruda-6a996a2fcb97578a60142d5c9c36b867d24b7c56.tar.gz biruda-6a996a2fcb97578a60142d5c9c36b867d24b7c56.tar.bz2 |
termination in foreground on Windows
Diffstat (limited to 'src/biruda.c')
-rw-r--r-- | src/biruda.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/biruda.c b/src/biruda.c index d95530e..aefc5c9 100644 --- a/src/biruda.c +++ b/src/biruda.c @@ -1,7 +1,10 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#ifndef _WIN32 +#ifdef _WIN32 +#define WIN32_MEAN_AND_LEAN +#include <windows.h> +#else #include <errno.h> #include <unistd.h> #include <signal.h> @@ -149,10 +152,27 @@ static int create_coordinator( cfg_t *cfg ) static volatile int got_terminate = 0; +#ifdef _WIN32 +BOOL WINAPI terminate_foreground_func( DWORD ctrlType ) +{ + switch( ctrlType ) { + case CTRL_C_EVENT: + case CTRL_BREAK_EVENT: + case CTRL_CLOSE_EVENT: + case CTRL_LOGOFF_EVENT: + case CTRL_SHUTDOWN_EVENT: + got_terminate = 1; + return TRUE; + default: + return FALSE; + } +} +#else static void terminate_foreground_func( int sig ) { got_terminate = 1; } +#endif int main( int argc, char *argv[] ) { @@ -205,6 +225,7 @@ int main( int argc, char *argv[] ) if( args_info.foreground_given ) { #ifdef _WIN32 + SetConsoleCtrlHandler( terminate_foreground_func, TRUE ); #else struct sigaction sa; @@ -214,11 +235,11 @@ int main( int argc, char *argv[] ) (void)sigaction( SIGINT, &sa, NULL ); (void)sigaction( SIGTERM, &sa, NULL ); +#endif while( !got_terminate ) { sleep( 1 ); } -#endif } if( has_coordinator ) { |