]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: applet: Change return value for .init callback function
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 12 May 2022 09:52:27 +0000 (11:52 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 17 May 2022 14:13:21 +0000 (16:13 +0200)
0 is now returned on success and -1 on error.

addons/promex/service-prometheus.c
include/haproxy/applet-t.h
src/hlua.c

index 8422e54f6902dfc0506893343b74681fe630ef84..9501b1c09cddc797e67ef55a9ac098d1950953ff 100644 (file)
@@ -1497,7 +1497,7 @@ static int promex_appctx_init(struct appctx *appctx)
 {
        applet_reserve_svcctx(appctx, sizeof(struct promex_ctx));
        appctx->st0 = PROMEX_ST_INIT;
-       return 1;
+       return 0;
 }
 
 /* The main I/O handler for the promex applet. */
index 2784650d9b8ee178ccafa8d969d9288aea9d81e1..8e7eddb8cda09993ea06518a360237a0197484eb 100644 (file)
@@ -46,8 +46,8 @@ struct applet {
        enum obj_type obj_type;            /* object type = OBJ_TYPE_APPLET */
        /* 3 unused bytes here */
        char *name;                        /* applet's name to report in logs */
-       int (*init)(struct appctx *);   /* callback to init resources, may be NULL.
-                                            expect 1 if ok, 0 if an error occurs, -1 if miss data. */
+       int (*init)(struct appctx *);      /* callback to init resources, may be NULL.
+                                             expect 0 if ok, -1 if an error occurs. */
        void (*fct)(struct appctx *);      /* internal I/O handler, may never be NULL */
        void (*release)(struct appctx *);  /* callback to release resources, may be NULL */
        unsigned int timeout;              /* execution timeout. */
index 193956a91a71e12cf4b9d4552c3a4a09e2021c66..e323b9afa251715469cdfc3f822c89c3e705a0c6 100644 (file)
@@ -9226,7 +9226,7 @@ static int hlua_applet_tcp_init(struct appctx *ctx)
        if (!hlua) {
                SEND_ERR(strm->be, "Lua applet tcp '%s': out of memory.\n",
                         ctx->rule->arg.hlua_rule->fcn->name);
-               return 0;
+               return -1;
        }
        HLUA_INIT(hlua);
        tcp_ctx->hlua = hlua;
@@ -9237,7 +9237,7 @@ static int hlua_applet_tcp_init(struct appctx *ctx)
        if (!task) {
                SEND_ERR(strm->be, "Lua applet tcp '%s': out of memory.\n",
                         ctx->rule->arg.hlua_rule->fcn->name);
-               return 0;
+               return -1;
        }
        task->nice = 0;
        task->context = ctx;
@@ -9252,7 +9252,7 @@ static int hlua_applet_tcp_init(struct appctx *ctx)
        if (!hlua_ctx_init(hlua, fcn_ref_to_stack_id(ctx->rule->arg.hlua_rule->fcn), task, 0)) {
                SEND_ERR(strm->be, "Lua applet tcp '%s': can't initialize Lua context.\n",
                         ctx->rule->arg.hlua_rule->fcn->name);
-               return 0;
+               return -1;
        }
 
        /* Set timeout according with the applet configuration. */
@@ -9266,7 +9266,7 @@ static int hlua_applet_tcp_init(struct appctx *ctx)
                        error = "critical error";
                SEND_ERR(strm->be, "Lua applet tcp '%s': %s.\n",
                         ctx->rule->arg.hlua_rule->fcn->name, error);
-               return 0;
+               return -1;
        }
 
        /* Check stack available size. */
@@ -9274,7 +9274,7 @@ static int hlua_applet_tcp_init(struct appctx *ctx)
                SEND_ERR(strm->be, "Lua applet tcp '%s': full stack.\n",
                         ctx->rule->arg.hlua_rule->fcn->name);
                RESET_SAFE_LJMP(hlua);
-               return 0;
+               return -1;
        }
 
        /* Restore the function in the stack. */
@@ -9285,7 +9285,7 @@ static int hlua_applet_tcp_init(struct appctx *ctx)
                SEND_ERR(strm->be, "Lua applet tcp '%s': full stack.\n",
                         ctx->rule->arg.hlua_rule->fcn->name);
                RESET_SAFE_LJMP(hlua);
-               return 0;
+               return -1;
        }
        hlua->nargs = 1;
 
@@ -9295,7 +9295,7 @@ static int hlua_applet_tcp_init(struct appctx *ctx)
                        SEND_ERR(strm->be, "Lua applet tcp '%s': full stack.\n",
                                 ctx->rule->arg.hlua_rule->fcn->name);
                        RESET_SAFE_LJMP(hlua);
-                       return 0;
+                       return -1;
                }
                lua_pushstring(hlua->T, *arg);
                hlua->nargs++;
@@ -9307,7 +9307,7 @@ static int hlua_applet_tcp_init(struct appctx *ctx)
        cs_cant_get(cs);
        cs_rx_endp_more(cs);
 
-       return 1;
+       return 0;
 }
 
 void hlua_applet_tcp_fct(struct appctx *ctx)
@@ -9400,9 +9400,8 @@ static void hlua_applet_tcp_release(struct appctx *ctx)
        tcp_ctx->hlua = NULL;
 }
 
-/* The function returns 1 if the initialisation is complete, 0 if
- * an errors occurs and -1 if more data are required for initializing
- * the applet. It also reserves the appctx for an hlua_http_ctx.
+/* The function returns 0 if the initialisation is complete or -1 if
+ * an errors occurs. It also reserves the appctx for an hlua_http_ctx.
  */
 static int hlua_applet_http_init(struct appctx *ctx)
 {
@@ -9420,7 +9419,7 @@ static int hlua_applet_http_init(struct appctx *ctx)
        if (!hlua) {
                SEND_ERR(strm->be, "Lua applet http '%s': out of memory.\n",
                         ctx->rule->arg.hlua_rule->fcn->name);
-               return 0;
+               return -1;
        }
        HLUA_INIT(hlua);
        http_ctx->hlua = hlua;
@@ -9435,7 +9434,7 @@ static int hlua_applet_http_init(struct appctx *ctx)
        if (!task) {
                SEND_ERR(strm->be, "Lua applet http '%s': out of memory.\n",
                         ctx->rule->arg.hlua_rule->fcn->name);
-               return 0;
+               return -1;
        }
        task->nice = 0;
        task->context = ctx;
@@ -9450,7 +9449,7 @@ static int hlua_applet_http_init(struct appctx *ctx)
        if (!hlua_ctx_init(hlua, fcn_ref_to_stack_id(ctx->rule->arg.hlua_rule->fcn), task, 0)) {
                SEND_ERR(strm->be, "Lua applet http '%s': can't initialize Lua context.\n",
                         ctx->rule->arg.hlua_rule->fcn->name);
-               return 0;
+               return -1;
        }
 
        /* Set timeout according with the applet configuration. */
@@ -9464,7 +9463,7 @@ static int hlua_applet_http_init(struct appctx *ctx)
                        error = "critical error";
                SEND_ERR(strm->be, "Lua applet http '%s': %s.\n",
                         ctx->rule->arg.hlua_rule->fcn->name, error);
-               return 0;
+               return -1;
        }
 
        /* Check stack available size. */
@@ -9472,7 +9471,7 @@ static int hlua_applet_http_init(struct appctx *ctx)
                SEND_ERR(strm->be, "Lua applet http '%s': full stack.\n",
                         ctx->rule->arg.hlua_rule->fcn->name);
                RESET_SAFE_LJMP(hlua);
-               return 0;
+               return -1;
        }
 
        /* Restore the function in the stack. */
@@ -9483,7 +9482,7 @@ static int hlua_applet_http_init(struct appctx *ctx)
                SEND_ERR(strm->be, "Lua applet http '%s': full stack.\n",
                         ctx->rule->arg.hlua_rule->fcn->name);
                RESET_SAFE_LJMP(hlua);
-               return 0;
+               return -1;
        }
        hlua->nargs = 1;
 
@@ -9493,7 +9492,7 @@ static int hlua_applet_http_init(struct appctx *ctx)
                        SEND_ERR(strm->be, "Lua applet http '%s': full stack.\n",
                                 ctx->rule->arg.hlua_rule->fcn->name);
                        RESET_SAFE_LJMP(hlua);
-                       return 0;
+                       return -1;
                }
                lua_pushstring(hlua->T, *arg);
                hlua->nargs++;
@@ -9504,7 +9503,7 @@ static int hlua_applet_http_init(struct appctx *ctx)
        /* Wakeup the applet when data is ready for read. */
        cs_cant_get(cs);
 
-       return 1;
+       return 0;
 }
 
 void hlua_applet_http_fct(struct appctx *ctx)