Skip to content

Commit

Permalink
Use execvpe to execute zenity and kdialog
Browse files Browse the repository at this point in the history
This removes the hard-coding of zenity or kdialog paths. Zenity is preferred still.
  • Loading branch information
paulfd authored and redtide committed Feb 21, 2024
1 parent 8c62c39 commit eb44e51
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions vstgui/lib/platform/linux/x11fileselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (); }

Expand All @@ -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;
}

Expand Down Expand Up @@ -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<std::string> args;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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 ()
Expand Down

0 comments on commit eb44e51

Please sign in to comment.