]> git.ipfire.org Git - pakfire.git/commitdiff
execute: Keep reading log output even after the process has terminated
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 28 May 2021 10:04:00 +0000 (10:04 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 28 May 2021 10:04:00 +0000 (10:04 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/execute.c

index 95ee28b556adab061b736ccb802b8ee01716bad9..bc021825feb9b468da10cb36ff6fce58aea36e48 100644 (file)
@@ -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));