File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ synopsis : Set FD_CLOEXEC on sockets created by curl
3+ issues : []
4+ prs : [12439]
5+ ---
6+
7+
8+ Curl creates sockets without setting FD_CLOEXEC/SOCK_CLOEXEC, this can cause connections to remain open forever when using commands like ` nix shell `
9+
10+ This change sets the FD_CLOEXEC flag using a CURLOPT_SOCKOPTFUNCTION callback.
Original file line number Diff line number Diff line change @@ -300,6 +300,14 @@ struct curlFileTransfer : public FileTransfer
300300 return ((TransferItem *) userp)->readCallback (buffer, size, nitems);
301301 }
302302
303+ #if !defined(_WIN32) && LIBCURL_VERSION_NUM >= 0x071000
304+ static int cloexec_callback (void *, curl_socket_t curlfd, curlsocktype purpose) {
305+ unix::closeOnExec (curlfd);
306+ vomit (" cloexec set for fd %i" , curlfd);
307+ return CURL_SOCKOPT_OK;
308+ }
309+ #endif
310+
303311 void init ()
304312 {
305313 if (!req) req = curl_easy_init ();
@@ -359,6 +367,10 @@ struct curlFileTransfer : public FileTransfer
359367 curl_easy_setopt (req, CURLOPT_SSL_VERIFYHOST, 0 );
360368 }
361369
370+ #if !defined(_WIN32) && LIBCURL_VERSION_NUM >= 0x071000
371+ curl_easy_setopt (req, CURLOPT_SOCKOPTFUNCTION, cloexec_callback);
372+ #endif
373+
362374 curl_easy_setopt (req, CURLOPT_CONNECTTIMEOUT, fileTransferSettings.connectTimeout .get ());
363375
364376 curl_easy_setopt (req, CURLOPT_LOW_SPEED_LIMIT, 1L );
You can’t perform that action at this time.
0 commit comments