From aa017116b3202874e2224ff3b4bacff24a48fafc Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Tue, 12 Sep 2023 12:41:43 -0700 Subject: [PATCH] Tools: Fixes usage of waitpid in the face of EINTR waitpid can return early if interrupted due to EINTR. Loop on this case and try again. --- Source/Tools/FEXRootFSFetcher/Main.cpp | 4 ++-- Source/Tools/FEXServer/SquashFS.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Tools/FEXRootFSFetcher/Main.cpp b/Source/Tools/FEXRootFSFetcher/Main.cpp index 99f577caf..31edfb6fb 100644 --- a/Source/Tools/FEXRootFSFetcher/Main.cpp +++ b/Source/Tools/FEXRootFSFetcher/Main.cpp @@ -149,7 +149,7 @@ namespace Exec { } else { int32_t Status{}; - waitpid(pid, &Status, 0); + while (waitpid(pid, &Status, 0) == -1 && errno == EINTR); if (WIFEXITED(Status)) { return (int8_t)WEXITSTATUS(Status); } @@ -192,7 +192,7 @@ namespace Exec { } int32_t Status{}; - waitpid(pid, &Status, 0); + while (waitpid(pid, &Status, 0) == -1 && errno == EINTR); if (WIFEXITED(Status)) { // Return what we've read close(fd[0]); diff --git a/Source/Tools/FEXServer/SquashFS.cpp b/Source/Tools/FEXServer/SquashFS.cpp index 27d8a1e41..369810d27 100644 --- a/Source/Tools/FEXServer/SquashFS.cpp +++ b/Source/Tools/FEXServer/SquashFS.cpp @@ -157,7 +157,7 @@ namespace SquashFS { // Parent // Wait for the child to exit // This will happen with execvpe of squashmount or exit on failure - waitpid(pid, nullptr, 0); + while (waitpid(pid, nullptr, 0) == -1 && errno == EINTR); // Check the child pipe for messages pollfd PollFD; @@ -217,7 +217,7 @@ namespace SquashFS { } else { // Wait for fusermount to leave - waitpid(pid, nullptr, 0); + while (waitpid(pid, nullptr, 0) == -1 && errno == EINTR); // Remove the mount path rmdir(MountFolder.c_str());