From b8d5307bd9b34e0f13012ba4e656c01e1d273c27 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Fri, 25 Jul 2025 15:44:47 +0200 Subject: [PATCH] MEDIUM: applet: Emit a warning when a legacy applet is spawned To motivate developers to support the new applets API, a warning is now emitted when a legacy applet is spawned. To not flood users, this warning is only emitted once per legacy applet. To do so, the applet flag APPLET_FL_WARNED was added. It is set when the warning is emitted. Note that test and set on this flag are not performed via atomic operations. So it is possible to have more than one warning for a given applet if it is spawned in same time on several threads. At worrst, there is one warning per thread. --- include/haproxy/applet-t.h | 1 + src/applet.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/include/haproxy/applet-t.h b/include/haproxy/applet-t.h index adeb9da12..8b31e02bc 100644 --- a/include/haproxy/applet-t.h +++ b/include/haproxy/applet-t.h @@ -82,6 +82,7 @@ static forceinline char *appctx_show_flags(char *buf, size_t len, const char *de } #define APPLET_FL_NEW_API 0x00000001 /* Set if the applet is based on the new API (using applet's buffers) */ +#define APPLET_FL_WARNED 0x00000002 /* Set when warning was already emitted about a legacy applet */ /* Applet descriptor */ struct applet { diff --git a/src/applet.c b/src/applet.c index 1cd10e038..6bfff12de 100644 --- a/src/applet.c +++ b/src/applet.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -232,6 +233,13 @@ struct appctx *appctx_new_on(struct applet *applet, struct sedesc *sedesc, int t TRACE_ENTER(APPLET_EV_NEW); + if (unlikely(!(applet->flags & (APPLET_FL_NEW_API|APPLET_FL_WARNED)))) { + send_log(NULL, LOG_WARNING, + "Applet '%s' is based on a deprecated API. Please report this error to developers\n", + applet->name); + applet->flags |= APPLET_FL_WARNED; + } + appctx = pool_zalloc(pool_head_appctx); if (unlikely(!appctx)) { TRACE_ERROR("APPCTX allocation failure", APPLET_EV_NEW|APPLET_EV_ERR); -- 2.47.2