]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: applet: Add appctx_init() helper fnuction
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 12 May 2022 12:59:28 +0000 (14:59 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 17 May 2022 14:13:21 +0000 (16:13 +0200)
It is just a helper function that call the .init applet callback function,
if it exists. This will simplify a bit the init stage when a new applet is
started. For now, this callback function is only used when a new service is
started.

include/haproxy/applet.h
src/stream.c

index 2ee368b83114108509e66eae4880b540d31857b7..bef5aa5e603181258e3cde497f105e5d15313870 100644 (file)
@@ -42,6 +42,16 @@ void appctx_shut(struct appctx *appctx);
 
 struct appctx *appctx_new(struct applet *applet, struct cs_endpoint *endp);
 
+/* Helper function to call .init applet callback function, if it exists. Returns 0
+ * on success and -1 on error.
+ */
+static inline int appctx_init(struct appctx *appctx)
+{
+       if (appctx->applet->init)
+               return appctx->applet->init(appctx);
+       return 0;
+}
+
 /* Releases an appctx previously allocated by appctx_new(). */
 static inline void __appctx_free(struct appctx *appctx)
 {
index dd3358e48588ac1d62a068d013502304b56b8ee7..29d1a60b56169aa58a4aa1f4212ff16490691313 100644 (file)
@@ -997,9 +997,8 @@ enum act_return process_use_service(struct act_rule *rule, struct proxy *px,
                        return ACT_RET_ERR;
 
                /* Finish initialisation of the context. */
-               memset(&appctx->ctx, 0, sizeof(appctx->ctx));
                appctx->rule = rule;
-               if (appctx->applet->init && !appctx->applet->init(appctx))
+               if (appctx_init(appctx) == -1)
                        return ACT_RET_ERR;
        }
        else