]> git.ipfire.org Git - thirdparty/util-linux.git/commit
more: fix poll() use
authorKarel Zak <kzak@redhat.com>
Tue, 20 Feb 2024 11:26:33 +0000 (12:26 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 20 Feb 2024 11:26:33 +0000 (12:26 +0100)
commitfe23722854f651984fad597cbb5b44653f72832a
tree2bb5ea44714590e260acca4588fb4f21a82f6ee1
parent1c14996da1e132830bcc024c2ca7430fe3c2ac28
more: fix poll() use

The more(1) command utilizes signalfd() to monitor signals and reads
commands from the user via stderr (as stdin is typically used for
piping and not for user interaction).

However, the current more_poll() implementation ignores stderr. As a result,
more(1) waits on read(stderr) while completely ignoring signals. This issue
becomes evident when using commands like:

    grep foo /path/file | more

In such cases, it's only possible to exit 'more' by pressing 'q';
CTRL+C does not work.

Changes:

- Refactor more_poll() code:
  - Introduce an enum to access pfd[] items instead of using magical constants.
  - Implement a while() loop to handle EAGAIN or POLLHUP.

- Ignore stdin after POLLHUP (indicating that the pipe's peer closed).
- Ensure stderr is also checked.
- Use return codes akin to classic poll().

Note: I have doubts regarding the usability of stdin in more_poll(),
as the function is primarily used to wait for user input (via stderr)
and to monitor signals. Nevertheless, it is retained for potential use
in detecting when the pipe's peer (or the entire session) has been
terminated (see commit 68e14d3d5f4116ad3aca0e392d008645ea90cf70).

Signed-off-by: Karel Zak <kzak@redhat.com>
text-utils/more.c