X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Ffatal-signal.c;h=ef3fbc047127b72005176c97db88b245353a7b5c;hb=c5cf10598f8c9f4428291e9df3ecd72a05fb1ccf;hp=1e63d48d6360cd35529740dbc02c891d94705838;hpb=84a6cbae3684abe57733ea8e297eb5c63358908a;p=sliver-openvswitch.git diff --git a/lib/fatal-signal.c b/lib/fatal-signal.c index 1e63d48d6..ef3fbc047 100644 --- a/lib/fatal-signal.c +++ b/lib/fatal-signal.c @@ -59,13 +59,16 @@ static struct hook hooks[MAX_HOOKS]; static size_t n_hooks; static int signal_fds[2]; -HANDLE wevent; +static HANDLE wevent; static volatile sig_atomic_t stored_sig_nr = SIG_ATOMIC_MAX; static struct ovs_mutex mutex; static void atexit_handler(void); static void call_hooks(int sig_nr); +#ifdef _WIN32 +static BOOL WINAPI ConsoleHandlerRoutine(DWORD dwCtrlType); +#endif /* Initializes the fatal signal handling module. Calling this function is * optional, because calling any other function in the module will also @@ -91,6 +94,9 @@ fatal_signal_init(void) char *msg_buf = ovs_lasterror_to_string(); VLOG_FATAL("Failed to create a event (%s).", msg_buf); } + + /* Register a function to handle Ctrl+C. */ + SetConsoleCtrlHandler(ConsoleHandlerRoutine, true); #endif for (i = 0; i < ARRAY_SIZE(fatal_signals); i++) { @@ -212,6 +218,14 @@ fatal_signal_wait(void) poll_fd_wait_event(signal_fds[0], wevent, POLLIN); } +void +fatal_ignore_sigpipe(void) +{ +#ifndef _WIN32 + signal(SIGPIPE, SIG_IGN); +#endif +} + static void atexit_handler(void) { @@ -235,6 +249,15 @@ call_hooks(int sig_nr) } } } + +#ifdef _WIN32 +BOOL WINAPI ConsoleHandlerRoutine(DWORD dwCtrlType) +{ + stored_sig_nr = SIGINT; + SetEvent(wevent); + return true; +} +#endif /* Files to delete on exit. */ static struct sset files = SSET_INITIALIZER(&files);