summary refs log tree commit diff
path: root/calmwm.c
diff options
context:
space:
mode:
authorokan <okan>2014-09-06 16:24:32 +0000
committerokan <okan>2014-09-06 16:24:32 +0000
commit977992626a092487f4d5df364729693ad2be0131 (patch)
tree29115ad8bc0fa124cbcddc2fa12d90d7e8ede83f /calmwm.c
parent140f8b9eba06dfd416ae1503130da374867dd8d8 (diff)
downloadcwm-977992626a092487f4d5df364729693ad2be0131.tar.gz
cwm-977992626a092487f4d5df364729693ad2be0131.tar.xz
cwm-977992626a092487f4d5df364729693ad2be0131.zip
generic sighandler
Diffstat (limited to 'calmwm.c')
-rw-r--r--calmwm.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/calmwm.c b/calmwm.c
index 3656b48..90844a5 100644
--- a/calmwm.c
+++ b/calmwm.c
@@ -48,7 +48,7 @@ struct conf			 Conf;
 const char			*homedir;
 volatile sig_atomic_t		 cwm_status;
 
-static void	sigchld_cb(int);
+static void	sighdlr(int);
 static int	x_errorhandler(Display *, XErrorEvent *);
 static void	x_init(const char *);
 static void	x_restart(char **);
@@ -84,7 +84,7 @@ main(int argc, char **argv)
 	argc -= optind;
 	argv += optind;
 
-	if (signal(SIGCHLD, sigchld_cb) == SIG_ERR)
+	if (signal(SIGCHLD, sighdlr) == SIG_ERR)
 		err(1, "signal");
 
 	if ((homedir = getenv("HOME")) == NULL || *homedir == '\0') {
@@ -205,16 +205,19 @@ x_errorhandler(Display *dpy, XErrorEvent *e)
 }
 
 static void
-sigchld_cb(int which)
+sighdlr(int sig)
 {
 	pid_t	 pid;
-	int	 save_errno = errno;
-	int	 status;
-
-	/* Collect dead children. */
-	while ((pid = waitpid(-1, &status, WNOHANG)) > 0 ||
-	    (pid < 0 && errno == EINTR))
-		;
+	int	 save_errno = errno, status;
+
+	switch (sig) {
+	case SIGCHLD:
+		/* Collect dead children. */
+		while ((pid = waitpid(WAIT_ANY, &status, WNOHANG)) > 0 ||
+		    (pid < 0 && errno == EINTR))
+			;
+		break;
+	}
 
 	errno = save_errno;
 }