From a68da468a523c4c7b5fd44f8f8d34bdc3dc5bde8 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Sat, 8 Jan 2022 21:33:24 -0800 Subject: [PATCH 1/3] FEXRootFSFetcher: ExecAndWaitForResponse sign extend program result Only the lower 8bits of the execve result is the program result. Makes sure to sign extend it so -1 is a true -1 instead of 255 --- Source/Tools/FEXRootFSFetcher/Main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Tools/FEXRootFSFetcher/Main.cpp b/Source/Tools/FEXRootFSFetcher/Main.cpp index e174b0bbb1..180da40a04 100644 --- a/Source/Tools/FEXRootFSFetcher/Main.cpp +++ b/Source/Tools/FEXRootFSFetcher/Main.cpp @@ -20,7 +20,7 @@ namespace Exec { int32_t Status{}; waitpid(pid, &Status, 0); if (WIFEXITED(Status)) { - return WEXITSTATUS(Status); + return (int8_t)WEXITSTATUS(Status); } } From 285ed8f1e0ac1c2686746e1af2ce8c20e0bedeb2 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Sat, 8 Jan 2022 21:34:59 -0800 Subject: [PATCH 2/3] FEXRootFSFetcher: Adds new Exec function with stdout,stderr redirection Just so we can test for applications without spamming terminal --- Source/Tools/FEXRootFSFetcher/Main.cpp | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Source/Tools/FEXRootFSFetcher/Main.cpp b/Source/Tools/FEXRootFSFetcher/Main.cpp index 180da40a04..7849b7b2f7 100644 --- a/Source/Tools/FEXRootFSFetcher/Main.cpp +++ b/Source/Tools/FEXRootFSFetcher/Main.cpp @@ -27,6 +27,37 @@ namespace Exec { return -1; } + int32_t ExecAndWaitForResponseRedirect(const char *path, char* const* args, int stdoutRedirect = STDOUT_FILENO, int stderrRedirect = STDERR_FILENO) { + pid_t pid = fork(); + if (pid == 0) { + if (stdoutRedirect == -1) { + close(STDOUT_FILENO); + } + else if (stdoutRedirect != STDOUT_FILENO) { + close(STDOUT_FILENO); + dup2(stdoutRedirect, STDOUT_FILENO); + } + if (stderrRedirect == -1) { + close(STDERR_FILENO); + } + else if (stderrRedirect != STDOUT_FILENO) { + close(STDERR_FILENO); + dup2(stderrRedirect, STDERR_FILENO); + } + execvp(path, args); + _exit(-1); + } + else { + int32_t Status{}; + waitpid(pid, &Status, 0); + if (WIFEXITED(Status)) { + return (int8_t)WEXITSTATUS(Status); + } + } + + return -1; + } + std::string ExecAndWaitForResponseText(const char *path, char* const* args) { int fd[2]; pipe(fd); From 5a5a498ed6fd473e4fa23b7d50d7ae67aa1191e5 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Sat, 8 Jan 2022 21:35:29 -0800 Subject: [PATCH 3/3] FEXRootFSFetcher: Check if curl is installed and fail before running Before doing anything that requires curl, actually check if it is installed. Then instruct the user to install curl before using. Doesn't try installing curl itself since we don't have a clean way to execute sudo from potentially GUI. Fixes #1498 --- Source/Tools/FEXRootFSFetcher/Main.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Source/Tools/FEXRootFSFetcher/Main.cpp b/Source/Tools/FEXRootFSFetcher/Main.cpp index 7849b7b2f7..cd1347779e 100644 --- a/Source/Tools/FEXRootFSFetcher/Main.cpp +++ b/Source/Tools/FEXRootFSFetcher/Main.cpp @@ -809,6 +809,19 @@ int main(int argc, char **argv, char **const envp) { return 0; } + // Check if curl exists on the host + std::vector ExecveArgs = { + "curl", + "-V", + nullptr, + }; + + int32_t Result = Exec::ExecAndWaitForResponseRedirect(ExecveArgs[0], const_cast(ExecveArgs.data()), -1, -1); + if (Result == -1) { + ExecWithInfo("curl is required to use this tool. Please install curl before using."); + return -1; + } + FEX_CONFIG_OPT(LDPath, ROOTFS); std::error_code ec;