]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: trace: accept trace spec right after "-dt" on the command line
authorWilly Tarreau <w@1wt.eu>
Fri, 5 Sep 2025 07:30:07 +0000 (09:30 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 5 Sep 2025 07:33:28 +0000 (09:33 +0200)
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
src/trace.c

index 350a43c64f94580b618c6a086e942efad853738c..5f89ddd7940b669e24bfd7e75b8830eccfa89e23 100644 (file)
@@ -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[<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"
                "        -D goes daemon ; -C changes to <dir> 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
index 026720a74b1ac12074eb4662233d7ec6c6ffb49b..b2d763ebf32845b0774b65e214dd41468e16a48c 100644 (file)
@@ -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;