diff --git a/src/fifo.c b/src/fifo.c index 88707e0..bdc4e20 100644 --- a/src/fifo.c +++ b/src/fifo.c @@ -9,6 +9,16 @@ #include "config.h" #include "fifo.h" +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))) + warnx("Can't open FIFO: %s\n", strerror(errno)); +} + void fifo_init(void) { @@ -17,8 +27,7 @@ fifo_init(void) 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_RDONLY | O_NDELAY, 0))) - warnx("Can't open FIFO: %s\n", strerror(errno)); + fifo_open(); } static void @@ -42,14 +51,14 @@ fifo_parse(char *cmd) XSync(W->dpy, false); } -int +void fifo_read(void) { char buf[256] = { 0 }; - int ret = 0; + int ret; if((ret = read(W->fifo.fd, buf, sizeof(buf) - 1)) > 0) fifo_parse(buf); - - return ret; + else if(!ret) + fifo_open(); } diff --git a/src/fifo.h b/src/fifo.h index caa03f8..81a6a57 100644 --- a/src/fifo.h +++ b/src/fifo.h @@ -14,6 +14,6 @@ #include void fifo_init(void); -int fifo_read(void); +void fifo_read(void); #endif /* __FIFO_H */ diff --git a/src/wmfs.c b/src/wmfs.c index d896c10..ecc29f3 100644 --- a/src/wmfs.c +++ b/src/wmfs.c @@ -242,12 +242,12 @@ static void wmfs_loop(void) { XEvent ev; - int fd = ConnectionNumber(W->dpy); + int maxfd, fd = ConnectionNumber(W->dpy); fd_set iset; while(W->running) { - int maxfd = fd + 1; + maxfd = fd + 1; FD_ZERO(&iset); FD_SET(fd, &iset); @@ -269,15 +269,7 @@ wmfs_loop(void) } } else if(W->fifo.fd > 0 && FD_ISSET(W->fifo.fd, &iset)) - { - if(fifo_read() == 0) - { - close(W->fifo.fd); - - if(!(W->fifo.fd = open(W->fifo.path, O_RDONLY | O_NDELAY, 0))) - warnx("Can't reopen FIFO: %s\n", strerror(errno)); - } - } + fifo_read(); } } }