[v11,2/3] cmdline: handle EOF in cmdline_poll
Checks
Commit Message
If end of file is reached on input, then cmdline_poll() will
return 1 (ie file has something); and then the cmdline_in()
call to read will return 0. With the existing code,
caller has no way to tell that end of file has been reached
and will retry forever.
A good way to handle this is to make end of file equivalent
to the quit command. Since no more input is possible at that
point.
Fixes: 067855e651d6 ("cmdline: add polling mode")
Cc: pawelx.wodkowski@intel.com
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
Note: cmdline_poll() should not have been added back
in 2015, looks like there is no users, and no tests for this.
lib/cmdline/cmdline.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
@@ -197,9 +197,14 @@ cmdline_poll(struct cmdline *cl)
if (read_status < 0)
return read_status;
- status = cmdline_in(cl, &c, 1);
- if (status < 0 && cl->rdl.status != RDLINE_EXITED)
- return status;
+ if (read_status == 0) {
+ /* end of file is implicit quit */
+ cmdline_quit(cl);
+ } else {
+ status = cmdline_in(cl, &c, 1);
+ if (status < 0 && cl->rdl.status != RDLINE_EXITED)
+ return status;
+ }
}
return cl->rdl.status;