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_
#define _ardour_system_exec_h_
#include <glibmm/threads.h>
#include "ardour/libardour_visibility.h"
#include "pbd/system_exec.h"
namespace ARDOUR {
class LIBARDOUR_API SystemExec
: public PBD::SystemExec
class LIBARDOUR_API SystemExec : public PBD::SystemExec
{
public:
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 ();
int start (StdErrMode stderr_mode = IgnoreAndClose) {
return PBD::SystemExec::start (stderr_mode, _vfork_exec_wrapper);
int start (StdErrMode stderr_mode = IgnoreAndClose)
{
return PBD::SystemExec::start (stderr_mode, _vfork_exec.c_str ());
}
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_ */

View File

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