From: Michael Tremer Date: Fri, 28 May 2021 10:04:00 +0000 (+0000) Subject: execute: Keep reading log output even after the process has terminated X-Git-Tag: 0.9.28~1285^2~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a1d36329ae725b1642168eb6028a6dc18b4cce9;p=pakfire.git execute: Keep reading log output even after the process has terminated Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/execute.c b/src/libpakfire/execute.c index 95ee28b55..bc021825f 100644 --- a/src/libpakfire/execute.c +++ b/src/libpakfire/execute.c @@ -201,8 +201,17 @@ static int pakfire_execute_logger(Pakfire pakfire, pakfire_execute_logging_callb } } + int ended = 0; + // Loop for as long as the process is alive - while (waitpid(pid, status, WNOHANG) == 0) { + while (!ended) { + // If waitpid() returns non-zero, the process has ended, but we want to perform + // one last iteration over the loop to read any remaining content from the file + // descriptor buffers. + r = waitpid(pid, status, WNOHANG); + if (r) + ended = 1; + int fds = epoll_wait(epollfd, events, EPOLL_MAX_EVENTS, -1); if (fds < 1) { ERROR(pakfire, "epoll_wait() failed: %s\n", strerror(errno));