Skip to content

Commit b3839e7

Browse files
committed
BUG/MEDIUM: hlua/cli: Fix lua CLI commands to work with applet's buffers
In 3.0, the CLI applet was rewritten to use its own buffers. However, the lua part, used to register CLI commands at runtime, was not updated accordingly. It means the lua CLI commands still try to write in the channel buffers. This is of course totally unexepected and not supported. Because of this bug, the applet hangs intead of returning the command result. The registration of lua CLI commands relies on the lua TCP applets. So the send and receive functions were fixed to use the applet's buffer when it is required and still use the channel buffers otherwies. This way, other lua TCP applets can still run on the legacy mode, without the applet's buffers. This patch must be backported to 3.0. (cherry picked from commit e5e36ce) Signed-off-by: Christopher Faulet <[email protected]>
1 parent 93097de commit b3839e7

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

src/hlua.c

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5273,7 +5273,10 @@ __LJMP static int hlua_applet_tcp_recv_yield(lua_State *L, int status, lua_KCont
52735273
size_t len2;
52745274

52755275
/* Read the maximum amount of data available. */
5276-
ret = co_getblk_nc(sc_oc(sc), &blk1, &len1, &blk2, &len2);
5276+
if (luactx->appctx->flags & APPCTX_FL_INOUT_BUFS)
5277+
ret = b_getblk_nc(&luactx->appctx->inbuf, &blk1, &len1, &blk2, &len2, 0, b_data(&luactx->appctx->inbuf));
5278+
else
5279+
ret = co_getblk_nc(sc_oc(sc), &blk1, &len1, &blk2, &len2);
52775280

52785281
/* Data not yet available. return yield. */
52795282
if (ret == 0) {
@@ -5299,7 +5302,10 @@ __LJMP static int hlua_applet_tcp_recv_yield(lua_State *L, int status, lua_KCont
52995302
*/
53005303
luaL_addlstring(&luactx->b, blk1, len1);
53015304
luaL_addlstring(&luactx->b, blk2, len2);
5302-
co_skip(sc_oc(sc), len1 + len2);
5305+
if (luactx->appctx->flags & APPCTX_FL_INOUT_BUFS)
5306+
b_del(&luactx->appctx->inbuf, len1 + len2);
5307+
else
5308+
co_skip(sc_oc(sc), len1 + len2);
53035309
applet_need_more_data(luactx->appctx);
53045310
MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_tcp_recv_yield, TICK_ETERNITY, 0));
53055311

@@ -5317,8 +5323,10 @@ __LJMP static int hlua_applet_tcp_recv_yield(lua_State *L, int status, lua_KCont
53175323
luaL_addlstring(&luactx->b, blk2, len2);
53185324
len -= len2;
53195325

5320-
/* Consume input channel output buffer data. */
5321-
co_skip(sc_oc(sc), len1 + len2);
5326+
if (luactx->appctx->flags & APPCTX_FL_INOUT_BUFS)
5327+
b_del(&luactx->appctx->inbuf, len1 + len2);
5328+
else
5329+
co_skip(sc_oc(sc), len1 + len2);
53225330

53235331
/* If there is no other data available, yield waiting for new data. */
53245332
if (len > 0) {
@@ -5376,13 +5384,17 @@ __LJMP static int hlua_applet_tcp_send_yield(lua_State *L, int status, lua_KCont
53765384
struct channel *chn = sc_ic(sc);
53775385
int max;
53785386

5379-
/* Get the max amount of data which can write as input in the channel. */
5380-
max = channel_recv_max(chn);
5387+
/* Get the max amount of data which can be written */
5388+
if (luactx->appctx->flags & APPCTX_FL_INOUT_BUFS)
5389+
max = b_room(&luactx->appctx->outbuf);
5390+
else
5391+
max = channel_recv_max(chn);
5392+
53815393
if (max > (len - l))
53825394
max = len - l;
53835395

53845396
/* Copy data. */
5385-
ci_putblk(chn, str + l, max);
5397+
applet_putblk(luactx->appctx, str + l, max);
53865398

53875399
/* update counters. */
53885400
l += max;
@@ -5393,7 +5405,10 @@ __LJMP static int hlua_applet_tcp_send_yield(lua_State *L, int status, lua_KCont
53935405
* applet, and returns a yield.
53945406
*/
53955407
if (l < len) {
5396-
sc_need_room(sc, channel_recv_max(chn) + 1);
5408+
if (luactx->appctx->flags & APPCTX_FL_INOUT_BUFS)
5409+
applet_have_more_data(luactx->appctx);
5410+
else
5411+
sc_need_room(sc, channel_recv_max(chn) + 1);
53975412
MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_tcp_send_yield, TICK_ETERNITY, 0));
53985413
}
53995414

@@ -10935,7 +10950,10 @@ void hlua_applet_tcp_fct(struct appctx *ctx)
1093510950

1093610951
out:
1093710952
/* eat the whole request */
10938-
co_skip(sc_oc(sc), co_data(sc_oc(sc)));
10953+
if (ctx->flags & APPCTX_FL_INOUT_BUFS)
10954+
b_reset(&ctx->inbuf);
10955+
else
10956+
co_skip(sc_oc(sc), co_data(sc_oc(sc)));
1093910957
return;
1094010958

1094110959
error:

0 commit comments

Comments
 (0)