home
/
code
/
khatus.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Check that file exists and that it is a FIFO
[khatus.git]
/
x5
/
khatus.c
diff --git
a/x5/khatus.c
b/x5/khatus.c
index
a41351a
..
faef5b1
100644
(file)
--- a/
x5/khatus.c
+++ b/
x5/khatus.c
@@
-1,6
+1,8
@@
+
#include <fcntl.h>
#include <unistd.h>
#include <sys/select.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/select.h>
+#include <sys/stat.h>
#include <assert.h>
#include <ctype.h>
#include <assert.h>
#include <ctype.h>
@@
-240,6
+242,7
@@
read_one(File *f, char *buf)
b = buf + f->pos;
memset(b, ' ', f->width);
b = buf + f->pos;
memset(b, ' ', f->width);
+ /* TODO: Read upto \n or width */
while ((n = read(f->fd, b, f->width)) > 0) {
b += n;
debug("read %zd from %s\n", n, f->name);
while ((n = read(f->fd, b, f->width)) > 0) {
b += n;
debug("read %zd from %s\n", n, f->name);
@@
-266,11
+269,17
@@
read_all(Config *cfg, char *buf)
fd_set fds;
int maxfd;
int ready;
fd_set fds;
int maxfd;
int ready;
+ struct stat st;
FD_ZERO(&fds);
FD_ZERO(&fds);
- /* TODO:
stat then c
heck TTL */
+ /* TODO:
C
heck TTL */
for (File *f = cfg->files; f; f = f->next) {
for (File *f = cfg->files; f; f = f->next) {
+ /* TODO: Create the FIFO if it doesn't already exist. */
+ if (lstat(f->name, &st) < 0)
+ fatal("Cannot stat \"%s\". Error: %s\n", f->name, strerror(errno));
+ if (!(st.st_mode & S_IFIFO))
+ fatal("\"%s\" is not a FIFO\n", f->name);
debug("opening: %s\n", f->name);
if (f->fd < 0)
f->fd = open(f->name, O_RDONLY | O_NONBLOCK);
debug("opening: %s\n", f->name);
if (f->fd < 0)
f->fd = open(f->name, O_RDONLY | O_NONBLOCK);
This page took
0.021892 seconds
and
4
git commands to generate.