From acc66f62ab6fc780644e193c6b8265269d30c970 Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Wed, 1 Feb 2012 14:13:19 +0100 Subject: [PATCH] Fix SIGCHLD signal handling, remove fifo from master --- Makefile.in | 1 - src/client.c | 2 +- src/event.c | 13 +++++---- src/fifo.c | 75 ---------------------------------------------------- src/screen.c | 18 +++++-------- src/wmfs.c | 52 +++++++++++------------------------- src/wmfs.h | 8 +----- 7 files changed, 30 insertions(+), 139 deletions(-) delete mode 100644 src/fifo.c diff --git a/Makefile.in b/Makefile.in index 59e41b9..c89a906 100644 --- a/Makefile.in +++ b/Makefile.in @@ -17,7 +17,6 @@ SRCS= \ src/screen.c \ src/tag.c \ src/util.c \ - src/fifo.c \ src/status.c \ src/systray.c \ src/mouse.c \ diff --git a/src/client.c b/src/client.c index 5d2c3bc..745ddd3 100644 --- a/src/client.c +++ b/src/client.c @@ -133,7 +133,7 @@ client_gb_frame(Window w) struct client* client_gb_pos(struct tag *t, int x, int y) { - struct client *c = SLIST_FIRST(&t->clients); + struct client *c; FOREACH_NFCLIENT(c, &t->clients, tnext) if(INAREA(x, y, c->geo)) diff --git a/src/event.c b/src/event.c index 39e03ea..3676945 100644 --- a/src/event.c +++ b/src/event.c @@ -16,10 +16,10 @@ #define EVDPY(e) (e)->xany.display -#define MOUSE_CHECK_BIND(m) \ - if(m->button == ev->button) \ - if(!m->use_area || (m->use_area && INAREA(ev->x, ev->y, m->area))) \ - if(m->func) \ +#define MOUSE_DO_BIND(m) \ + if(m->button == ev->button) \ + if(!m->use_area || (m->use_area && INAREA(ev->x, ev->y, m->area))) \ + if(m->func) \ m->func(m->cmd); static void event_buttonpress(XEvent *e) @@ -36,10 +36,10 @@ event_buttonpress(XEvent *e) W->last_clicked_barwin = b; SLIST_FOREACH(m, &b->mousebinds, next) - MOUSE_CHECK_BIND(m); + MOUSE_DO_BIND(m); SLIST_FOREACH(m, &b->statusmousebinds, next) - MOUSE_CHECK_BIND(m); + MOUSE_DO_BIND(m); break; } @@ -98,7 +98,6 @@ event_clientmessageevent(XEvent *e) if((sy = systray_find(ev->data.l[2]))) ewmh_send_message(sy->win, sy->win, "_XEMBED", XEMBED_FOCUS_IN, XEMBED_FOCUS_CURRENT, 0, 0, 0); - } } else if(ev->window == W->root) diff --git a/src/fifo.c b/src/fifo.c deleted file mode 100644 index 87416c3..0000000 --- a/src/fifo.c +++ /dev/null @@ -1,75 +0,0 @@ -/* - * wmfs2 by Martin Duquesnoy { for(i = 2011; i < 2111; ++i) ©(i); } - * File created by David Delassus. - * For license, see COPYING. - */ - -#include /* access */ - -#include "wmfs.h" -#include "util.h" -#include "config.h" -#include "fifo.h" - -#define READ_SIZE (32768) - -static void -fifo_open(void) -{ - if(W->fifo.fd) - close(W->fifo.fd); - - if(!(W->fifo.fd = open(W->fifo.path, O_RDONLY | O_NDELAY, 0))) - warnxl("Can't open FIFO: %s\n", strerror(errno)); -} - -void -fifo_init(void) -{ - xasprintf(&(W->fifo.path), "%s/wmfs-%s.fifo", P_tmpdir, DisplayString(W->dpy)); - - /* Check if fifo already exists */ - if(access(W->fifo.path, F_OK) != -1) - unlink(W->fifo.path); - - if(mkfifo(W->fifo.path, 0644) < 0) - warnxl("Can't create FIFO: %s\n", strerror(errno)); - - fifo_open(); -} - -static void -fifo_parse(char *cmd) -{ - void (*func)(Uicb); - char *p, *arg = NULL; - - /* remove trailing newline */ - if((p = strchr(cmd, '\n'))) - *p = '\0'; - - /* If an argument is present, delimit function string */ - if((p = strchr(cmd, ' '))) - { - *p = '\0'; - arg = p + 1; - } - - /* call the UICB function, p + 1 is command or NULL */ - if((func = uicb_name_func(cmd))) - func(arg); - - XSync(W->dpy, false); -} - -void -fifo_read(void) -{ - char buf[READ_SIZE] = { 0 }; - int ret; - - if((ret = read(W->fifo.fd, buf, sizeof(buf) - 1)) > 0) - fifo_parse(buf); - else if(!ret) - fifo_open(); -} diff --git a/src/screen.c b/src/screen.c index 3fa0748..e0a3979 100644 --- a/src/screen.c +++ b/src/screen.c @@ -101,10 +101,10 @@ screen_select(struct screen *s) void uicb_screen_next(Uicb cmd) { - struct screen *s; + struct screen *s = SLIST_NEXT(W->screen, next); (void)cmd; - if(!(s = SLIST_NEXT(W->screen, next))) + if(!s) s = SLIST_FIRST(&W->h.screen); screen_select(s); @@ -113,23 +113,19 @@ uicb_screen_next(Uicb cmd) void uicb_screen_prev(Uicb cmd) { - struct screen *s; + struct screen *s = SLIST_FIRST(&W->h.screen); (void)cmd; - SLIST_FOREACH(s, &W->h.screen, next) - if(SLIST_NEXT(W->screen, next) == s) - { - screen_select(s); - return; - } + while(SLIST_NEXT(s, next) && SLIST_NEXT(s, next) != s) + s = SLIST_NEXT(s, next); - screen_select(SLIST_FIRST(&W->h.screen)); + screen_select(s); } void uicb_screen_move_client_next(Uicb cmd) { - struct screen *s = SLIST_NEXT(W->screen, next);; + struct screen *s = SLIST_NEXT(W->screen, next); (void)cmd; if(!s) diff --git a/src/wmfs.c b/src/wmfs.c index a479517..51d6adf 100644 --- a/src/wmfs.c +++ b/src/wmfs.c @@ -22,7 +22,6 @@ #include "util.h" #include "config.h" #include "client.h" -#include "fifo.h" #include "layout.h" int @@ -357,39 +356,26 @@ wmfs_scan(void) XSync(W->dpy, false); } +static inline void +wmfs_sigchld(void) +{ + if(W->flags & WMFS_SIGCHLD) + { + while(waitpid(-1, NULL, WNOHANG) > 0); + W->flags ^= WMFS_SIGCHLD; + } +} + static void wmfs_loop(void) { XEvent ev; - int maxfd, fd = ConnectionNumber(W->dpy); - fd_set iset; - while(W->flags & WMFS_RUNNING) + while((W->flags & WMFS_RUNNING) && !XNextEvent(W->dpy, &ev)) { - maxfd = fd + 1; - - FD_ZERO(&iset); - FD_SET(fd, &iset); - - if(W->fifo.fd > 0) - { - maxfd += W->fifo.fd; - FD_SET(W->fifo.fd, &iset); - } - - if(select(maxfd, &iset, NULL, NULL, NULL) > 0) - { - if(FD_ISSET(fd, &iset)) - { - while((W->flags & WMFS_RUNNING) && XPending(W->dpy)) - { - XNextEvent(W->dpy, &ev); - EVENT_HANDLE(&ev); - } - } - else if(W->fifo.fd > 0 && FD_ISSET(W->fifo.fd, &iset)) - fifo_read(); - } + /* Manage SIGCHLD event here, X is not safe with it */ + wmfs_sigchld(); + EVENT_HANDLE(&ev); } } @@ -402,7 +388,6 @@ wmfs_init(void) screen_init(); event_init(); config_init(); - fifo_init(); } void @@ -486,13 +471,6 @@ wmfs_quit(void) free(r); } - /* FIFO stuffs */ - if(W->fifo.fd > 0) - { - close(W->fifo.fd); - unlink(W->fifo.path); - } - /* close log */ if(W->log) fclose(W->log), W->log = NULL; @@ -554,7 +532,7 @@ signal_handle(int sig) W->flags &= ~WMFS_RUNNING; break; case SIGCHLD: - while(waitpid(-1, NULL, WNOHANG) > 0); + W->flags |= WMFS_SIGCHLD; break; } } diff --git a/src/wmfs.h b/src/wmfs.h index fb0bcdf..8a72310 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -324,6 +324,7 @@ struct wmfs #define WMFS_SYSTRAY 0x08 #define WMFS_LOG 0x10 #define WMFS_LAUNCHER 0x20 +#define WMFS_SIGCHLD 0x40 Flags flags; GC gc, rgc; Atom *net_atom; @@ -332,13 +333,6 @@ struct wmfs struct barwin *last_clicked_barwin; struct theme *ctheme; - /* FIFO stuffs */ - struct - { - char *path; - int fd; - } fifo; - /* Log file */ FILE *log;