--- parser3/src/main/pa_http.C 2026/10/28 20:22:22 1.146 +++ parser3/src/main/pa_http.C 2026/10/29 23:51:57 1.148 @@ -18,7 +18,7 @@ #include // for TCP_NODELAY #endif -volatile const char * IDENT_PA_HTTP_C="$Id: pa_http.C,v 1.146 2026/10/28 20:22:22 moko Exp $" IDENT_PA_HTTP_H; +volatile const char * IDENT_PA_HTTP_C="$Id: pa_http.C,v 1.148 2026/10/29 23:51:57 moko Exp $" IDENT_PA_HTTP_H; // defines @@ -46,9 +46,20 @@ volatile const char * IDENT_PA_HTTP_C="$ #define PA_ACCEPT(sock, addr, len) ::accept4(sock, addr, len, SOCK_CLOEXEC) #define PA_SOCKET(domain, type, protocol) ::socket(domain, (type) | SOCK_CLOEXEC, protocol) #else +#ifdef FD_CLOEXEC +// FreeBSD < 10: a program executed by another thread between the call and fcntl still inherits the socket +static SOCKET pa_cloexec(SOCKET sock) { + if(sock != INVALID_SOCKET) + fcntl(sock, F_SETFD, FD_CLOEXEC); + return sock; +} +#define PA_ACCEPT(sock, addr, len) pa_cloexec(::accept(sock, addr, len)) +#define PA_SOCKET(domain, type, protocol) pa_cloexec(::socket(domain, type, protocol)) +#else #define PA_ACCEPT(sock, addr, len) ::accept(sock, addr, len) #define PA_SOCKET(domain, type, protocol) ::socket(domain, type, protocol) #endif +#endif #undef CRLF #define CRLF "\r\n" @@ -373,7 +384,7 @@ static int http_request(HTTP_response& r set_socket_timeout(sock, SO_RCVTIMEO, timeout_secs); } - if(connect(sock, (struct sockaddr *)&dest, sizeof(dest))) { + if(pa_sock_connect(sock, (struct sockaddr *)&dest, sizeof(dest))) { int no=check_socket_timeout(pa_socks_errno()); throw Exception("http.connect", 0, "cannot connect to host \"%s\": %s (%d)", host, pa_socks_strerr(no), no); }