Fix SIGCHLD signal handling, remove fifo from master

This commit is contained in:
Martin Duquesnoy 2012-02-01 14:13:19 +01:00
parent 5e3c44824d
commit acc66f62ab
7 changed files with 30 additions and 139 deletions

View File

@ -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 \

View File

@ -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))

View File

@ -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)

View File

@ -1,75 +0,0 @@
/*
* wmfs2 by Martin Duquesnoy <xorg62@gmail.com> { for(i = 2011; i < 2111; ++i) ©(i); }
* File created by David Delassus.
* For license, see COPYING.
*/
#include <sys/stat.h> /* 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();
}

View File

@ -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)

View File

@ -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;
}
}

View File

@ -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;