Skip to content

Commit

Permalink
Merge branch 'PR/more-stderr' of github.com:karelzak/util-linux-work
Browse files Browse the repository at this point in the history
* 'PR/more-stderr' of github.com:karelzak/util-linux-work:
  more: make sure we have data on stderr
  • Loading branch information
karelzak committed Aug 26, 2024
2 parents e8f7cd6 + 640b948 commit d191775
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions text-utils/more.c
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ static void read_line(struct more_control *ctl)
}

/* returns: 0 timeout or nothing; <0 error, >0 success */
static int more_poll(struct more_control *ctl, int timeout)
static int more_poll(struct more_control *ctl, int timeout, int *stderr_active)
{
enum {
POLLFD_SIGNAL = 0,
Expand All @@ -1364,6 +1364,9 @@ static int more_poll(struct more_control *ctl, int timeout)
};
int has_data = 0;

if (stderr_active)
*stderr_active = 0;

while (!has_data) {
int rc;

Expand Down Expand Up @@ -1430,8 +1433,11 @@ static int more_poll(struct more_control *ctl, int timeout)
}

/* event on stderr (we reads user commands from stderr!) */
if (pfd[POLLFD_STDERR].revents)
if (pfd[POLLFD_STDERR].revents) {
has_data++;
if (stderr_active)
*stderr_active = 1;
}
}

return has_data;
Expand Down Expand Up @@ -1502,7 +1508,7 @@ static void search(struct more_control *ctl, char buf[], int n)
}
break;
}
more_poll(ctl, 0);
more_poll(ctl, 0, NULL);
}
/* Move ctrl+c signal handling back to more_key_command(). */
signal(SIGINT, SIG_DFL);
Expand Down Expand Up @@ -1656,7 +1662,7 @@ static int skip_forwards(struct more_control *ctl, int nlines, cc_t comchar)
static int more_key_command(struct more_control *ctl, char *filename)
{
int retval = 0;
int done = 0, search_again = 0;
int done = 0, search_again = 0, stderr_active = 0;
char cmdbuf[INIT_BUF];
struct number_command cmd;

Expand All @@ -1666,7 +1672,9 @@ static int more_key_command(struct more_control *ctl, char *filename)
ctl->report_errors = 0;
ctl->search_called = 0;
for (;;) {
if (more_poll(ctl, -1) <= 0)
if (more_poll(ctl, -1, &stderr_active) <= 0)
continue;
if (stderr_active == 0)
continue;
cmd = read_command(ctl);
if (cmd.key == more_kc_unknown_command)
Expand Down

0 comments on commit d191775

Please sign in to comment.