[dwm] [dvtm] [PATCH 1/2] Correct signal handling

From: Rainer Müller <raimue_AT_codingfarm.de>
Date: Wed, 30 Apr 2008 00:06:23 +0200

The global errno variable needs to be saved at the begin of a signal handler
and to be restored at the end.

Signed-off-by: Rainer Müller <raimue_AT_codingfarm.de>

---
 dvtm.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/dvtm.c b/dvtm.c
index 6c85746..17ac4a4 100644
--- a/dvtm.c
+++ b/dvtm.c
@@ -760,15 +760,21 @@ get_client_by_pid(pid_t pid){
 
 void
 sigchld_handler(int sig){
+	int errsv = errno;
+
 	int child_status;
 	signal(SIGCHLD, sigchld_handler);
 	pid_t pid = wait(&child_status);
 	debug("child with pid %d died\n", pid);
 	client_killed = get_client_by_pid(pid);
+
+	errno = errsv;
 }
 
 void
 sigwinch_handler(int sig){
+	int errsv = errno;
+
 	struct winsize ws;
 	signal(SIGWINCH, sigwinch_handler);
 	if(ioctl(0, TIOCGWINSZ, &ws) == -1)
@@ -777,11 +783,15 @@ sigwinch_handler(int sig){
 	width = ws.ws_col;
 	height = ws.ws_row;
 	need_screen_resize = true;
+
+	errno = errsv;
 }
 
 void
 sigterm_handler(int sig){
+	int errsv = errno;
 	running = false;
+	errno = errsv;
 }
 
 void
-- 
1.5.5.1
Received on Wed Apr 30 2008 - 00:11:15 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:36:40 UTC