From 39796141fcf4dec540eb00e9faff2a61c5446dff Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Thu, 2 Apr 2020 12:57:54 +0300 Subject: [PATCH] Allow AppImage to spawn its own rpcs3 process for fatal error dialog (Linux) --- rpcs3/main.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/rpcs3/main.cpp b/rpcs3/main.cpp index d5d7b9b0d8..5ab1c8ac63 100644 --- a/rpcs3/main.cpp +++ b/rpcs3/main.cpp @@ -26,6 +26,8 @@ DYNAMIC_IMPORT("ntdll.dll", NtSetTimerResolution, NTSTATUS(ULONG DesiredResoluti #include #include #include +#include +#include #endif #ifdef __linux__ @@ -129,9 +131,24 @@ LOG_CHANNEL(sys_log, "SYS"); #else pid_t pid; std::vector data(text.data(), text.data() + text.size() + 1); + std::string run_arg = +s_argv0; std::string err_arg = "--error"; - char* argv[] = {+s_argv0, err_arg.data(), data.data(), nullptr}; - int ret = posix_spawn(&pid, +s_argv0, nullptr, nullptr, argv, environ); + + if (run_arg.find_first_of('/') == umax) + { + // AppImage has "rpcs3" in argv[0], can't just execute it +#ifdef __linux__ + char buffer[PATH_MAX]{}; + if (::readlink("/proc/self/exe", buffer, sizeof(buffer) - 1) > 0) + { + printf("Found exec link: %s\n", buffer); + run_arg = buffer; + } +#endif + } + + char* argv[] = {run_arg.data(), err_arg.data(), data.data(), nullptr}; + int ret = posix_spawn(&pid, run_arg.c_str(), nullptr, nullptr, argv, environ); if (ret == 0) {