Fifo: code cosmetic
This commit is contained in:
parent
4e9be5ff15
commit
2abbd8ca98
21
src/fifo.c
21
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();
|
||||
}
|
||||
|
||||
@ -14,6 +14,6 @@
|
||||
#include <string.h>
|
||||
|
||||
void fifo_init(void);
|
||||
int fifo_read(void);
|
||||
void fifo_read(void);
|
||||
|
||||
#endif /* __FIFO_H */
|
||||
|
||||
14
src/wmfs.c
14
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user