From c6ed048ce09050da0c66de0c4b22e05e97774b6d Mon Sep 17 00:00:00 2001 From: FRIGN Date: Fri, 19 Sep 2014 13:39:51 +0200 Subject: 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. --- ratox.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'ratox.c') diff --git a/ratox.c b/ratox.c index 564de60..1689a6d 100644 --- 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) { -- cgit v1.2.3