From cef29d3708a57ffe99de1932a7ab13910e683eed Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Wed, 22 Nov 2023 14:58:59 +0100 Subject: [PATCH] MINOR: trace: define simple -dt argument 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 | 4 ++++ include/haproxy/trace.h | 2 ++ src/haproxy.c | 5 +++++ src/trace.c | 18 ++++++++++++++++++ 4 files changed, 29 insertions(+) diff --git a/doc/management.txt b/doc/management.txt index b8916b31c8..2f106dbbdf 100644 --- a/doc/management.txt +++ b/doc/management.txt @@ -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 the total allocatable memory to 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 diff --git a/include/haproxy/trace.h b/include/haproxy/trace.h index ad6995774d..e91b25dd46 100644 --- a/include/haproxy/trace.h +++ b/include/haproxy/trace.h @@ -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) { diff --git a/src/haproxy.c b/src/haproxy.c index 900c897cd8..0d26ac103a 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -124,6 +124,7 @@ #include #include #include +#include #include #include #include @@ -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[,help,...] debug memory (default: poison with /0x50)\n" + " -dt activate traces on stderr\n" " -V enters verbose mode (disables quiet mode)\n" " -D goes daemon ; -C changes to 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') { diff --git a/src/trace.c b/src/trace.c index 990cd68515..da27a8bf9e 100644 --- a/src/trace.c +++ b/src/trace.c @@ -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,