[PATCH 8/8] common/parser.c: Do not treat zero return code as error

Andrey Smirnov andrew.smirnov at gmail.com
Sun Oct 11 11:43:41 PDT 2015


Run_command() would return zero to indicated success so treating it as
error case would completely break command repetition logic, so change
comparinson operator from "less or equal" to "less then"

Signed-off-by: Andrey Smirnov <andrew.smirnov at gmail.com>
---
 common/parser.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/common/parser.c b/common/parser.c
index 2b95aed..6136dbf 100644
--- a/common/parser.c
+++ b/common/parser.c
@@ -266,7 +266,6 @@ int run_shell(void)
 {
 	static char lastcommand[CONFIG_CBSIZE] = { 0, };
 	int len;
-	int rc = 1;
 
 	login();
 
@@ -276,14 +275,14 @@ int run_shell(void)
 		if (len > 0)
 			strcpy (lastcommand, console_buffer);
 
-		if (len == -1)
+		if (len == -1) {
 			puts ("<INTERRUPT>\n");
-		else
-			rc = run_command(lastcommand);
-
-		if (rc <= 0) {
-			/* invalid command or not repeatable, forget it */
-			lastcommand[0] = 0;
+		} else {
+			const int rc = run_command(lastcommand);
+			if (rc < 0) {
+				/* invalid command or not repeatable, forget it */
+				lastcommand[0] = 0;
+			}
 		}
 	}
 	return 0;
-- 
2.1.4




More information about the barebox mailing list