From 9a86ce6ea990ac72337bffb78f663f8a904a408f Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 29 Apr 2014 16:17:58 +0200 Subject: Fold fastd_open_pipe into fastd_async_init, simpify fastd_setfl and fastd_setfd and move to fastd.h --- src/fastd.c | 36 +----------------------------------- 1 file changed, 1 insertion(+), 35 deletions(-) (limited to 'src/fastd.c') diff --git a/src/fastd.c b/src/fastd.c index 9f1f60b..523889a 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -34,7 +34,6 @@ #include "poll.h" #include -#include #include #include #include @@ -121,20 +120,6 @@ static void init_signals(void) { } -void fastd_open_pipe(int *readfd, int *writefd) { - int pipefd[2]; - - /* use socketpair with SOCK_DGRAM instead of pipe2 with O_DIRECT to keep this portable */ - if (socketpair(AF_UNIX, SOCK_DGRAM, 0, pipefd)) - exit_errno("socketpair"); - - fastd_setfd(pipefd[0], FD_CLOEXEC, 0); - fastd_setfd(pipefd[1], FD_CLOEXEC, 0); - - *readfd = pipefd[0]; - *writefd = pipefd[1]; -} - static void init_log(void) { uid_t uid = geteuid(); gid_t gid = getegid(); @@ -202,25 +187,6 @@ static void init_sockets(void) { ctx.n_socks = conf.n_bind_addrs; } - -void fastd_setfd(const int fd, int set, int unset) { - int flags = fcntl(fd, F_GETFD); - if (flags < 0) - exit_errno("Getting file descriptor flags failed: fcntl"); - - if (fcntl(fd, F_SETFD, (flags|set) & (~unset)) < 0) - exit_errno("Setting file descriptor flags failed: fcntl"); -} - -void fastd_setfl(const int fd, int set, int unset) { - int flags = fcntl(fd, F_GETFL); - if (flags < 0) - exit_errno("Getting file status flags failed: fcntl"); - - if (fcntl(fd, F_SETFL, (flags|set) & (~unset)) < 0) - exit_errno("Setting file status flags failed: fcntl"); -} - static void close_sockets(void) { size_t i; for (i = 0; i < ctx.n_socks; i++) @@ -544,7 +510,7 @@ static int daemonize(void) { } else { /* child 2 */ - fastd_setfd(pipefd[1], FD_CLOEXEC, 0); + fastd_setfd(pipefd[1], FD_CLOEXEC); return pipefd[1]; } } -- cgit v1.2.3