diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-04-29 16:17:58 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-04-29 16:17:58 +0200 |
commit | 9a86ce6ea990ac72337bffb78f663f8a904a408f (patch) | |
tree | b532fb296850eab0598d89452373170c9b4c1c1a /src/fastd.c | |
parent | 639ebc2ff93adca5eb9e12d70a2e9e19731c84ba (diff) | |
download | fastd-9a86ce6ea990ac72337bffb78f663f8a904a408f.tar fastd-9a86ce6ea990ac72337bffb78f663f8a904a408f.zip |
Fold fastd_open_pipe into fastd_async_init, simpify fastd_setfl and fastd_setfd and move to fastd.h
Diffstat (limited to 'src/fastd.c')
-rw-r--r-- | src/fastd.c | 36 |
1 files changed, 1 insertions, 35 deletions
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 <fastd_version.h> -#include <fcntl.h> #include <grp.h> #include <pthread.h> #include <signal.h> @@ -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]; } } |