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 committed Oct 16, 2021
1 parent cfcf171 commit 6143126
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions vstgui/lib/platform/linux/x11fileselector.cpp
Expand Up @@ -18,15 +18,14 @@ 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 : CNewFileSelector
{
FileSelector (CFrame* parent, Style style) : CNewFileSelector (parent), style (style)
{
identifiyExDialogType ();
}

~FileSelector ()
Expand All @@ -37,15 +36,12 @@ struct FileSelector : CNewFileSelector
bool runInternal (CBaseObject* delegate) override
{
this->delegate = delegate;
switch (exDialogType)
{
case ExDialogType::kdialog:
return runKDialog ();
case ExDialogType::zenity:
return runZenity ();
case ExDialogType::none:
break;
}
if (runZenity())
return true;

if (runKDialog())
return true;

return false;
}

Expand Down Expand Up @@ -88,14 +84,6 @@ struct FileSelector : CNewFileSelector
zenity
};

void identifiyExDialogType ()
{
if (access (zenitypath, X_OK) != -1)
exDialogType = ExDialogType::zenity;
if (access (kdialogpath, X_OK) != -1)
exDialogType = ExDialogType::kdialog;
}

bool runKDialog ()
{
std::vector<std::string> args;
Expand Down Expand Up @@ -196,7 +184,9 @@ struct FileSelector : CNewFileSelector
return false;

if (forkPid == 0) {
execute (argv, envp, rw.fd);
if (!execute (argv, envp, rw.fd))
return false;

assert (false);
}

Expand All @@ -210,15 +200,17 @@ struct FileSelector : CNewFileSelector
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 6143126

Please sign in to comment.