BUG/MEDIUM: applet: Fix API for function to push new data in channels buffer

All applets only check the -1 error value (need room) for applet_put*
functions while the underlying functions may also return -2 if the input is
closed or -3 if the data length is invalid. It means applets already handle
other cases by their own.

The API should be fixed but for now, to ease backports, we only fix
applet_put* functions to always return -1 on error. This way, at least for
the applets point of view, the API is consistent.

This patch should be backported to 2.8. Probably not further. Except if we
suspect it could fix a bug.
This commit is contained in:
Christopher Faulet 2023-09-06 08:33:57 +02:00
parent 015fec6a29
commit 3ec156f027

View File

@ -177,8 +177,15 @@ static inline int applet_putchk(struct appctx *appctx, struct buffer *chunk)
int ret;
ret = ci_putchk(sc_ic(se->sc), chunk);
if (ret == -1)
if (ret < 0) {
/* XXX: Handle all errors as a lack of space because callers
* don't handles other cases for now. So applets must be
* carefull to handles shutdown (-2) and invalid calls (-3) by
* themselves.
*/
sc_need_room(se->sc, chunk->data);
ret = -1;
}
return ret;
}
@ -193,8 +200,15 @@ static inline int applet_putblk(struct appctx *appctx, const char *blk, int len)
int ret;
ret = ci_putblk(sc_ic(se->sc), blk, len);
if (ret == -1)
if (ret < -1) {
/* XXX: Handle all errors as a lack of space because callers
* don't handles other cases for now. So applets must be
* carefull to handles shutdown (-2) and invalid calls (-3) by
* themselves.
*/
sc_need_room(se->sc, len);
ret = -1;
}
return ret;
}
@ -210,8 +224,15 @@ static inline int applet_putstr(struct appctx *appctx, const char *str)
int ret;
ret = ci_putstr(sc_ic(se->sc), str);
if (ret == -1)
if (ret == -1) {
/* XXX: Handle all errors as a lack of space because callers
* don't handles other cases for now. So applets must be
* carefull to handles shutdown (-2) and invalid calls (-3) by
* themselves.
*/
sc_need_room(se->sc, strlen(str));
ret = -1;
}
return ret;
}
@ -226,8 +247,15 @@ static inline int applet_putchr(struct appctx *appctx, char chr)
int ret;
ret = ci_putchr(sc_ic(se->sc), chr);
if (ret == -1)
if (ret == -1) {
/* XXX: Handle all errors as a lack of space because callers
* don't handles other cases for now. So applets must be
* carefull to handles shutdown (-2) and invalid calls (-3) by
* themselves.
*/
sc_need_room(se->sc, 1);
ret = -1;
}
return ret;
}