diff --git a/vstgui/lib/platform/linux/x11fileselector.cpp b/vstgui/lib/platform/linux/x11fileselector.cpp index f727b8110..1e2f27fa0 100644 --- a/vstgui/lib/platform/linux/x11fileselector.cpp +++ b/vstgui/lib/platform/linux/x11fileselector.cpp @@ -18,13 +18,13 @@ extern "C" { extern char **environ; } namespace VSTGUI { namespace X11 { -static constexpr auto kdialogpath = "/usr/bin/kdialog"; -static constexpr auto zenitypath = "/usr/bin/zenity"; +static constexpr auto kdialogpath = "kdialog"; +static constexpr auto zenitypath = "zenity"; //------------------------------------------------------------------------ struct FileSelector : IPlatformFileSelector { - FileSelector (PlatformFileSelectorStyle style) : style (style) { identifiyExDialogType (); } + FileSelector (PlatformFileSelectorStyle style) : style (style) {} ~FileSelector () noexcept { closeProcess (); } @@ -36,15 +36,12 @@ struct FileSelector : IPlatformFileSelector bool runDialog (const PlatformFileSelectorConfig& config) { - switch (exDialogType) - { - case ExDialogType::kdialog: - return runKDialog (config); - case ExDialogType::zenity: - return runZenity (config); - case ExDialogType::none: - break; - } + if (runZenity (config)) + return true; + + if (runKDialog (config)) + return true; + return false; } @@ -89,14 +86,6 @@ struct FileSelector : IPlatformFileSelector zenity }; - void identifiyExDialogType () - { - if (access (zenitypath, X_OK) != -1) - exDialogType = ExDialogType::zenity; - if (access (kdialogpath, X_OK) != -1) - exDialogType = ExDialogType::kdialog; - } - bool runKDialog (const PlatformFileSelectorConfig& config) { std::vector args; @@ -199,7 +188,9 @@ struct FileSelector : IPlatformFileSelector return false; if (forkPid == 0) { - execute (argv, envp, rw.fd); + if (!execute (argv, envp, rw.fd)) + return false; + assert (false); } @@ -213,15 +204,17 @@ struct FileSelector : IPlatformFileSelector return true; } - [[noreturn]] - static void execute (char* argv[], char* envp[], const int pipeFd[2]) + static bool execute (char* argv[], char* envp[], const int pipeFd[2]) { close (pipeFd[0]); if (dup2 (pipeFd[1], STDOUT_FILENO) == -1) _exit (1); close (pipeFd[1]); - execve (argv[0], argv, envp); + if (execvpe (argv[0], argv, envp) == -1) + return false; + _exit (1); + return true; // not reachable } void closeProcess ()