From: Cristian Rodríguez Date: Sun, 15 Jan 2023 01:33:14 +0000 (+0000) Subject: lib:pager: fix signal safety issues X-Git-Tag: v2.39-rc1~123^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=518a0ad;p=thirdparty%2Futil-linux.git lib:pager: fix signal safety issues - Cannot use stdio in signal handlers, so you cannot safely call fflush. - cannot call exit() but only _exit() --- diff --git a/lib/pager.c b/lib/pager.c index e5bd07a471..8f62310c07 100644 --- a/lib/pager.c +++ b/lib/pager.c @@ -114,7 +114,9 @@ static int wait_or_whine(pid_t pid) if (waiting < 0) { if (errno == EINTR) continue; - err(EXIT_FAILURE, _("waitpid failed (%s)"), strerror(errno)); + /* Can't err() on signal handler */ + ignore_result(write(STDERR_FILENO, "waitpid failed", 14)); + _exit(EXIT_FAILURE); } if (waiting != pid) return -1; @@ -163,8 +165,6 @@ static void wait_for_pager(void) if (pager_process.pid == 0) return; - fflush(stdout); - fflush(stderr); /* signal EOF to pager */ close(STDOUT_FILENO); close(STDERR_FILENO);