Patchwork [2,of,3] chg: verify return value of sigaction() and sigemptyset()

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 11, 2016, 2:05 p.m.
Message ID <def82508e22c33bdfe04.1455199512@mimosa>
Download mbox | patch
Permalink /patch/13113/
State Accepted
Headers show

Comments

Yuya Nishihara - Feb. 11, 2016, 2:05 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1454075536 -32400
#      Fri Jan 29 22:52:16 2016 +0900
# Node ID def82508e22c33bdfe042fd372bddf6dc3f93e2c
# Parent  8384b91109172edce0dd3fd89825890f5f977b78
chg: verify return value of sigaction() and sigemptyset()

They should never fail, but it couldn't hurt to be a paranoid.

Patch

diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
--- a/contrib/chg/chg.c
+++ b/contrib/chg/chg.c
@@ -241,14 +241,22 @@  static void setupsignalhandler(pid_t pid
 	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) */