Fix FIFO (close it and reopen it after reading)
This commit is contained in:
parent
984145243d
commit
7b9d9d1e53
11
src/fifo.c
11
src/fifo.c
@ -17,7 +17,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_NONBLOCK, 0)))
|
||||
if(!(W->fifo.fd = open(W->fifo.path, O_RDONLY | O_NDELAY, 0)))
|
||||
warnx("Can't open FIFO: %s\n", strerror(errno));
|
||||
}
|
||||
|
||||
@ -42,11 +42,14 @@ fifo_parse(char *cmd)
|
||||
XSync(W->dpy, false);
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
fifo_read(void)
|
||||
{
|
||||
static char buf[256] = { 0 };
|
||||
char buf[256] = { 0 };
|
||||
int ret = 0;
|
||||
|
||||
if(read(W->fifo.fd, buf, sizeof(buf) - 1) > 0)
|
||||
if((ret = read(W->fifo.fd, buf, sizeof(buf) - 1)) > 0)
|
||||
fifo_parse(buf);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -14,6 +14,6 @@
|
||||
#include <string.h>
|
||||
|
||||
void fifo_init(void);
|
||||
void fifo_read(void);
|
||||
int fifo_read(void);
|
||||
|
||||
#endif /* __FIFO_H */
|
||||
|
||||
19
src/wmfs.c
19
src/wmfs.c
@ -243,19 +243,20 @@ wmfs_loop(void)
|
||||
{
|
||||
XEvent ev;
|
||||
int fd = ConnectionNumber(W->dpy);
|
||||
int maxfd = fd + 1;
|
||||
fd_set iset;
|
||||
|
||||
if(W->fifo.fd > 0)
|
||||
maxfd += W->fifo.fd;
|
||||
|
||||
while(W->running)
|
||||
{
|
||||
int 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)
|
||||
{
|
||||
@ -268,7 +269,15 @@ wmfs_loop(void)
|
||||
}
|
||||
}
|
||||
else if(W->fifo.fd > 0 && FD_ISSET(W->fifo.fd, &iset))
|
||||
fifo_read();
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user