about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--dwm.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/dwm.c b/dwm.c
index b390294..f7b9477 100644
--- a/dwm.c
+++ b/dwm.c
@@ -182,7 +182,6 @@ static void setlayout(const Arg *arg);
 static void setmfact(const Arg *arg);
 static void setup(void);
 static void showhide(Client *c);
-static void sigchld(int signal);
 static void spawn(const Arg *arg);
 static void tag(const Arg *arg);
 static int textnw(const char *text, unsigned int len);
@@ -1392,24 +1391,22 @@ showhide(Client *c) {
 	}
 }
 
-
-void
-sigchld(int signal) {
-	while(0 < waitpid(-1, NULL, WNOHANG));
-}
-
 void
 spawn(const Arg *arg) {
-	signal(SIGCHLD, sigchld);
+	/* The double-fork construct avoids zombie processes and keeps the code
+	 * clean from stupid signal handlers. */
 	if(fork() == 0) {
-		if(dpy)
-			close(ConnectionNumber(dpy));
-		setsid();
-		execvp(((char **)arg->v)[0], (char **)arg->v);
-		fprintf(stderr, "dwm: execvp %s", ((char **)arg->v)[0]);
-		perror(" failed");
+		if(fork() == 0) {
+			if(dpy)
+				close(ConnectionNumber(dpy));
+			setsid();
+			execvp(((char **)arg->v)[0], (char **)arg->v);
+			fprintf(stderr, "dwm: execvp %s", ((char **)arg->v)[0]);
+			perror(" failed");
+		}
 		exit(0);
 	}
+	wait(0);
 }
 
 void
02'>102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183