reverted spawn
e7572804
1 file(s) · +11 −14
| 182 | 182 | static void setmfact(const Arg *arg); |
|
| 183 | 183 | static void setup(void); |
|
| 184 | 184 | static void showhide(Client *c); |
|
| 185 | - | static void sigchld(int signal); |
|
| 186 | 185 | static void spawn(const Arg *arg); |
|
| 187 | 186 | static void tag(const Arg *arg); |
|
| 188 | 187 | static int textnw(const char *text, unsigned int len); |
|
| 1392 | 1391 | } |
|
| 1393 | 1392 | } |
|
| 1394 | 1393 | ||
| 1395 | - | ||
| 1396 | - | void |
|
| 1397 | - | sigchld(int signal) { |
|
| 1398 | - | while(0 < waitpid(-1, NULL, WNOHANG)); |
|
| 1399 | - | } |
|
| 1400 | - | ||
| 1401 | 1394 | void |
|
| 1402 | 1395 | spawn(const Arg *arg) { |
|
| 1403 | - | signal(SIGCHLD, sigchld); |
|
| 1396 | + | /* The double-fork construct avoids zombie processes and keeps the code |
|
| 1397 | + | * clean from stupid signal handlers. */ |
|
| 1404 | 1398 | if(fork() == 0) { |
|
| 1405 | - | if(dpy) |
|
| 1406 | - | close(ConnectionNumber(dpy)); |
|
| 1407 | - | setsid(); |
|
| 1408 | - | execvp(((char **)arg->v)[0], (char **)arg->v); |
|
| 1409 | - | fprintf(stderr, "dwm: execvp %s", ((char **)arg->v)[0]); |
|
| 1410 | - | perror(" failed"); |
|
| 1399 | + | if(fork() == 0) { |
|
| 1400 | + | if(dpy) |
|
| 1401 | + | close(ConnectionNumber(dpy)); |
|
| 1402 | + | setsid(); |
|
| 1403 | + | execvp(((char **)arg->v)[0], (char **)arg->v); |
|
| 1404 | + | fprintf(stderr, "dwm: execvp %s", ((char **)arg->v)[0]); |
|
| 1405 | + | perror(" failed"); |
|
| 1406 | + | } |
|
| 1411 | 1407 | exit(0); |
|
| 1412 | 1408 | } |
|
| 1409 | + | wait(0); |
|
| 1413 | 1410 | } |
|
| 1414 | 1411 | ||
| 1415 | 1412 | void |
|