diff --git a/src/event.c b/src/event.c index e1e0989..c391521 100644 --- a/src/event.c +++ b/src/event.c @@ -695,7 +695,5 @@ getevent(XEvent ev) break; } - wait((int[]){0}); - return; } diff --git a/src/init.c b/src/init.c index 21b01e0..2e8e168 100644 --- a/src/init.c +++ b/src/init.c @@ -55,12 +55,24 @@ const func_name_list_t layout_list[] = { NULL, NULL } }; +static void sigchld(int); + +static void +sigchld(int sig) +{ + (void)sig; + if (signal(SIGCHLD, sigchld) == SIG_ERR) + warn("signal(SIGCHLD)"); + while (waitpid(-1, NULL, WNOHANG) > 0); +} + /** Init WMFS */ void init(void) { /* First init */ + sigchld(0); ewmh_init_hints(); init_conf(); init_gc(); diff --git a/src/util.c b/src/util.c index f3147c1..7cd4edc 100644 --- a/src/util.c +++ b/src/util.c @@ -30,6 +30,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include "wmfs.h" /** malloc with error support and size_t overflow protection @@ -252,15 +253,14 @@ alias_to_str(char *conf_choice) * \param cmd Command * \return child pid */ -int +pid_t spawn(const char *format, ...) { char *sh = NULL; char cmd[512]; va_list ap; - pid_t pid, ret; - int p[2]; size_t len; + pid_t pid; va_start(ap, format); len = vsnprintf(cmd, sizeof(cmd), format, ap); @@ -275,48 +275,18 @@ spawn(const char *format, ...) if(!(sh = getenv("SHELL"))) sh = "/bin/sh"; - if (pipe(p) == -1) - { - warn("pipe"); - return -1; - } - if((pid = fork()) == 0) { - close(p[0]); - if((pid = fork()) == 0) - { - if(dpy) - close(ConnectionNumber(dpy)); - setsid(); - execl(sh, sh, "-c", cmd, (char*)NULL); - exit(EXIT_FAILURE); - } - - if (sizeof(pid_t) != write(p[1], &pid, sizeof(pid_t))) - warn("write"); - - close(p[1]); - exit(EXIT_SUCCESS); - } - else if (pid != -1) - { - close(p[1]); - if (sizeof(pid_t) != read(p[0], &ret, sizeof(pid_t))) - { - warn("read"); - ret = -1; - } - close(p[0]); - waitpid(pid, NULL, 0); - } - else - { - warn("fork"); - ret = -1; + if(dpy) + close(ConnectionNumber(dpy)); + setsid(); + execl(sh, sh, "-c", cmd, (char*)NULL); + err(1, "execl(%s)", cmd); } + if (pid == -1) + warn("fork()"); - return ret; + return pid; } /** Swap two pointer. diff --git a/src/wmfs.c b/src/wmfs.c index 0a6c8b6..bb65499 100644 --- a/src/wmfs.c +++ b/src/wmfs.c @@ -134,7 +134,7 @@ quit(void) /* kill status script */ if (conf.status_pid != (pid_t)-1) - kill(conf.status_pid, SIGQUIT); + kill(conf.status_pid, SIGTERM); return; } diff --git a/src/wmfs.h b/src/wmfs.h index 48f325c..ebe5e35 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -309,7 +309,7 @@ Layout layout_name_to_struct(Layout lt[], char *name, int n, const func_name_lis char* alias_to_str(char *conf_choice); /* }}} */ char *char_to_str(const char c); -int spawn(const char *str, ...); +pid_t spawn(const char *str, ...); void swap_ptr(void **x, void **y); void uicb_spawn(uicb_t); char *clean_value(char *str);