From c366ebc7ef8909e5d7e6d769b4e952a0124ef338 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 28 Mar 2020 10:00:08 +0000 Subject: [PATCH] more: make execute() more robust and timely The wait() is now a little more robust by being more tolerate rogue SIGCHLDs and unblocked signals. The repeated fork() and sleep() is removed, if first try does not success give up without delay to provide user timely feedback. Signed-off-by: Sami Kerola --- text-utils/more.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/text-utils/more.c b/text-utils/more.c index 4fe20d2ad4..4a8abed808 100644 --- a/text-utils/more.c +++ b/text-utils/more.c @@ -1084,16 +1084,14 @@ static void sigwinch_handler(struct more_control *ctl) static void execute(struct more_control *ctl, char *filename, char *cmd, ...) { - int id; - int n; + pid_t id; va_list argp; char *arg; char **args; int argcount; fflush(NULL); - for (n = 10; (id = fork()) < 0 && n > 0; n--) - sleep(5); + id = fork(); if (id == 0) { int errsv; if (!isatty(STDIN_FILENO)) { @@ -1137,8 +1135,11 @@ static void execute(struct more_control *ctl, char *filename, char *cmd, ...) exit(errsv == ENOENT ? EX_EXEC_ENOENT : EX_EXEC_FAILED); } if (id > 0) { - while (wait(NULL) > 0) - /* nothing */ ; + errno = 0; + while (wait(NULL) > 0) { + if (errno == EINTR) + continue; + } } else fputs(_("can't fork\n"), stderr); set_tty(ctl); -- 2.47.3