To close the possible race between socket() and fcntl(), we use
SOCK_CLOEXEC instead of fcntl() when it is available.
Closes #20442
{
char errbuf[STRERROR_LEN];
+#ifdef SOCK_CLOEXEC
+ addr->socktype |= SOCK_CLOEXEC;
+#endif
+
DEBUGASSERT(data);
DEBUGASSERT(data->conn);
if(data->set.fopensocket) {
}
#endif /* USE_SO_NOSIGPIPE */
-#ifdef HAVE_FCNTL
+#if defined(HAVE_FCNTL) && !defined(SOCK_CLOEXEC)
if(fcntl(*sockfd, F_SETFD, FD_CLOEXEC) < 0) {
failf(data, "fcntl set CLOEXEC: %s",
curlx_strerror(SOCKERRNO, errbuf, sizeof(errbuf)));