summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-04-01 18:53:58 +0200
committerThomas Haller <thaller@redhat.com>2022-04-01 19:02:06 +0200
commit4c9a89140b05a15e5ed4cd617bb9e48461f851ed (patch)
treeb0e072077bea70c055ec468c2729cd25aca7180d
parenteff551004085ed03250c43ebe113a57b2a0f8f2a (diff)
downloadNetworkManager-th/connectivity-resolve.tar.gz
connectivity: only enable verbose libcurl debug logging with "NM_LOG_CONCHECK" environmentth/connectivity-resolve
For regular operation -- even for `level=TRACE` -- it's just too verbose. Only enable it if the environment "NM_LOG_CONCHECK=1" is set. An environment variable is a bit unwieldy to use, but this is really just for a heavy libcurl debugging session.
-rw-r--r--src/core/nm-connectivity.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/core/nm-connectivity.c b/src/core/nm-connectivity.c
index 57722d6ac3..8373867f10 100644
--- a/src/core/nm-connectivity.c
+++ b/src/core/nm-connectivity.c
@@ -623,6 +623,25 @@ _timeout_cb(gpointer user_data)
return G_SOURCE_REMOVE;
}
+static gboolean
+easy_debug_enabled(void)
+{
+ static int enabled = 0;
+ int e;
+
+ /* libcurl debug logging can be useful, but is very verbose.
+ * Only enable it when we have a certain environment variable set. */
+
+again:
+ e = g_atomic_int_get(&enabled);
+ if (G_UNLIKELY(e == 0)) {
+ e = _nm_utils_ascii_str_to_bool(g_getenv("NM_LOG_CONCHECK"), FALSE) ? 1 : -1;
+ if (G_UNLIKELY(!g_atomic_int_compare_and_exchange(&enabled, 0, e)))
+ goto again;
+ }
+ return e >= 0;
+}
+
static int
easy_debug_cb(CURL *handle, curl_infotype type, char *data, size_t size, void *userptr)
{
@@ -750,7 +769,7 @@ do_curl_request(NMConnectivityCheckHandle *cb_data, const char *hosts)
curl_easy_setopt(ehandle, CURLOPT_RESOLVE, cb_data->concheck.hosts);
curl_easy_setopt(ehandle, CURLOPT_IPRESOLVE, resolve);
curl_easy_setopt(ehandle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
- if (_LOGT_ENABLED()) {
+ if (_LOGT_ENABLED() && easy_debug_enabled()) {
curl_easy_setopt(ehandle, CURLOPT_DEBUGFUNCTION, easy_debug_cb);
curl_easy_setopt(ehandle, CURLOPT_DEBUGDATA, cb_data);
curl_easy_setopt(ehandle, CURLOPT_VERBOSE, 1L);