Re: [LTP] [PATCH v2 3/3] lib: Prefer LTP_DEBUG over -D

Li Wang via ltp
2026-03-27T03:46:10Z

On Thu, Mar 26, 2026 at 06:04:35PM +0100, Petr Vorel wrote:
> Environment variable has usually higher preference than getopt.
> Also document it.
>
> Fixes: e434de62b4 ("lib: Extend LTP_ENABLE_DEBUG to support verbosity levels")
> Signed-off-by: Petr Vorel <pvorel@suse.cz>

Reviewed-by: Li Wang <liwang@redhat.com>

> @@ -825,13 +825,15 @@ static void parse_opts(int argc, char *argv[])
> tst_brk(TBROK, "Invalid option");
> break;
> case 'D':
> - if (optarg)
> - context->tdebug = SAFE_STRTOL(optarg, 1, 2);
> - else
> - context->tdebug = 1;
> -
> - if (context->tdebug)
> - tst_res(TINFO, "Enabling debug info (level %d)", context->tdebug);
> + if (!getenv("LTP_DEBUG")) {

My preference is to shorten the code indentation:

case 'D':
if (getenv("LTP_DEBUG"))
break;

context->tdebug = optarg ? SAFE_STRTOL(optarg, 1, 2) : 1;

if (context->tdebug)
tst_res(TINFO, "Enabling debug info (level %d)", context->tdebug);
break;

> + if (optarg)
> + context->tdebug = SAFE_STRTOL(optarg, 1, 2);
> + else
> + context->tdebug = 1;
> +
> + if (context->tdebug)
> + tst_res(TINFO, "Enabling debug info (level %d)", context->tdebug);
> + }
> break;
> case 'h':
> print_help();
> --
> 2.53.0
>

--
Regards,
Li Wang