--- parser3/src/main/pa_http.C 2026/10/29 19:51:53 1.147 +++ parser3/src/main/pa_http.C 2026/10/30 17:15:10 1.149 @@ -18,7 +18,7 @@ #include // for TCP_NODELAY #endif -volatile const char * IDENT_PA_HTTP_C="$Id: pa_http.C,v 1.147 2026/10/29 19:51:53 moko Exp $" IDENT_PA_HTTP_H; +volatile const char * IDENT_PA_HTTP_C="$Id: pa_http.C,v 1.149 2026/10/30 17:15:10 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" @@ -358,7 +369,7 @@ static int http_request(HTTP_response& r if(!set_addr(&dest, host, port)) throw Exception("http.host", 0, "cannot resolve hostname \"%s\"", host); - if((sock=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP/*0*/)) == INVALID_SOCKET) { + if((sock=PA_SOCKET(AF_INET, SOCK_STREAM, IPPROTO_TCP/*0*/)) == INVALID_SOCKET) { int no=pa_socks_errno(); throw Exception("http.connect", 0, "cannot make socket: %s (%d)", pa_socks_strerr(no), no); }