From 9d63dfcf49924fad573109c80dfa881c19cfe195 Mon Sep 17 00:00:00 2001 From: Steven Murdoch Date: Sat, 20 Nov 2010 13:50:55 +0000 Subject: [PATCH 1/2] Fix compile error on MacOS X (and other platforms without O_CLOEXEC) --- src/common/compat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/compat.c b/src/common/compat.c index 42602fb3a3..07d961812c 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -112,7 +112,7 @@ tor_open_cloexec(const char *path, int flags, unsigned mode) int fd = open(path, flags, mode); #ifdef FD_CLOEXEC if (fd >= 0) - fcntl(s, F_SETFD, FD_CLOEXEC); + fcntl(fd, F_SETFD, FD_CLOEXEC); #endif return fd; #endif From 15f2b7859bbf66ca74cc240e89ba02c81d95cb02 Mon Sep 17 00:00:00 2001 From: Steven Murdoch Date: Sun, 21 Nov 2010 15:40:17 +0000 Subject: [PATCH 2/2] Don't both open the socket with SOCK_CLOEXEC and set FD_CLOEXEC --- src/common/compat.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/compat.c b/src/common/compat.c index 07d961812c..56315e5079 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -935,11 +935,12 @@ tor_open_socket(int domain, int type, int protocol) { int s; #ifdef SOCK_CLOEXEC +#define LINUX_CLOEXEC_OPEN_SOCKET type |= SOCK_CLOEXEC; #endif s = socket(domain, type, protocol); if (s >= 0) { -#ifdef FD_CLOEXEC +#if !defined(LINUX_CLOEXEC_OPEN_SOCKET) && defined(FD_CLOEXEC) fcntl(s, F_SETFD, FD_CLOEXEC); #endif socket_accounting_lock();