From 2703401f0813753d0fc4eed94826d873cef8dd06 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Sat, 28 Jan 2023 19:46:09 +0200 Subject: [PATCH] Fix process creation on Linux Forked child process did not exit properly, sometimes causing scripting compilation to get stuck and never finish. --- Source/Engine/Platform/Linux/LinuxPlatform.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Platform/Linux/LinuxPlatform.cpp b/Source/Engine/Platform/Linux/LinuxPlatform.cpp index a5bd099c9..5dc62a26e 100644 --- a/Source/Engine/Platform/Linux/LinuxPlatform.cpp +++ b/Source/Engine/Platform/Linux/LinuxPlatform.cpp @@ -2802,6 +2802,7 @@ int32 LinuxProcess(const StringView& cmdLine, const StringView& workingDir, cons { close(fildes[0]); // close the reading end of the pipe dup2(fildes[1], STDOUT_FILENO); // redirect stdout to pipe + close(fildes[1]); dup2(STDOUT_FILENO, STDERR_FILENO); // redirect stderr to stdout } @@ -2810,6 +2811,8 @@ int32 LinuxProcess(const StringView& cmdLine, const StringView& workingDir, cons { LOG(Warning, " failed, errno={}", errno); } + fflush(stdout); + _exit(1); } else { @@ -2822,7 +2825,7 @@ int32 LinuxProcess(const StringView& cmdLine, const StringView& workingDir, cons { char lineBuffer[1024]; close(fildes[1]); // close the writing end of the pipe - FILE *stdPipe = fdopen(fildes[0], "r"); + FILE* stdPipe = fdopen(fildes[0], "r"); while (fgets(lineBuffer, sizeof(lineBuffer), stdPipe) != NULL) { char *p = lineBuffer + strlen(lineBuffer)-1; @@ -2857,6 +2860,7 @@ int32 LinuxProcess(const StringView& cmdLine, const StringView& workingDir, cons returnCode = EPIPE; } } + close(fildes[0]); } }