]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: applet: Emit a warning when a legacy applet is spawned
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 25 Jul 2025 13:44:47 +0000 (15:44 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 25 Jul 2025 13:53:33 +0000 (15:53 +0200)
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
src/applet.c

index adeb9da12f6adc74a41ca2720034d9e9968cd995..8b31e02bcac991e93146bb7ac37d85e9f6550738 100644 (file)
@@ -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 {
index 1cd10e0382b099b46378ee1591b760345b2221d0..6bfff12de22df05c2284893afe6f84ed436e3547 100644 (file)
@@ -19,6 +19,7 @@
 #include <haproxy/channel.h>
 #include <haproxy/htx.h>
 #include <haproxy/list.h>
+#include <haproxy/log.h>
 #include <haproxy/sc_strm.h>
 #include <haproxy/stconn.h>
 #include <haproxy/stream.h>
@@ -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);