33// distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
44
55#include " x11fileselector.h"
6+ #include " ../../vstguibase.h"
67#include < unistd.h>
78#include < sys/wait.h>
89#include < sys/types.h>
@@ -18,13 +19,19 @@ extern "C" { extern char **environ; }
1819namespace VSTGUI {
1920namespace X11 {
2021
22+ #if LINUX
23+ // Use execvpe on Linux to support also NixOS based distributions
24+ static constexpr auto kdialogpath = " kdialog" ;
25+ static constexpr auto zenitypath = " zenity" ;
26+ #else
2127static constexpr auto kdialogpath = " /usr/bin/kdialog" ;
2228static constexpr auto zenitypath = " /usr/bin/zenity" ;
29+ #endif
2330
2431// ------------------------------------------------------------------------
2532struct FileSelector : IPlatformFileSelector
2633{
27- FileSelector (PlatformFileSelectorStyle style) : style (style) { identifiyExDialogType (); }
34+ FileSelector (PlatformFileSelectorStyle style) : style (style) {}
2835
2936 ~FileSelector () noexcept { closeProcess (); }
3037
@@ -36,15 +43,12 @@ struct FileSelector : IPlatformFileSelector
3643
3744 bool runDialog (const PlatformFileSelectorConfig& config)
3845 {
39- switch (exDialogType)
40- {
41- case ExDialogType::kdialog:
42- return runKDialog (config);
43- case ExDialogType::zenity:
44- return runZenity (config);
45- case ExDialogType::none:
46- break ;
47- }
46+ if (runZenity (config))
47+ return true ;
48+
49+ if (runKDialog (config))
50+ return true ;
51+
4852 return false ;
4953 }
5054
@@ -89,14 +93,6 @@ struct FileSelector : IPlatformFileSelector
8993 zenity
9094 };
9195
92- void identifiyExDialogType ()
93- {
94- if (access (zenitypath, X_OK) != -1 )
95- exDialogType = ExDialogType::zenity;
96- if (access (kdialogpath, X_OK) != -1 )
97- exDialogType = ExDialogType::kdialog;
98- }
99-
10096 bool runKDialog (const PlatformFileSelectorConfig& config)
10197 {
10298 std::vector<std::string> args;
@@ -199,7 +195,9 @@ struct FileSelector : IPlatformFileSelector
199195 return false ;
200196
201197 if (forkPid == 0 ) {
202- execute (argv, envp, rw.fd );
198+ if (!execute (argv, envp, rw.fd ))
199+ return false ;
200+
203201 assert (false );
204202 }
205203
@@ -213,15 +211,21 @@ struct FileSelector : IPlatformFileSelector
213211 return true ;
214212 }
215213
216- [[noreturn]]
217- static void execute (char * argv[], char * envp[], const int pipeFd[2 ])
214+ static bool execute (char * argv[], char * envp[], const int pipeFd[2 ])
218215 {
219216 close (pipeFd[0 ]);
220217 if (dup2 (pipeFd[1 ], STDOUT_FILENO) == -1 )
221218 _exit (1 );
222219 close (pipeFd[1 ]);
223- execve (argv[0 ], argv, envp);
220+ #if LINUX
221+ if (execvpe (argv[0 ], argv, envp) == -1 )
222+ #else
223+ if (execve (argv[0 ], argv, envp) == -1 )
224+ #endif
225+ return false ;
226+
224227 _exit (1 );
228+ return true ; // not reachable
225229 }
226230
227231 void closeProcess ()
0 commit comments