philipp / rpms / dhcp

Forked from rpms/dhcp 4 years ago
Clone
Blob Blame History Raw
diff --git a/omapip/isclib.c b/omapip/isclib.c
index b3d336d..b252fb6 100644
--- a/omapip/isclib.c
+++ b/omapip/isclib.c
@@ -28,6 +28,7 @@
 #include "dhcpd.h"
 
 #include <sys/time.h>
+#include <signal.h>
 
 dhcp_context_t dhcp_gbl_ctx;
 
@@ -67,6 +67,21 @@ isclib_cleanup(void)
 	return;
 }
 
+/* Installs a handler for a signal using sigaction */
+static void
+handle_signal(int sig, void (*handler)(int)) {
+	struct sigaction sa;
+
+	memset(&sa, 0, sizeof(sa));
+	sa.sa_handler = handler;
+	sigfillset(&sa.sa_mask);
+	if (sigaction(sig, &sa, NULL) != 0) {
+		log_debug("handle_signal() failed for signal %d error: %s",
+                          sig, strerror(errno));
+	}
+}
+
+
 isc_result_t
 dhcp_context_create(void) {
 	isc_result_t result;
@@ -102,11 +117,6 @@ dhcp_context_create(void) {
 	if (result != ISC_R_SUCCESS)
 		goto cleanup;
 
-	result = isc_app_ctxstart(dhcp_gbl_ctx.actx);
-	if (result != ISC_R_SUCCESS)
-		return (result);
-	dhcp_gbl_ctx.actx_started = ISC_TRUE;
-
 	result = isc_taskmgr_createinctx(dhcp_gbl_ctx.mctx,
 					 dhcp_gbl_ctx.actx,
 					 1, 0,
@@ -130,6 +140,21 @@ dhcp_context_create(void) {
 	if (result != ISC_R_SUCCESS)
 		goto cleanup;
 
+        result = isc_app_ctxstart(dhcp_gbl_ctx.actx);
+        if (result != ISC_R_SUCCESS)
+          return (result);
+        dhcp_gbl_ctx.actx_started = ISC_TRUE;
+
+        /* Not all OSs support suppressing SIGPIPE through socket
+         * options, so set the sigal action to be ignore.  This allows
+         * broken connections to fail gracefully with EPIPE on writes */
+        handle_signal(SIGPIPE, SIG_IGN);
+
+        /* Reset handlers installed by isc_app_ctxstart()
+         * to default for control-c and kill */
+        handle_signal(SIGINT, SIG_DFL);
+        handle_signal(SIGTERM, SIG_DFL);
+        
 #if !defined (NSUPDATE)
 	/* The dst library is inited as part of dns_lib_init, we don't
 	 * need it if NSUPDATE is enabled */