From: Sami Kerola Date: Sat, 28 Mar 2020 10:00:08 +0000 (+0000) Subject: more: make execute() more robust and timely X-Git-Tag: v2.36-rc1~147^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c366ebc7ef8909e5d7e6d769b4e952a0124ef338;p=thirdparty%2Futil-linux.git 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 --- 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);