diff --git a/include/haproxy/tools.h b/include/haproxy/tools.h index 2e266621d..22a20a856 100644 --- a/include/haproxy/tools.h +++ b/include/haproxy/tools.h @@ -1540,4 +1540,6 @@ void ha_freearray(char ***array); void ha_memset_s(void *s, int c, size_t n); +void chunk_append_thread_ctx(struct buffer *output, const struct thread_exec_ctx *ctx, const char *pfx, const char *sfx); + #endif /* _HAPROXY_TOOLS_H */ diff --git a/src/tools.c b/src/tools.c index cdbf7e201..f6e1d273b 100644 --- a/src/tools.c +++ b/src/tools.c @@ -7502,6 +7502,28 @@ void ha_memset_s(void *s, int c, size_t n) __asm__ __volatile__("" : : "r"(s) : "memory"); } +/* Optionally appends the thread execution context as a string to the output, + * prefixed with and suffixed with if not NULL and only when the + * context type is not TH_EX_CTX_NONE. Otherwise it does nothing and leaves the + * chunk untouched. + */ +void chunk_append_thread_ctx(struct buffer *output, const struct thread_exec_ctx *ctx, const char *pfx, const char *sfx) +{ + if (!ctx->type) + return; + + chunk_appendf(output,"%s", pfx ? pfx : ""); + + switch (ctx->type) { + default: + chunk_appendf(output,"other ctx %p", ctx->pointer); + break; + } + + chunk_appendf(output,"%s", sfx ? sfx : ""); +} + + /* * Local variables: * c-indent-level: 8