From c8bc624553801e80f2e54e76b276d71a95eb6d5e Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 29 Oct 2012 00:45:20 -0700 Subject: [PATCH] - client, Unix: make Curl sockets close-on-exec, so that app processes don't inherit them. - client: fix bug that makes client exit if a slot dir contains finish file on startup --- checkin_notes | 10 ++++++++++ client/app_control.cpp | 1 + client/http_curl.cpp | 15 +++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/checkin_notes b/checkin_notes index fe6708b68e..e76a6b4cca 100644 --- a/checkin_notes +++ b/checkin_notes @@ -6428,3 +6428,13 @@ David 28 Oct 2012 client/ app.cpp app_control.cpp + +David 28 Oct 2012 + - client, Unix: make Curl sockets close-on-exec, + so that app processes don't inherit them. + - client: fix bug that makes client exit if a slot dir contains + finish file on startup + + client/ + app_control.cpp + http_curl.cpp diff --git a/client/app_control.cpp b/client/app_control.cpp index c0875689ab..86e6d35b4e 100644 --- a/client/app_control.cpp +++ b/client/app_control.cpp @@ -129,6 +129,7 @@ bool ACTIVE_TASK_SET::poll() { last_finish_check_time = gstate.now; for (i=0; itask_state() == PROCESS_UNINITIALIZED) continue; if (atp->finish_file_time) { atp->kill_task(false); } else if (atp->finish_file_present()) { diff --git a/client/http_curl.cpp b/client/http_curl.cpp index 0add2af084..01af8bebab 100644 --- a/client/http_curl.cpp +++ b/client/http_curl.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #if HAVE_SYS_SOCKET_H #include #endif @@ -387,6 +388,14 @@ bool HTTP_OP::no_proxy_for_url(const char* url) { return false; } +static int set_cloexec(void*, curl_socket_t fd, curlsocktype purpose) { +#ifndef _WIN32 + if (purpose != CURLSOCKTYPE_IPCXN) return 0; + fcntl(fd, F_SETFD, FD_CLOEXEC); +#endif + return 0; +} + // the following will do an HTTP GET or POST using libcurl // int HTTP_OP::libcurl_exec( @@ -520,10 +529,16 @@ int HTTP_OP::libcurl_exec( // bypass any signal handlers that curl may want to install // curl_easy_setopt(curlEasy, CURLOPT_NOSIGNAL, 1L); + // bypass progress meter // curl_easy_setopt(curlEasy, CURLOPT_NOPROGRESS, 1L); + // arrange for a function to get called between socket() and connect() + // so that we can mark the socket as close-on-exec + // + curl_easy_setopt(curlEasy, CURLOPT_SOCKOPTFUNCTION, set_cloexec); + // setup timeouts // curl_easy_setopt(curlEasy, CURLOPT_TIMEOUT, 0L);