$OpenBSD: patch-src_daemon_priv_c,v 1.1 2013/07/15 21:35:46 sthen Exp $

From 5c4fa9bdc202c7f474cb50f77a79acbea2abd009 Mon Sep 17 00:00:00 2001
From: Vincent Bernat <vincent.bernat@dailymotion.com>
Date: Mon, 15 Jul 2013 15:28:46 +0200
Subject: [PATCH] priv: use `sigaction()` instead of `signal()` to install
 non-default signals

`signal()` is not portable to install non-default signals.
---
 src/daemon/priv.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

--- src/daemon/priv.c.orig	Thu Jul 11 22:13:52 2013
+++ src/daemon/priv.c	Mon Jul 15 22:32:23 2013
@@ -490,12 +490,22 @@ priv_init(const char *chrootdir, int ctl, uid_t uid, g
 		if (atexit(priv_exit) != 0)
 			fatal("privsep", "unable to set exit function");
 
-		signal(SIGALRM, sig_pass_to_chld);
-		signal(SIGTERM, sig_pass_to_chld);
-		signal(SIGHUP, sig_pass_to_chld);
-		signal(SIGINT, sig_pass_to_chld);
-		signal(SIGQUIT, sig_pass_to_chld);
-		signal(SIGCHLD, sig_chld);
+		/* Install signal handlers */
+		const struct sigaction pass_to_child = {
+			.sa_handler = sig_pass_to_chld,
+			.sa_flags = SA_RESTART
+		};
+		sigaction(SIGALRM, &pass_to_child, NULL);
+		sigaction(SIGTERM, &pass_to_child, NULL);
+		sigaction(SIGHUP,  &pass_to_child, NULL);
+		sigaction(SIGINT,  &pass_to_child, NULL);
+		sigaction(SIGQUIT, &pass_to_child, NULL);
+		const struct sigaction child = {
+			.sa_handler = sig_chld,
+			.sa_flags = SA_RESTART
+		};
+		sigaction(SIGCHLD, &child, NULL);
+
                 if (waitpid(monitored, &status, WNOHANG) != 0)
                         /* Child is already dead */
                         _exit(1);
