Skip to content

Commit 670dc29

Browse files
committed
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.
1 parent abfd6f3 commit 670dc29

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

src/haproxy.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ static void usage(char *name)
697697
" -vq/-vqs/-vqb only displays version, short version, branch.\n"
698698
" -d enters debug mode ; -db only disables background mode.\n"
699699
" -dM[<byte>,help,...] debug memory (default: poison with <byte>/0x50)\n"
700-
" -dt activate traces on stderr\n"
700+
" -dt activate traces on stderr; see '-dt help'\n"
701701
" -V enters verbose mode (disables quiet mode)\n"
702702
" -D goes daemon ; -C changes to <dir> before loading files.\n"
703703
" -W master-worker mode.\n"
@@ -1624,24 +1624,26 @@ static void init_args(int argc, char **argv)
16241624
kwd_dump = flag + 2;
16251625
}
16261626
else if (*flag == 'd' && flag[1] == 't') {
1627-
if (argc > 1 && argv[1][0] != '-') {
1628-
int ret = trace_parse_cmd(argv[1], &err_msg);
1629-
if (ret <= -1) {
1630-
if (ret < -1) {
1631-
ha_alert("-dt: %s.\n", err_msg);
1632-
ha_free(&err_msg);
1633-
exit(EXIT_FAILURE);
1634-
}
1635-
else {
1636-
printf("%s\n", err_msg);
1637-
ha_free(&err_msg);
1638-
exit(0);
1639-
}
1640-
}
1627+
char *arg = flag + 2;
1628+
int ret;
1629+
1630+
if (!*arg && argc > 1 && argv[1][0] != '-') {
1631+
arg = argv[1];
16411632
argc--; argv++;
16421633
}
1643-
else {
1644-
trace_parse_cmd(NULL, NULL);
1634+
1635+
ret = trace_parse_cmd(arg, &err_msg);
1636+
if (ret <= -1) {
1637+
if (ret < -1) {
1638+
ha_alert("-dt: %s.\n", err_msg);
1639+
ha_free(&err_msg);
1640+
exit(EXIT_FAILURE);
1641+
}
1642+
else {
1643+
printf("%s\n", err_msg);
1644+
ha_free(&err_msg);
1645+
exit(0);
1646+
}
16451647
}
16461648
}
16471649
#ifdef HA_USE_KTLS

src/trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ int trace_parse_cmd(const char *arg_src, char **errmsg)
10081008
char *arg, *oarg;
10091009
char *saveptr;
10101010

1011-
if (!arg_src) {
1011+
if (!arg_src || !*arg_src) {
10121012
/* No trace specification, activate all sources on error level. */
10131013
struct trace_source *src = NULL;
10141014

0 commit comments

Comments
 (0)