socketpair: set SO_NOSIGPIPE where possible

Set SO_NOSIGPIPE on socketpair/inet-simulated socketpair
implementations. eventfd and pipe() do not need/want it.

Closes #20397
This commit is contained in:
Stefan Eissing 2026-01-22 11:46:46 +01:00 committed by Daniel Stenberg
parent ef3101d181
commit 2a6ae3684e
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
3 changed files with 35 additions and 9 deletions

View file

@ -294,6 +294,15 @@ static CURLcode sock_assign_addr(struct Curl_sockaddr_ex *dest,
return CURLE_OK;
}
#ifdef USE_SO_NOSIGPIPE
int Curl_sock_nosigpipe(curl_socket_t sockfd)
{
int onoff = 1;
return setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE,
(void *)&onoff, sizeof(onoff));
}
#endif /* USE_SO_NOSIGPIPE */
static CURLcode socket_open(struct Curl_easy *data,
struct Curl_sockaddr_ex *addr,
curl_socket_t *sockfd)
@ -333,15 +342,12 @@ static CURLcode socket_open(struct Curl_easy *data,
}
#ifdef USE_SO_NOSIGPIPE
{
int onoff = 1;
if(setsockopt(*sockfd, SOL_SOCKET, SO_NOSIGPIPE,
(void *)&onoff, sizeof(onoff)) < 0) {
failf(data, "setsockopt enable SO_NOSIGPIPE: %s",
curlx_strerror(SOCKERRNO, errbuf, sizeof(errbuf)));
*sockfd = CURL_SOCKET_BAD;
return CURLE_COULDNT_CONNECT;
}
if(Curl_sock_nosigpipe(*sockfd) < 0) {
failf(data, "setsockopt enable SO_NOSIGPIPE: %s",
curlx_strerror(SOCKERRNO, errbuf, sizeof(errbuf)));
sclose(*sockfd);
*sockfd = CURL_SOCKET_BAD;
return CURLE_COULDNT_CONNECT;
}
#endif /* USE_SO_NOSIGPIPE */