13
0

Clean up vfork_exec_wrapper static intialization

Print a less cryptic error message in case the wrapper app
cannot be found. Also address a future race condition (once
we start parallel plugin scans and will exec-wrapper from a
helper thread).
This commit is contained in:
Robin Gareus 2021-07-15 21:37:25 +02:00
parent d9877d5c99
commit 1d993d586d
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 48 additions and 47 deletions

View File

@ -18,32 +18,35 @@
#ifndef _ardour_system_exec_h_ #ifndef _ardour_system_exec_h_
#define _ardour_system_exec_h_ #define _ardour_system_exec_h_
#include <glibmm/threads.h>
#include "ardour/libardour_visibility.h" #include "ardour/libardour_visibility.h"
#include "pbd/system_exec.h" #include "pbd/system_exec.h"
namespace ARDOUR { namespace ARDOUR {
class LIBARDOUR_API SystemExec class LIBARDOUR_API SystemExec : public PBD::SystemExec
: public PBD::SystemExec
{ {
public: public:
SystemExec (std::string c, std::string a = ""); SystemExec (std::string c, std::string a = "");
SystemExec (std::string c, char ** a); SystemExec (std::string c, char** a);
SystemExec (std::string c, const std::map<char, std::string> subs); SystemExec (std::string c, const std::map<char, std::string> subs);
~SystemExec (); ~SystemExec ();
int start (StdErrMode stderr_mode = IgnoreAndClose) { int start (StdErrMode stderr_mode = IgnoreAndClose)
return PBD::SystemExec::start (stderr_mode, _vfork_exec_wrapper); {
return PBD::SystemExec::start (stderr_mode, _vfork_exec.c_str ());
} }
private: private:
static char * _vfork_exec_wrapper; static void initialize ();
}; /* end class */ static bool _initialized;
static Glib::Threads::Mutex _init_mutex;
static std::string _vfork_exec;
}; /* end namespace */ };
}; // namespace ARDOUR
#endif /* _libpbd_system_exec_h_ */ #endif /* _libpbd_system_exec_h_ */

View File

@ -18,64 +18,62 @@
*/ */
#include <glibmm/miscutils.h> #include <glibmm/miscutils.h>
#include "pbd/file_utils.h"
#include "pbd/error.h" #include "pbd/error.h"
#include "pbd/file_utils.h"
#include "ardour/filesystem_paths.h" #include "ardour/filesystem_paths.h"
#include "ardour/system_exec.h" #include "ardour/system_exec.h"
namespace ARDOUR { namespace ARDOUR {
char * SystemExec::_vfork_exec_wrapper = NULL; bool SystemExec::_initialized = false;
Glib::Threads::Mutex SystemExec::_init_mutex;
std::string SystemExec::_vfork_exec;
static char *vfork_exec_wrapper_path() { void
#ifdef PLATFORM_WINDOWS SystemExec::initialize ()
return NULL; {
#else if (_initialized) {
std::string vfork_exec_wrapper; return;
if (!PBD::find_file ( }
PBD::Searchpath( #ifndef PLATFORM_WINDOWS
ARDOUR::ardour_dll_directory() // deployed Glib::Threads::Mutex::Lock lk (_init_mutex);
+ G_SEARCHPATH_SEPARATOR_S + Glib::build_filename(ARDOUR::ardour_dll_directory(), "vfork") // src, build (ardev, etc) if (_initialized) {
), return;
"ardour-exec-wrapper", vfork_exec_wrapper)) { }
PBD::fatal << "vfork exec wrapper 'ardour-exec-wrapper' was not found in $PATH." << endmsg; PBD::Searchpath vfsp (
abort(); /*NOTREACHED*/ ARDOUR::ardour_dll_directory () //< deployed
+ G_SEARCHPATH_SEPARATOR_S + Glib::build_filename (ARDOUR::ardour_dll_directory (), "vfork") //< src-tree (ardev, etc)
);
if (!PBD::find_file (vfsp, "ardour-exec-wrapper", _vfork_exec)) {
PBD::fatal << "child process app 'ardour-exec-wrapper' was not found in search path:\n"
<< vfsp.to_string () << endmsg;
abort (); /*NOTREACHED*/
} }
return strdup(vfork_exec_wrapper.c_str());
#endif #endif
_initialized = true;
} }
SystemExec::SystemExec (std::string c, char ** a) SystemExec::SystemExec (std::string c, char** a)
: PBD::SystemExec(c, a) : PBD::SystemExec (c, a)
{ {
#ifndef PLATFORM_WINDOWS initialize ();
if (!_vfork_exec_wrapper) {
_vfork_exec_wrapper = vfork_exec_wrapper_path();
}
#endif
} }
SystemExec::SystemExec (std::string c, std::string a) SystemExec::SystemExec (std::string c, std::string a)
: PBD::SystemExec(c, a) : PBD::SystemExec (c, a)
{ {
#ifndef PLATFORM_WINDOWS initialize ();
if (!_vfork_exec_wrapper) {
_vfork_exec_wrapper = vfork_exec_wrapper_path();
}
#endif
} }
SystemExec::SystemExec (std::string c, const std::map<char, std::string> subs) SystemExec::SystemExec (std::string c, const std::map<char, std::string> subs)
: PBD::SystemExec(c, subs) : PBD::SystemExec (c, subs)
{ {
#ifndef PLATFORM_WINDOWS initialize ();
if (!_vfork_exec_wrapper) {
_vfork_exec_wrapper = vfork_exec_wrapper_path();
}
#endif
} }
SystemExec::~SystemExec() { } SystemExec::~SystemExec () {}
} // namespace ARDOUR } // namespace ARDOUR