ofproto: Inline trivial functions.
[sliver-openvswitch.git] / lib / fatal-signal.c
index 1e63d48..ef3fbc0 100644 (file)
@@ -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
 \f
 /* Files to delete on exit. */
 static struct sset files = SSET_INITIALIZER(&files);