[PATCH 2/5] cmdline: handle EOF as quit

Stephen Hemminger stephen at networkplumber.org
Sat Aug 31 19:09:26 CEST 2024


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: stable at dpdk.org

Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
(cherry picked from commit 415549f1ccce62b82cb182175346904a65f74cec)
---
 lib/cmdline/cmdline.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/lib/cmdline/cmdline.c b/lib/cmdline/cmdline.c
index 8f1854cb0b..5600f012c2 100644
--- a/lib/cmdline/cmdline.c
+++ b/lib/cmdline/cmdline.c
@@ -199,9 +199,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;
-- 
2.45.2



More information about the stable mailing list