summaryrefslogtreecommitdiff
path: root/ratox.c
diff options
context:
space:
mode:
authorFRIGN <dev@frign.de>2014-09-19 13:39:51 +0200
committersin <sin@2f30.org>2014-09-19 14:20:19 +0100
commitc6ed048ce09050da0c66de0c4b22e05e97774b6d (patch)
tree570996e7c70c4f0f5e893f5cbee2f27827b394b3 /ratox.c
parent7171cb2591c5df14b362c45a0ebc6cb166518953 (diff)
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 (limited to 'ratox.c')
-rw-r--r--ratox.c17
1 files changed, 12 insertions, 5 deletions
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) {