MINOR: applet: replace cs_applet_shut() with appctx_shut()

The former takes a conn_stream still attached to a valid appctx,
which also complicates the termination of the applet. Instead, let's
pass the appctx which already points to the endpoint, this allows us
to properly detach the conn_stream before the call, which is cleaner
and safer.
This commit is contained in:
Willy Tarreau 2022-05-10 19:42:22 +02:00
parent 4201ab791d
commit 1c3ead45a4
3 changed files with 19 additions and 18 deletions

View File

@ -37,6 +37,7 @@ extern struct pool_head *pool_head_appctx;
struct task *task_run_applet(struct task *t, void *context, unsigned int state); struct task *task_run_applet(struct task *t, void *context, unsigned int state);
int appctx_buf_available(void *arg); int appctx_buf_available(void *arg);
void *applet_reserve_svcctx(struct appctx *appctx, size_t size); void *applet_reserve_svcctx(struct appctx *appctx, size_t size);
void appctx_shut(struct appctx *appctx);
struct appctx *appctx_new(struct applet *applet, struct cs_endpoint *endp); struct appctx *appctx_new(struct applet *applet, struct cs_endpoint *endp);

View File

@ -93,6 +93,20 @@ void *applet_reserve_svcctx(struct appctx *appctx, size_t size)
return appctx->svcctx; return appctx->svcctx;
} }
/* call the applet's release() function if any, and marks the endp as shut.
* Needs to be called upon close().
*/
void appctx_shut(struct appctx *appctx)
{
if (appctx->endp->flags & (CS_EP_SHR|CS_EP_SHW))
return;
if (appctx->applet->release)
appctx->applet->release(appctx);
appctx->endp->flags |= CS_EP_SHRR | CS_EP_SHWN;
}
/* Callback used to wake up an applet when a buffer is available. The applet /* Callback used to wake up an applet when a buffer is available. The applet
* <appctx> is woken up if an input buffer was requested for the associated * <appctx> is woken up if an input buffer was requested for the associated
* conn-stream. In this case the buffer is immediately allocated and the * conn-stream. In this case the buffer is immediately allocated and the

View File

@ -388,11 +388,11 @@ static void cs_detach_endp(struct conn_stream **csp)
else if (cs->endp->flags & CS_EP_T_APPLET) { else if (cs->endp->flags & CS_EP_T_APPLET) {
struct appctx *appctx = __cs_appctx(cs); struct appctx *appctx = __cs_appctx(cs);
cs_applet_shut(cs);
cs->endp->flags |= CS_EP_ORPHAN; cs->endp->flags |= CS_EP_ORPHAN;
cs->endp->cs = NULL; cs->endp->cs = NULL;
appctx_free(appctx);
cs->endp = NULL; cs->endp = NULL;
appctx_shut(appctx);
appctx_free(appctx);
} }
if (cs->endp) { if (cs->endp) {
@ -514,20 +514,6 @@ struct appctx *cs_applet_create(struct conn_stream *cs, struct applet *app)
return appctx; return appctx;
} }
/* call the applet's release function if any. Needs to be called upon close() */
void cs_applet_shut(struct conn_stream *cs)
{
struct appctx *appctx = __cs_appctx(cs);
if (cs->endp->flags & (CS_EP_SHR|CS_EP_SHW))
return;
if (appctx->applet->release)
appctx->applet->release(appctx);
cs->endp->flags |= CS_EP_SHRR | CS_EP_SHWN;
}
/* /*
* This function performs a shutdown-read on a detached conn-stream in a * This function performs a shutdown-read on a detached conn-stream in a
* connected or init state (it does nothing for other states). It either shuts * connected or init state (it does nothing for other states). It either shuts
@ -922,7 +908,7 @@ static void cs_app_shutr_applet(struct conn_stream *cs)
return; return;
if (cs_oc(cs)->flags & CF_SHUTW) { if (cs_oc(cs)->flags & CF_SHUTW) {
cs_applet_shut(cs); appctx_shut(__cs_appctx(cs));
cs->state = CS_ST_DIS; cs->state = CS_ST_DIS;
__cs_strm(cs)->conn_exp = TICK_ETERNITY; __cs_strm(cs)->conn_exp = TICK_ETERNITY;
} }
@ -980,7 +966,7 @@ static void cs_app_shutw_applet(struct conn_stream *cs)
case CS_ST_QUE: case CS_ST_QUE:
case CS_ST_TAR: case CS_ST_TAR:
/* Note that none of these states may happen with applets */ /* Note that none of these states may happen with applets */
cs_applet_shut(cs); appctx_shut(__cs_appctx(cs));
cs->state = CS_ST_DIS; cs->state = CS_ST_DIS;
/* fall through */ /* fall through */
default: default: