From: Stefan Eissing Date: Wed, 7 Aug 2024 10:54:58 +0000 (+0200) Subject: tracing: allow CURL_DEBUG override X-Git-Tag: curl-8_10_0~332 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3ac1569c166de9156f7508db0cba8685456e6682;p=thirdparty%2Fcurl.git tracing: allow CURL_DEBUG override On debug builds, allow environment variable CURL_DEBUG to override any setting done via '-v' or '--no-verbose'. Closes #14436 --- diff --git a/docs/libcurl/libcurl-env-dbg.md b/docs/libcurl/libcurl-env-dbg.md index 2f4186939c..e20ebfacc9 100644 --- a/docs/libcurl/libcurl-env-dbg.md +++ b/docs/libcurl/libcurl-env-dbg.md @@ -64,6 +64,15 @@ Trace logging behavior as an alternative to calling curl_global_trace(3). Example: **CURL_DEBUG=http/2** means trace details about HTTP/2 handling. +In the curl command line tool, built with `--enable-debug`, this environment +variable adds to arguments like `--verbose`, `-vvv`. At least a single `-v` +is needed to make the run emit trace output, but when it does, the contents +of `CURL_DEBUG` are added and can override existing options. + +Example: **CURL_DEBUG=tcp,-http/2 curl -vv url** means trace protocol details, +triggered by `-vv`, add tracing of TCP in addition and remove tracing of +HTTP/2. + ## CURL_DEBUG_SIZE Fake the size returned by CURLINFO_HEADER_SIZE and CURLINFO_REQUEST_SIZE. diff --git a/lib/curl_trc.c b/lib/curl_trc.c index a45e07509f..3618275e5d 100644 --- a/lib/curl_trc.c +++ b/lib/curl_trc.c @@ -314,7 +314,7 @@ static void trc_apply_level_by_category(int category, int lvl) } } -CURLcode Curl_trc_opt(const char *config) +static CURLcode trc_opt(const char *config) { char *token, *tok_buf, *tmp; int lvl; @@ -355,18 +355,29 @@ CURLcode Curl_trc_opt(const char *config) return CURLE_OK; } -CURLcode Curl_trc_init(void) +CURLcode Curl_trc_opt(const char *config) { + CURLcode result = config? trc_opt(config) : CURLE_OK; #ifdef DEBUGBUILD - /* WIP: we use the auto-init from an env var only in DEBUG builds for - * convenience. */ - const char *config = getenv("CURL_DEBUG"); - if(config) { - return Curl_trc_opt(config); + /* CURL_DEBUG can override anything */ + if(!result) { + const char *dbg_config = getenv("CURL_DEBUG"); + if(dbg_config) + result = trc_opt(dbg_config); } #endif /* DEBUGBUILD */ + return result; +} + +CURLcode Curl_trc_init(void) +{ +#ifdef DEBUGBUILD + return Curl_trc_opt(NULL); +#else return CURLE_OK; +#endif } + #else /* defined(CURL_DISABLE_VERBOSE_STRINGS) */ CURLcode Curl_trc_init(void)