Move stdin/out handling entirely into stdinout.c
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "flow.h"
|
||||
@@ -11,6 +13,12 @@
|
||||
|
||||
static opts_group stdinout_opts;
|
||||
|
||||
static void stdinout_reopen(int fd, char *path, int flags) {
|
||||
// Presumes that all fds < fd are open
|
||||
assert(!close(fd));
|
||||
assert(open(path, flags | O_CLOEXEC | O_NOCTTY) == fd);
|
||||
}
|
||||
|
||||
static bool stdinout_stdin(const char __attribute__((unused)) *arg) {
|
||||
int fd = fcntl(STDIN_FILENO, F_DUPFD_CLOEXEC, 0);
|
||||
assert(fd >= 0);
|
||||
@@ -34,4 +42,11 @@ void stdinout_opts_add() {
|
||||
|
||||
void stdinout_init() {
|
||||
opts_call(stdinout_opts);
|
||||
stdinout_reopen(STDIN_FILENO, "/dev/null", O_RDONLY);
|
||||
stdinout_reopen(STDOUT_FILENO, "/dev/full", O_WRONLY);
|
||||
}
|
||||
|
||||
void stdinout_cleanup() {
|
||||
assert(!close(STDIN_FILENO));
|
||||
assert(!close(STDOUT_FILENO));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user