Patchwork [1,of,3] chg: initialize sigaction fields more reliably

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

Comments

Yuya Nishihara - Feb. 11, 2016, 2:05 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1454074942 -32400
#      Fri Jan 29 22:42:22 2016 +0900
# Node ID 8384b91109172edce0dd3fd89825890f5f977b78
# Parent  b3d16471a2465c181313cd05cba0c3e04b5fe316
chg: initialize sigaction fields more reliably

It seems calling memset() and sigemptyset() is common pattern to initialize
sigaction. And strictly speaking, sigset_t must be initialized by sigemptyset()
or sigfillset(). I saw git and uwsgi do that way, so let's follow them.

Patch

diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
--- a/contrib/chg/chg.c
+++ b/contrib/chg/chg.c
@@ -241,6 +241,7 @@  static void setupsignalhandler(pid_t pid
 	memset(&sa, 0, sizeof(sa));
 	sa.sa_handler = forwardsignal;
 	sa.sa_flags = SA_RESTART;
+	sigemptyset(&sa.sa_mask);
 
 	sigaction(SIGHUP, &sa, NULL);
 	sigaction(SIGINT, &sa, NULL);
diff --git a/contrib/chg/util.c b/contrib/chg/util.c
--- a/contrib/chg/util.c
+++ b/contrib/chg/util.c
@@ -11,6 +11,7 @@ 
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
@@ -63,6 +64,7 @@  int runshellcmd(const char *cmd, const c
 	sigset_t oldmask;
 
 	/* block or mask signals just as system() does */
+	memset(&newsa, 0, sizeof(newsa));
 	newsa.sa_handler = SIG_IGN;
 	newsa.sa_flags = 0;
 	if (sigemptyset(&newsa.sa_mask) < 0)