diff --git a/dev/flags/flags.c b/dev/flags/flags.c index ac933e252..d867ba247 100644 --- a/dev/flags/flags.c +++ b/dev/flags/flags.c @@ -3,9 +3,10 @@ #include #include -#include +#include #include #include +#include #include #include @@ -22,10 +23,11 @@ #define SHOW_AS_HSL 0x00000200 #define SHOW_AS_HTX 0x00000400 #define SHOW_AS_HMSG 0x00000800 +#define SHOW_AS_FD 0x00001000 // command line names, must be in exact same order as the SHOW_AS_* flags above // so that show_as_words[i] matches flag 1U<flags = %s\n", (hsl_show_flags (buf, bsz, " | ", flags), buf)); if (show_as & SHOW_AS_HTX) printf("htx->flags = %s\n", (htx_show_flags (buf, bsz, " | ", flags), buf)); if (show_as & SHOW_AS_HMSG) printf("hmsg->flags = %s\n", (hmsg_show_flags (buf, bsz, " | ", flags), buf)); + if (show_as & SHOW_AS_FD) printf("fd->flags = %s\n", (fd_show_flags (buf, bsz, " | ", flags), buf)); } return 0; } diff --git a/include/haproxy/fd-t.h b/include/haproxy/fd-t.h index cecf797fe..b2ca87cb1 100644 --- a/include/haproxy/fd-t.h +++ b/include/haproxy/fd-t.h @@ -24,6 +24,7 @@ #include #include +#include /* Direction for each FD event update */ enum { @@ -112,6 +113,27 @@ enum { #define FD_EXCL_SYSCALL (1U << FD_EXCL_SYSCALL_BIT) #define FD_DISOWN (1U << FD_DISOWN_BIT) +/* This function is used to report flags in debugging tools. Please reflect + * below any single-bit flag addition above in the same order via the + * __APPEND_FLAG macro. The new end of the buffer is returned. + */ +static forceinline char *fd_show_flags(char *buf, size_t len, const char *delim, uint flg) +{ +#define _(f, ...) __APPEND_FLAG(buf, len, delim, flg, f, #f, __VA_ARGS__) + /* prologue */ + _(0); + /* flags */ + _(FD_EV_ACTIVE_R, _(FD_EV_ACTIVE_W, _(FD_EV_READY_R, _(FD_EV_READY_W, + _(FD_EV_SHUT_R, _(FD_EV_SHUT_W, _(FD_EV_ERR_RW, _(FD_POLL_IN, + _(FD_POLL_PRI, _(FD_POLL_OUT, _(FD_POLL_ERR, _(FD_POLL_HUP, + _(FD_LINGER_RISK, _(FD_CLONED, _(FD_INITIALIZED, _(FD_ET_POSSIBLE, + _(FD_EXPORTED, _(FD_EXCL_SYSCALL, _(FD_DISOWN))))))))))))))))))); + /* epilogue */ + _(~0U); + return buf; +#undef _ +} + /* FD update status after fd_update_events() */ enum { FD_UPDT_DONE = 0, // update done, nothing else to be done