From 1117b84689ee5337369b95c7b093be9acbed26ae Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 7 Jan 2005 22:49:02 +0000 Subject: add FD_CLOEXEC support git-svn-id: file:///home/lennart/svn/public/libasyncns/trunk@13 cc0fb855-19ed-0310-866e-8c1d96e4abae --- libasyncns/asyncns.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'libasyncns/asyncns.c') diff --git a/libasyncns/asyncns.c b/libasyncns/asyncns.c index 6976256..d1ce584 100644 --- a/libasyncns/asyncns.c +++ b/libasyncns/asyncns.c @@ -155,6 +155,20 @@ static int fd_nonblock(int fd) { return fcntl(fd, F_SETFL, i | O_NONBLOCK); } +static int fd_cloexec(int fd) { + int v; + assert(fd >= 0); + + if ((v = fcntl(fd, F_GETFD, 0)) < 0) + return -1; + + if (v & FD_CLOEXEC) + return 0; + + return fcntl(fd, F_SETFD, v | FD_CLOEXEC); +} + + static void *serialize_addrinfo(void *p, const struct addrinfo *ai, size_t *length, size_t maxlength) { addrinfo_serialization_t *s = p; size_t cnl, l; @@ -402,6 +416,11 @@ asyncns_t* asyncns_new(int n_proc) { if (socketpair(PF_UNIX, SOCK_DGRAM, 0, fd2) < 0) goto fail; + fd_cloexec(fd1[0]); + fd_cloexec(fd1[1]); + fd_cloexec(fd2[0]); + fd_cloexec(fd2[1]); + if (n_proc > MAX_WORKERS) n_proc = MAX_WORKERS; -- cgit