my->info.read_blocked = false;
my->info.write_blocked = false;
- switch (my->info.cfg->flags) {
+ /*
+ * Other flags may be O_CREAT, etc.
+ */
+ switch (my->info.cfg->flags & (O_RDONLY | O_WRONLY | O_RDWR)) {
case O_RDONLY:
my->bio.read = fr_bio_fd_read_stream;
my->bio.write = fr_bio_null_write; /* @todo - error on write? */
my->info.socket.type = SOCK_STREAM;
my->info.socket.unix.path = cfg->filename;
- fd = open(cfg->filename, cfg->flags);
+ /*
+ * Allow hacks for stdout and stderr
+ */
+ if (strcmp(cfg->filename, "/dev/stdout") == 0) {
+ if (cfg->flags != O_WRONLY) {
+ fail_dev:
+ fr_strerror_printf("Cannot read from %s", cfg->filename);
+ return -1;
+ }
+
+ fd = dup(STDOUT_FILENO);
+
+ } else if (strcmp(cfg->filename, "/dev/stderr") == 0) {
+ if (cfg->flags != O_WRONLY) goto fail_dev;
+
+ fd = dup(STDERR_FILENO);
+
+ } else {
+ fd = open(cfg->filename, cfg->flags, cfg->perm);
+ }
if (fd < 0) {
fr_strerror_printf("Failed opening file %s: %s", cfg->filename, fr_syserror(errno));
return -1;