From: Karel Zak Date: Tue, 5 Oct 2021 08:53:13 +0000 (+0200) Subject: more: fix -e in non-interactive mode X-Git-Tag: v2.38-rc1~230 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2ae8b75754c990bd9bb81ef644770b561c8792bb;p=thirdparty%2Futil-linux.git more: fix -e in non-interactive mode Signed-off-by: Karel Zak --- diff --git a/text-utils/more.1.adoc b/text-utils/more.1.adoc index 13679b16c8..ea1b669c46 100644 --- a/text-utils/more.1.adoc +++ b/text-utils/more.1.adoc @@ -66,7 +66,7 @@ Prompt with "[Press space to continue, 'q' to quit.]", and display "[Press 'h' f Do not pause after any line containing a *^L* (form feed). *-e*, *--exit-on-eof*:: -Exit on End-Of-File. +Exit on End-Of-File, enabled by default if not executed on terminal. *-f*, *--no-pause*:: Count logical lines, rather than screen lines (i.e., long lines are not folded). diff --git a/text-utils/more.c b/text-utils/more.c index d08b5b1b2b..2f97569cda 100644 --- a/text-utils/more.c +++ b/text-utils/more.c @@ -219,6 +219,7 @@ struct more_control { no_scroll:1, /* do not scroll, clear the screen and then display text */ no_tty_in:1, /* is input in interactive mode */ no_tty_out:1, /* is output in interactive mode */ + no_tty_err:1, /* is stderr terminal */ print_banner:1, /* print file name banner */ reading_num:1, /* are we reading leading_number */ report_errors:1, /* is an error reported */ @@ -1958,8 +1959,9 @@ static void initterm(struct more_control *ctl) ctl->no_tty_out = tcgetattr(STDOUT_FILENO, &ctl->output_tty); #endif ctl->no_tty_in = tcgetattr(STDIN_FILENO, &ctl->output_tty); - tcgetattr(STDERR_FILENO, &ctl->output_tty); + ctl->no_tty_err = tcgetattr(STDERR_FILENO, &ctl->output_tty); ctl->original_tty = ctl->output_tty; + ctl->hard_tabs = (ctl->output_tty.c_oflag & TABDLY) != TAB3; if (ctl->no_tty_out) return; @@ -2058,6 +2060,10 @@ int main(int argc, char **argv) initterm(&ctl); + if (ctl.no_tty_err) + /* exit when we cannot read user's input */ + ctl.exit_on_eof = 1; + #ifdef HAVE_MAGIC ctl.magic = magic_open(MAGIC_MIME_ENCODING | MAGIC_SYMLINK); magic_load(ctl.magic, NULL);