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.
This commit is contained in:
Willy Tarreau 2025-09-05 09:30:07 +02:00
parent abfd6f3b93
commit 670dc299d3
2 changed files with 20 additions and 18 deletions

View File

@ -697,7 +697,7 @@ static void usage(char *name)
" -vq/-vqs/-vqb only displays version, short version, branch.\n" " -vq/-vqs/-vqb only displays version, short version, branch.\n"
" -d enters debug mode ; -db only disables background mode.\n" " -d enters debug mode ; -db only disables background mode.\n"
" -dM[<byte>,help,...] debug memory (default: poison with <byte>/0x50)\n" " -dM[<byte>,help,...] debug memory (default: poison with <byte>/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" " -V enters verbose mode (disables quiet mode)\n"
" -D goes daemon ; -C changes to <dir> before loading files.\n" " -D goes daemon ; -C changes to <dir> before loading files.\n"
" -W master-worker mode.\n" " -W master-worker mode.\n"
@ -1624,24 +1624,26 @@ static void init_args(int argc, char **argv)
kwd_dump = flag + 2; kwd_dump = flag + 2;
} }
else if (*flag == 'd' && flag[1] == 't') { else if (*flag == 'd' && flag[1] == 't') {
if (argc > 1 && argv[1][0] != '-') { char *arg = flag + 2;
int ret = trace_parse_cmd(argv[1], &err_msg); int ret;
if (ret <= -1) {
if (ret < -1) { if (!*arg && argc > 1 && argv[1][0] != '-') {
ha_alert("-dt: %s.\n", err_msg); arg = argv[1];
ha_free(&err_msg);
exit(EXIT_FAILURE);
}
else {
printf("%s\n", err_msg);
ha_free(&err_msg);
exit(0);
}
}
argc--; argv++; 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 #ifdef HA_USE_KTLS

View File

@ -1008,7 +1008,7 @@ int trace_parse_cmd(const char *arg_src, char **errmsg)
char *arg, *oarg; char *arg, *oarg;
char *saveptr; char *saveptr;
if (!arg_src) { if (!arg_src || !*arg_src) {
/* No trace specification, activate all sources on error level. */ /* No trace specification, activate all sources on error level. */
struct trace_source *src = NULL; struct trace_source *src = NULL;