diff options
Diffstat (limited to 'src/daemon/daemon.c')
-rw-r--r-- | src/daemon/daemon.c | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 6db7ec10..d85ed92a 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c | |||
@@ -1149,12 +1149,22 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
1149 | if (MHD_YES == need_fcntl) | 1149 | if (MHD_YES == need_fcntl) |
1150 | { | 1150 | { |
1151 | /* make socket non-inheritable */ | 1151 | /* make socket non-inheritable */ |
1152 | #if !WINDOWS | ||
1152 | flags = fcntl (s, F_GETFD); | 1153 | flags = fcntl (s, F_GETFD); |
1153 | if ( ( (-1 == flags) || | 1154 | if ( ( (-1 == flags) || |
1154 | ( (flags != (flags | FD_CLOEXEC)) && | 1155 | ( (flags != (flags | FD_CLOEXEC)) && |
1155 | (0 != fcntl (s, F_SETFD, flags | FD_CLOEXEC)) ) ) ) | 1156 | (0 != fcntl (s, F_SETFD, flags | FD_CLOEXEC)) ) ) ) |
1157 | #else | ||
1158 | DWORD dwFlags; | ||
1159 | if (!GetHandleInformation ((HANDLE) s, &dwFlags) || | ||
1160 | ((dwFlags != dwFlags & ~HANDLE_FLAG_INHERIT) && | ||
1161 | !SetHandleInformation ((HANDLE) s, HANDLE_FLAG_INHERIT, 0))) | ||
1162 | #endif | ||
1156 | { | 1163 | { |
1157 | #if HAVE_MESSAGES | 1164 | #if HAVE_MESSAGES |
1165 | #if WINDOWS | ||
1166 | SetErrnoFromWinError (GetLastError ()); | ||
1167 | #endif | ||
1158 | FPRINTF(stderr, "Failed to make socket non-inheritable: %s\n", | 1168 | FPRINTF(stderr, "Failed to make socket non-inheritable: %s\n", |
1159 | STRERROR (errno)); | 1169 | STRERROR (errno)); |
1160 | #endif | 1170 | #endif |
@@ -1993,35 +2003,54 @@ create_socket (int domain, int type, int protocol) | |||
1993 | int ctype = SOCK_STREAM | sock_cloexec; | 2003 | int ctype = SOCK_STREAM | sock_cloexec; |
1994 | int fd; | 2004 | int fd; |
1995 | int flags; | 2005 | int flags; |
2006 | #if WINDOWS | ||
2007 | DWORD dwFlags; | ||
2008 | #endif | ||
1996 | 2009 | ||
1997 | /* use SOCK_STREAM rather than ai_socktype: some getaddrinfo | 2010 | /* use SOCK_STREAM rather than ai_socktype: some getaddrinfo |
1998 | * implementations do not set ai_socktype, e.g. RHL6.2. */ | 2011 | * implementations do not set ai_socktype, e.g. RHL6.2. */ |
1999 | fd = socket(domain, ctype, protocol); | 2012 | fd = SOCKET(domain, ctype, protocol); |
2000 | if ( (-1 == fd) && (EINVAL == errno) && (0 != sock_cloexec) ) | 2013 | if ( (-1 == fd) && (EINVAL == errno) && (0 != sock_cloexec) ) |
2001 | { | 2014 | { |
2002 | sock_cloexec = 0; | 2015 | sock_cloexec = 0; |
2003 | fd = socket(domain, type, protocol); | 2016 | fd = SOCKET(domain, type, protocol); |
2004 | } | 2017 | } |
2005 | if (-1 == fd) | 2018 | if (-1 == fd) |
2006 | return -1; | 2019 | return -1; |
2007 | if (0 != sock_cloexec) | 2020 | if (0 != sock_cloexec) |
2008 | return fd; /* this is it */ | 2021 | return fd; /* this is it */ |
2009 | /* flag was not set during 'socket' call, let's try setting it manually */ | 2022 | /* flag was not set during 'socket' call, let's try setting it manually */ |
2023 | #if !WINDOWS | ||
2010 | flags = fcntl (fd, F_GETFD); | 2024 | flags = fcntl (fd, F_GETFD); |
2011 | if (flags < 0) | 2025 | if (flags < 0) |
2026 | #else | ||
2027 | if (!GetHandleInformation ((HANDLE) fd, &dwFlags)) | ||
2028 | #endif | ||
2012 | { | 2029 | { |
2013 | #if HAVE_MESSAGES | 2030 | #if HAVE_MESSAGES |
2031 | #if WINDOWS | ||
2032 | SetErrnoFromWinError (GetLastError ()); | ||
2033 | #endif | ||
2014 | FPRINTF(stderr, "Failed to get socket options to make socket non-inheritable: %s\n", | 2034 | FPRINTF(stderr, "Failed to get socket options to make socket non-inheritable: %s\n", |
2015 | STRERROR (errno)); | 2035 | STRERROR (errno)); |
2016 | #endif | 2036 | #endif |
2017 | return fd; /* good luck */ | 2037 | return fd; /* good luck */ |
2018 | } | 2038 | } |
2039 | #if !WINDOWS | ||
2019 | if (flags == (flags | FD_CLOEXEC)) | 2040 | if (flags == (flags | FD_CLOEXEC)) |
2020 | return fd; /* already set */ | 2041 | return fd; /* already set */ |
2021 | flags |= FD_CLOEXEC; | 2042 | flags |= FD_CLOEXEC; |
2022 | if (0 != fcntl (fd, F_SETFD, flags)) | 2043 | if (0 != fcntl (fd, F_SETFD, flags)) |
2044 | #else | ||
2045 | if (dwFlags != dwFlags | HANDLE_FLAG_INHERIT) | ||
2046 | return fd; /* already unset */ | ||
2047 | if (!SetHandleInformation ((HANDLE) fd, HANDLE_FLAG_INHERIT, 0)) | ||
2048 | #endif | ||
2023 | { | 2049 | { |
2024 | #if HAVE_MESSAGES | 2050 | #if HAVE_MESSAGES |
2051 | #if WINDOWS | ||
2052 | SetErrnoFromWinError (GetLastError ()); | ||
2053 | #endif | ||
2025 | FPRINTF(stderr, "Failed to make socket non-inheritable: %s\n", | 2054 | FPRINTF(stderr, "Failed to make socket non-inheritable: %s\n", |
2026 | STRERROR (errno)); | 2055 | STRERROR (errno)); |
2027 | #endif | 2056 | #endif |
@@ -2804,7 +2833,7 @@ MHD_init () | |||
2804 | mhd_panic_cls = NULL; | 2833 | mhd_panic_cls = NULL; |
2805 | 2834 | ||
2806 | #ifdef WINDOWS | 2835 | #ifdef WINDOWS |
2807 | plibc_init ("GNU", "libmicrohttpd"); | 2836 | plibc_init_utf8 ("GNU", "libmicrohttpd", 1); |
2808 | #endif | 2837 | #endif |
2809 | #if HTTPS_SUPPORT | 2838 | #if HTTPS_SUPPORT |
2810 | gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); | 2839 | gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); |