ash: fix ignoreeof option

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>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Ron Yorston 2021-09-12 11:20:33 +01:00 committed by Denys Vlasenko
parent 9346ea9550
commit 0beee20977

View File

@ -10826,9 +10826,7 @@ preadfd(void)
* Refill the input buffer and return the next input character: * Refill the input buffer and return the next input character:
* *
* 1) If a string was pushed back on the input, pop it; * 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) * 2) If we are reading from a string we can't refill the buffer, return EOF.
* or we are reading from a string so 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. * 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. * 4) Process input up to the next newline, deleting nul characters.
*/ */
@ -10845,21 +10843,9 @@ preadbuffer(void)
popstring(); popstring();
return __pgetc(); 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", if (g_parsefile->buf == NULL) {
* 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) {
pgetc_debug("preadbuffer PEOF1"); 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; return PEOF;
} }
@ -10869,10 +10855,8 @@ preadbuffer(void)
again: again:
more = preadfd(); more = preadfd();
if (more <= 0) { if (more <= 0) {
/* don't try reading again */ g_parsefile->left_in_buffer = g_parsefile->left_in_line = 0;
g_parsefile->left_in_line = -99;
pgetc_debug("preadbuffer PEOF2"); pgetc_debug("preadbuffer PEOF2");
g_parsefile->next_to_pgetc++;
return PEOF; return PEOF;
} }
} }