Blame SOURCES/dhcp-handle_ctx_signals.patch

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