From 670dc299d343f953425e325469dbdb352846e92f Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 5 Sep 2025 09:30:07 +0200 Subject: [PATCH] MINOR: trace: accept trace spec right after "-dt" on the command line I continue to mistakenly set the traces using "-dtXXX" and to have to refer to the doc to figure that it requires a separate argument and differs from some other options. Worse, "-dthelp" doesn't say anything and silently ignores the argument. Let's make the parser take whatever follows "-dt" as the argument if present, otherwise take the next one (as it currently does). Doing this even allows to simplify the code, and is easier to figure the syntax since "-dthelp" now works. --- src/haproxy.c | 36 +++++++++++++++++++----------------- src/trace.c | 2 +- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/haproxy.c b/src/haproxy.c index 350a43c64..5f89ddd79 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -697,7 +697,7 @@ static void usage(char *name) " -vq/-vqs/-vqb only displays version, short version, branch.\n" " -d enters debug mode ; -db only disables background mode.\n" " -dM[,help,...] debug memory (default: poison with /0x50)\n" - " -dt activate traces on stderr\n" + " -dt activate traces on stderr; see '-dt help'\n" " -V enters verbose mode (disables quiet mode)\n" " -D goes daemon ; -C changes to before loading files.\n" " -W master-worker mode.\n" @@ -1624,24 +1624,26 @@ static void init_args(int argc, char **argv) kwd_dump = flag + 2; } else if (*flag == 'd' && flag[1] == 't') { - if (argc > 1 && argv[1][0] != '-') { - int ret = trace_parse_cmd(argv[1], &err_msg); - if (ret <= -1) { - if (ret < -1) { - ha_alert("-dt: %s.\n", err_msg); - ha_free(&err_msg); - exit(EXIT_FAILURE); - } - else { - printf("%s\n", err_msg); - ha_free(&err_msg); - exit(0); - } - } + char *arg = flag + 2; + int ret; + + if (!*arg && argc > 1 && argv[1][0] != '-') { + arg = argv[1]; argc--; argv++; } - else { - trace_parse_cmd(NULL, NULL); + + ret = trace_parse_cmd(arg, &err_msg); + if (ret <= -1) { + if (ret < -1) { + ha_alert("-dt: %s.\n", err_msg); + ha_free(&err_msg); + exit(EXIT_FAILURE); + } + else { + printf("%s\n", err_msg); + ha_free(&err_msg); + exit(0); + } } } #ifdef HA_USE_KTLS diff --git a/src/trace.c b/src/trace.c index 026720a74..b2d763ebf 100644 --- a/src/trace.c +++ b/src/trace.c @@ -1008,7 +1008,7 @@ int trace_parse_cmd(const char *arg_src, char **errmsg) char *arg, *oarg; char *saveptr; - if (!arg_src) { + if (!arg_src || !*arg_src) { /* No trace specification, activate all sources on error level. */ struct trace_source *src = NULL;