changeset 28085:c0d1bf1b26b7

chg: verify return value of sigaction() and sigemptyset() They should never fail, but it couldn't hurt to be a paranoid.
author Yuya Nishihara <yuya@tcha.org>
date Fri, 29 Jan 2016 22:52:16 +0900
parents 3fc45956c978
children 65d24ca35496
files contrib/chg/chg.c
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/chg/chg.c	Fri Jan 29 22:42:22 2016 +0900
+++ b/contrib/chg/chg.c	Fri Jan 29 22:52:16 2016 +0900
@@ -241,14 +241,22 @@
 	memset(&sa, 0, sizeof(sa));
 	sa.sa_handler = forwardsignal;
 	sa.sa_flags = SA_RESTART;
-	sigemptyset(&sa.sa_mask);
+	if (sigemptyset(&sa.sa_mask) < 0)
+		goto error;
 
-	sigaction(SIGHUP, &sa, NULL);
-	sigaction(SIGINT, &sa, NULL);
+	if (sigaction(SIGHUP, &sa, NULL) < 0)
+		goto error;
+	if (sigaction(SIGINT, &sa, NULL) < 0)
+		goto error;
 
 	/* terminate frontend by double SIGTERM in case of server freeze */
 	sa.sa_flags |= SA_RESETHAND;
-	sigaction(SIGTERM, &sa, NULL);
+	if (sigaction(SIGTERM, &sa, NULL) < 0)
+		goto error;
+	return;
+
+error:
+	abortmsg("failed to set up signal handlers (errno = %d)", errno);
 }
 
 /* This implementation is based on hgext/pager.py (pre 369741ef7253) */