[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH 1/3] ash: fix ignoreeof option
From:       Ron Yorston <rmy () pobox ! com>
Date:       2021-09-12 10:20:33
Message-ID: 613dd471.CHMUkX0Ei00zGXs8%rmy () pobox ! com
[Download RAW message or body]

The ignoreeof option should prevent an interactive shell from
exiting on EOF.  This hasn't worked in BusyBox ash since commit
727752d2d (ash: better fix for ash -c 'echo 5&' and ash -c 'sleep 5&'
with testcase).

Commit 3b4d04b77e (ash: input: Allow two consecutive calls to pungetc)
pulled in improved support for multiple calls to pungetc from dash,
thus rendering much of commit 727752d2d obsolete.  Removing this old
code fixes the problem with ignoreeof.

function                                             old     new   delta
__pgetc                                              605     587     -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-18)             Total: -18 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
---
 shell/ash.c | 22 +++-------------------
 1 file changed, 3 insertions(+), 19 deletions(-)

diff --git a/shell/ash.c b/shell/ash.c
index ba116d83a..99b89409e 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -10822,9 +10822,7 @@ preadfd(void)
  * Refill the input buffer and return the next input character:
  *
  * 1) If a string was pushed back on the input, pop it;
- * 2) If an EOF was pushed back (g_parsefile->left_in_line < -BIGNUM)
- *    or we are reading from a string so we can't refill the buffer,
- *    return EOF.
+ * 2) If we are reading from a string we can't refill the buffer, return EOF.
  * 3) If there is more stuff in this buffer, use it else call read to fill it.
  * 4) Process input up to the next newline, deleting nul characters.
  */
@@ -10841,21 +10839,9 @@ preadbuffer(void)
 		popstring();
 		return __pgetc();
 	}
-	/* on both branches above g_parsefile->left_in_line < 0.
-	 * "pgetc" needs refilling.
-	 */
 
-	/* -90 is our -BIGNUM. Below we use -99 to mark "EOF on read",
-	 * pungetc() may increment it a few times.
-	 * Assuming it won't increment it to less than -90.
-	 */
-	if (g_parsefile->left_in_line < -90 || g_parsefile->buf == NULL) {
+	if (g_parsefile->buf == NULL) {
 		pgetc_debug("preadbuffer PEOF1");
-		/* even in failure keep left_in_line and next_to_pgetc
-		 * in lock step, for correct multi-layer pungetc.
-		 * left_in_line was decremented before preadbuffer(),
-		 * must inc next_to_pgetc: */
-		g_parsefile->next_to_pgetc++;
 		return PEOF;
 	}
 
@@ -10865,10 +10851,8 @@ preadbuffer(void)
  again:
 		more = preadfd();
 		if (more <= 0) {
-			/* don't try reading again */
-			g_parsefile->left_in_line = -99;
+			g_parsefile->left_in_buffer = g_parsefile->left_in_line = 0;
 			pgetc_debug("preadbuffer PEOF2");
-			g_parsefile->next_to_pgetc++;
 			return PEOF;
 		}
 	}
-- 
2.31.1

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic