mirror of
https://github.com/NixOS/nix
synced 2025-06-25 06:31:14 +02:00
Set FD_CLOEXEC on sockets created by curl
Curl creates sockets without setting FD_CLOEXEC/SOCK_CLOEXEC, this can
cause connections to remain open forever when using commands like `nix
shell`
This change sets the FD_CLOEXEC flag using a CURLOPT_SOCKOPTFUNCTION
callback.
(cherry picked from commit 12d2527276
)
This commit is contained in:
parent
029dd96b8b
commit
cd149b56c7
2 changed files with 22 additions and 0 deletions
10
doc/manual/rl-next/curl-cloexec.md
Normal file
10
doc/manual/rl-next/curl-cloexec.md
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
---
|
||||||
|
synopsis: Set FD_CLOEXEC on sockets created by curl
|
||||||
|
issues: []
|
||||||
|
prs: [12439]
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
Curl creates sockets without setting FD_CLOEXEC/SOCK_CLOEXEC, this can cause connections to remain open forever when using commands like `nix shell`
|
||||||
|
|
||||||
|
This change sets the FD_CLOEXEC flag using a CURLOPT_SOCKOPTFUNCTION callback.
|
|
@ -300,6 +300,14 @@ struct curlFileTransfer : public FileTransfer
|
||||||
return ((TransferItem *) userp)->readCallback(buffer, size, nitems);
|
return ((TransferItem *) userp)->readCallback(buffer, size, nitems);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(_WIN32) && LIBCURL_VERSION_NUM >= 0x071000
|
||||||
|
static int cloexec_callback(void *, curl_socket_t curlfd, curlsocktype purpose) {
|
||||||
|
unix::closeOnExec(curlfd);
|
||||||
|
vomit("cloexec set for fd %i", curlfd);
|
||||||
|
return CURL_SOCKOPT_OK;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
if (!req) req = curl_easy_init();
|
if (!req) req = curl_easy_init();
|
||||||
|
@ -359,6 +367,10 @@ struct curlFileTransfer : public FileTransfer
|
||||||
curl_easy_setopt(req, CURLOPT_SSL_VERIFYHOST, 0);
|
curl_easy_setopt(req, CURLOPT_SSL_VERIFYHOST, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(_WIN32) && LIBCURL_VERSION_NUM >= 0x071000
|
||||||
|
curl_easy_setopt(req, CURLOPT_SOCKOPTFUNCTION, cloexec_callback);
|
||||||
|
#endif
|
||||||
|
|
||||||
curl_easy_setopt(req, CURLOPT_CONNECTTIMEOUT, fileTransferSettings.connectTimeout.get());
|
curl_easy_setopt(req, CURLOPT_CONNECTTIMEOUT, fileTransferSettings.connectTimeout.get());
|
||||||
|
|
||||||
curl_easy_setopt(req, CURLOPT_LOW_SPEED_LIMIT, 1L);
|
curl_easy_setopt(req, CURLOPT_LOW_SPEED_LIMIT, 1L);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue