cvs commit: src/sbin/natd Makefile natd.c

Sepherosa Ziehau sepherosa at gmail.com
Wed Jun 1 22:37:15 PDT 2005


On 6/2/05, Joerg Sonnenberger <joerg at xxxxxxxxxxxxxxxxx> wrote:
> On Wed, Jun 01, 2005 at 11:37:21AM -0700, Sascha Wildner wrote:
> >   * Add __unused where necessary.
> 
> Can you fix the signal handlers at the same time to only touch
> volatile sig_atomic_t variables and call safe system calls (not
> sure about whether the latter is done).

I think `safe' means async-signal safe.
Attached patch achieves them(safe syscall, sig_atomic_t)

> 
> Joerg
> 


-- 
Live Free or Die
Index: natd.c
===================================================================
RCS file: /opt/df_cvs/src/sbin/natd/natd.c,v
retrieving revision 1.7
diff -u -p -r1.7 natd.c
--- natd.c	1 Jun 2005 18:37:20 -0000	1.7
+++ natd.c	2 Jun 2005 05:30:22 -0000
@@ -105,8 +105,8 @@ static void	SetupPunchFW(const char *str
 
 static	int			verbose;
 static 	int			background;
-static	int			running;
-static	int			assignAliasAddr;
+static	volatile sig_atomic_t	running;
+static	volatile sig_atomic_t	assignAliasAddr;
 static	char*			ifName;
 static  int			ifIndex;
 static	u_short			inPort;
@@ -131,6 +131,7 @@ int main (int argc, char** argv)
 	struct sockaddr_in	addr;
 	fd_set			readMask;
 	int			fdMax;
+	struct sigaction	sa;
 /* 
  * Initialize packet aliasing software.
  * Done already here to be able to alter option bits
@@ -289,10 +290,13 @@ int main (int argc, char** argv)
  * Catch signals to manage shutdown and
  * refresh of interface address.
  */
-	siginterrupt(SIGTERM, 1);
-	siginterrupt(SIGHUP, 1);
-	signal (SIGTERM, InitiateShutdown);
-	signal (SIGHUP, RefreshAddr);
+	memset(&sa, 0, sizeof(sa));
+	sigemptyset(&sa.sa_mask);
+
+	sa.sa_handler = InitiateShutdown;
+	sigaction(SIGTERM, &sa, NULL);
+	sa.sa_handler = RefreshAddr;
+	sigaction(SIGHUP, &sa, NULL);
 /*
  * Set alias address if it has been given.
  */
@@ -795,14 +799,18 @@ static void RefreshAddr (int sig __unuse
 
 static void InitiateShutdown (int sig __unused)
 {
+	struct sigaction sa;
 /*
  * Start timer to allow kernel gracefully
  * shutdown existing connections when system
  * is shut down.
  */
-	siginterrupt(SIGALRM, 1);
-	signal (SIGALRM, Shutdown);
-	alarm (10);
+	memset(&sa, 0, sizeof(sa));
+	sigemptyset(&sa.sa_mask);
+
+	sa.sa_handler = Shutdown;
+	sigaction(SIGALRM, &sa, NULL);
+	alarm(10);
 }
 
 static void Shutdown (int sig __unused)




More information about the Submit mailing list