]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: trace: define simple -dt argument
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 22 Nov 2023 13:58:59 +0000 (14:58 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 27 Nov 2023 16:10:18 +0000 (17:10 +0100)
Add '-dt' haproxy process argument. This will automatically activate all
trace sources on stderr with the error level. This could be useful to
troubleshoot issues such as protocol violations.

doc/management.txt
include/haproxy/trace.h
src/haproxy.c
src/trace.c

index b8916b31c8bd79be5d85eab30044eb1007d65935..2f106dbbdf7894a394d38f928532b92c812859ac 100644 (file)
@@ -402,6 +402,10 @@ list of options is :
     the libc fails to resolve an address, the startup sequence is not
     interrupted.
 
+  -dt : activate traces on stderr. This enables all trace sources on error
+    level. This can notably be useful to detect protocol violations from
+    clients or servers.
+
   -m <limit> : limit the total allocatable memory to <limit> megabytes across
     all processes. This may cause some connection refusals or some slowdowns
     depending on the amount of memory needed for normal operations. This is
index ad6995774d78e1557455469c714c3105708d37a4..e91b25dd46fe5f6f1afaca8dc0dab9b13d0f604c 100644 (file)
@@ -190,6 +190,8 @@ void trace_no_cb(enum trace_level level, uint64_t mask, const struct trace_sourc
 
 void trace_register_source(struct trace_source *source);
 
+int trace_parse_cmd();
+
 /* return a single char to describe a trace state */
 static inline char trace_state_char(enum trace_state st)
 {
index 900c897cd89c06b6822191f559f00864a08b8061..0d26ac103aa0040fd917914c729253e551d52f85 100644 (file)
 #include <haproxy/thread.h>
 #include <haproxy/time.h>
 #include <haproxy/tools.h>
+#include <haproxy/trace.h>
 #include <haproxy/uri_auth-t.h>
 #include <haproxy/vars.h>
 #include <haproxy/version.h>
@@ -588,6 +589,7 @@ static void usage(char *name)
                "        -v displays version ; -vv shows known build options.\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"
                "        -V enters verbose mode (disables quiet mode)\n"
                "        -D goes daemon ; -C changes to <dir> before loading files.\n"
                "        -W master-worker mode.\n"
@@ -1705,6 +1707,9 @@ static void init_args(int argc, char **argv)
                                arg_mode |= MODE_DUMP_KWD;
                                kwd_dump = flag + 2;
                        }
+                       else if (*flag == 'd' && flag[1] == 't') {
+                               trace_parse_cmd();
+                       }
                        else if (*flag == 'd')
                                arg_mode |= MODE_DEBUG;
                        else if (*flag == 'c' && flag[1] == 'c') {
index 990cd685150308eb5fd7a8d2e6154c02f8877d88..da27a8bf9e8dd97fb9c0b0ec813f140445a69c32 100644 (file)
@@ -731,6 +731,24 @@ static int trace_parse_statement(char **args, char **msg)
 
 }
 
+/* Parse a process argument specified via "-dt".
+ *
+ * Returns 0 on success else non-zero.
+ */
+int trace_parse_cmd()
+{
+       struct trace_source *src;
+
+       list_for_each_entry(src, &trace_sources, source_link) {
+               src->sink = sink_find("stderr");
+               src->level = TRACE_LEVEL_ERROR;
+               src->verbosity = 1;
+               src->state = TRACE_STATE_RUNNING;
+       }
+
+       return 0;
+}
+
 /* parse a "trace" statement in the "global" section, returns 1 if a message is returned, otherwise zero */
 static int cfg_parse_trace(char **args, int section_type, struct proxy *curpx,
                           const struct proxy *defpx, const char *file, int line,