chg: verify return value of sigaction() and sigemptyset()
authorYuya Nishihara <yuya@tcha.org>
Fri, 29 Jan 2016 22:52:16 +0900
changeset 28085 c0d1bf1b26b7
parent 28084 3fc45956c978
child 28086 65d24ca35496
chg: verify return value of sigaction() and sigemptyset() They should never fail, but it couldn't hurt to be a paranoid.
contrib/chg/chg.c
--- 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) */