]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
more: make execute() more robust and timely
authorSami Kerola <kerolasa@iki.fi>
Sat, 28 Mar 2020 10:00:08 +0000 (10:00 +0000)
committerSami Kerola <kerolasa@iki.fi>
Mon, 13 Apr 2020 11:14:07 +0000 (12:14 +0100)
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 <kerolasa@iki.fi>
text-utils/more.c

index 4fe20d2ad47bcd7826d065e02f8a40c63cd7c3f5..4a8abed8087ce7b78427cae6838ae9865f186622 100644 (file)
@@ -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);