diff options
Diffstat (limited to 'dwm.c')
| -rw-r--r-- | dwm.c | 56 |
1 files changed, 54 insertions, 2 deletions
@@ -236,6 +236,7 @@ static int xerrorstart(Display *dpy, XErrorEvent *ee); static void zoom(const Arg *arg); static void togglemouse(const Arg *arg); static void quicksearch(const Arg *arg); +static void autostart_exec(void); static pid_t getparentprocess(pid_t p); static int isdescprocess(pid_t p, pid_t c); @@ -277,6 +278,9 @@ static Window root, wmcheckwin; static xcb_connection_t *xcon; +static pid_t *autostart_pids; +static size_t autostart_len; + /* configuration, allows nested code to access above variables */ #include "config.h" @@ -1226,7 +1230,15 @@ void quit(const Arg *arg) { if(arg->i) restart = 1; - running = 0; + size_t i; + + for (i = 0; i < autostart_len; i++) { + if (0 < autostart_pids[i]) { + kill(autostart_pids[i], SIGTERM); + waitpid(autostart_pids[i], NULL, 0); + } + } + running = 0; } Monitor * @@ -1512,6 +1524,7 @@ setup(void) XSetWindowAttributes wa; Atom utf8string; struct sigaction sa; + pid_t pid; /* do not transform children into zombies when they terminate */ sigemptyset(&sa.sa_mask); @@ -1520,7 +1533,22 @@ setup(void) sigaction(SIGCHLD, &sa, NULL); /* clean up any zombies (inherited from .xinitrc etc) immediately */ - while (waitpid(-1, NULL, WNOHANG) > 0); + // while (waitpid(-1, NULL, WNOHANG) > 0); + while (0 < (pid = waitpid(-1, NULL, WNOHANG))) { + pid_t *p, *lim; + + if (!(p = autostart_pids)) + continue; + lim = &p[autostart_len]; + + for (; p < lim; p++) { + if (*p == pid) { + *p = -1; + break; + } + } + } + signal(SIGHUP, sighup); signal(SIGTERM, sigterm); @@ -2222,6 +2250,29 @@ zoom(const Arg *arg) XWarpPointer(dpy, None, selmon->sel->win, 0, 0, 0, 0, selmon->sel->w/2, selmon->sel->h/2); } +static void +autostart_exec() { + const char *const *p; + size_t i = 0; + + for (p = autostart; *p; autostart_len++, p++) + while (*++p); + + autostart_pids = malloc(autostart_len * sizeof(pid_t)); + + for (p = autostart; *p; i++, p++) { + if ((autostart_pids[i] = fork()) == 0) { + setsid(); + execvp(*p, (char *const *)p); + fprintf(stderr, "dwm: execvp %s\n", *p); + perror(" failed"); + _exit(EXIT_FAILURE); + } + + while (*++p); + } +} + int main(int argc, char *argv[]) { @@ -2236,6 +2287,7 @@ main(int argc, char *argv[]) if (!(xcon = XGetXCBConnection(dpy))) die("dwm: cannot get xcb connection\n"); checkotherwm(); + autostart_exec(); setup(); #ifdef __OpenBSD__ if (pledge("stdio rpath proc exec ps", NULL) == -1) |
