From d1ec33ed5364577dff95071f36f76e4b29e86131 Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Thu, 27 Oct 2011 15:01:13 +0200 Subject: [PATCH] Fix fifo code --- src/client.c | 6 ++---- src/fifo.c | 40 +++++++++++++--------------------------- 2 files changed, 15 insertions(+), 31 deletions(-) diff --git a/src/client.c b/src/client.c index 6188bac..0d07f03 100644 --- a/src/client.c +++ b/src/client.c @@ -528,9 +528,7 @@ client_frame_new(struct client *c) struct client* client_new(Window w, XWindowAttributes *wa) { - struct client *c = NULL; - - c = xcalloc(1, sizeof(struct client)); + struct client *c = xcalloc(1, sizeof(struct client)); /* C attributes */ c->win = w; @@ -794,7 +792,7 @@ client_apply_tgeo(struct tag *t) do { \ SLIST_FOREACH(gc, &c->tag->clients, tnext) \ draw_reversed_rect(W->root, &gc->tgeo); \ - draw_reversed_cross(W->root, &c->tag->sel->tgeo); \ + /* draw_reversed_cross(W->root, &c->tag->sel->tgeo);*/ \ } while(/* CONSTCOND */ 0); void client_fac_resize(struct client *c, enum position p, int fac) diff --git a/src/fifo.c b/src/fifo.c index 3e9ba73..a7723d8 100644 --- a/src/fifo.c +++ b/src/fifo.c @@ -14,38 +14,30 @@ fifo_init(void) { xasprintf(&(W->fifo.path), "%s/wmfs-%s.fifo", P_tmpdir, DisplayString(W->dpy)); - if(mkfifo(W->fifo.path, 0644) < 0 || !(W->fifo.fd = open(W->fifo.path, O_NONBLOCK, 0))) + if(mkfifo(W->fifo.path, 0644) < 0) warnx("Can't create FIFO: %s\n", strerror(errno)); + + if(!(W->fifo.fd = open(W->fifo.path, O_NONBLOCK, 0))) + warnx("Can't open FIFO: %s\n", strerror(errno)); } static void fifo_parse(char *cmd) { void (*func)(Uicb); - char *uicb = NULL; - char *arg = NULL; - char *p = NULL; + char *p = NULL; /* remove trailing newline */ if((p = strchr(cmd, '\n'))) - *p = 0; + *p = '\0'; - /* Check if an argument is present */ + /* If an argument is present, delimit function string */ if((p = strchr(cmd, ' '))) - { - *p = 0; - arg = xstrdup(p + 1); - } - uicb = xstrdup(cmd); + *p = '\0'; - /* call the UICB function */ - func = uicb_name_func(uicb); - if(func) - func(arg); - - if(arg) - free(arg); - free(uicb); + /* call the UICB function, p + 1 is command or NULL */ + if((func = uicb_name_func(cmd))) + func(p + 1); XSync(W->dpy, false); } @@ -53,14 +45,8 @@ fifo_parse(char *cmd) void fifo_read(void) { - char buf[256] = {0}; + static char buf[256] = { 0 }; - /* Don't read it if not open */ - if(!(W->fifo.fd)) - return; - - read(W->fifo.fd, buf, sizeof(buf) - 1); - - if(buf[0]) + if(read(W->fifo.fd, buf, sizeof(buf) - 1) > 0) fifo_parse(buf); }