ratox

FIFO based tox client
git clone git://git.2f30.org/ratox.git
Log | Files | Refs | README | LICENSE

commit c6ed048ce09050da0c66de0c4b22e05e97774b6d
parent 7171cb2591c5df14b362c45a0ebc6cb166518953
Author: FRIGN <dev@frign.de>
Date:   Fri, 19 Sep 2014 13:39:51 +0200

Clear up the enums and fix implicit condition-bug

The OUT_F-type was not clear. Make it easier to see the out-file
has no state (=NONE) and is defined for each slot individually.

Moreover, in the initial creation, the err-file fell through
just because STATIC = 0 and .outfile wasn't defined for it.

It was only coincidence this worked and now we have a much
more bulletproof implementation.

Diffstat:
ratox.c | 17++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/ratox.c b/ratox.c @@ -60,8 +60,8 @@ enum { }; enum { + NONE, FIFO, - OUT_F, STATIC, FOLDER }; @@ -77,9 +77,9 @@ static struct slot gslots[] = { }; static struct file gfiles[] = { - { .type = FIFO, .name = "in", .flags = O_RDONLY | O_NONBLOCK, }, - { .type = OUT_F, .name = "out", .flags = O_WRONLY | O_TRUNC | O_CREAT }, - { .type = OUT_F, .name = "err", .flags = O_WRONLY | O_TRUNC | O_CREAT }, + { .type = FIFO, .name = "in", .flags = O_RDONLY | O_NONBLOCK, }, + { .type = NONE, .name = "out", .flags = O_WRONLY | O_TRUNC | O_CREAT }, + { .type = STATIC, .name = "err", .flags = O_WRONLY | O_TRUNC | O_CREAT }, }; enum { @@ -634,7 +634,14 @@ localinit(void) exit(EXIT_FAILURE); } gslots[i].fd[m] = r; - } else if (gfiles[m].type == OUT_F) { + } else if (gfiles[m].type == STATIC) { + r = openat(gslots[i].dirfd, gfiles[m].name, gfiles[m].flags, 0644); + if (r < 0) { + perror("open"); + exit(EXIT_FAILURE); + } + gslots[i].fd[m] = r; + } else if (gfiles[m].type == NONE) { if (gslots[i].outtype == STATIC) { r = openat(gslots[i].dirfd, gfiles[m].name, gfiles[m].flags, 0644); if (r < 0) {