[PATCH v10 1/2] cmdline: handle EOF in cmdline_poll
Stephen Hemminger
stephen at networkplumber.org
Tue Jan 31 03:54:21 CET 2023
On Mon, 30 Jan 2023 22:12:42 +0000
Ferruh Yigit <ferruh.yigit at amd.com> wrote:
> On 1/30/2023 8:09 PM, Stephen Hemminger wrote:
> > If end of file is reached on input, then cmdline_read_char()
> > will return 0. The problem is that cmdline_poll() was not checking
> > for this and would continue and not return the status.
> >
> > Fixes: 9251cd97a6be ("cmdline: add internal wrappers for character input")
> > Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
> > ---
> > lib/cmdline/cmdline.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/lib/cmdline/cmdline.c b/lib/cmdline/cmdline.c
> > index e1009ba4c413..de41406d61e0 100644
> > --- a/lib/cmdline/cmdline.c
> > +++ b/lib/cmdline/cmdline.c
> > @@ -194,7 +194,7 @@ cmdline_poll(struct cmdline *cl)
> > else if (status > 0) {
> > c = -1;
> > read_status = cmdline_read_char(cl, &c);
> > - if (read_status < 0)
> > + if (read_status <= 0)
> > return read_status;
>
> According API doc it will be wrong to return '0', which imply 'RDLINE_INIT'.
The API doc is a mess. It says function returns things enum that is only
defined in cmdline_private.h. Therefore no application could safely depend
on it.
End of File is not an error in most API's.
More information about the dev
mailing list