]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
more: fix -e in non-interactive mode
authorKarel Zak <kzak@redhat.com>
Tue, 5 Oct 2021 08:53:13 +0000 (10:53 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 5 Oct 2021 08:53:13 +0000 (10:53 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
text-utils/more.1.adoc
text-utils/more.c

index 13679b16c8f0ef856f1ca9e9e1430fcb16a54c2a..ea1b669c46f71fe95a3b15ff60737b2253d063ca 100644 (file)
@@ -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).
index d08b5b1b2b79af2dca2993c06395474d407206c8..2f97569cda083f19230acfe3afbb149eae73e691 100644 (file)
@@ -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);