From 82d491cb8080acee348306e708375a8d52bab36b Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 1 Apr 2022 18:11:05 +0200 Subject: [PATCH] Allow to unset LD_LIBRARY_PATH on exec This is useful when using distro-packaged video-tools (e.g. on Linux/ARM), or when running post-export commands. --- libs/ardour/ardour/system_exec.h | 6 +++--- libs/ardour/system_exec.cc | 12 ++++++------ libs/pbd/pbd/system_exec.h | 22 +++++++++++----------- libs/pbd/system_exec.cc | 21 +++++++++++++-------- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/libs/ardour/ardour/system_exec.h b/libs/ardour/ardour/system_exec.h index b126fa1a1d..723fcca63f 100644 --- a/libs/ardour/ardour/system_exec.h +++ b/libs/ardour/ardour/system_exec.h @@ -28,9 +28,9 @@ namespace ARDOUR { 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, const std::map subs); + SystemExec (std::string cmd, std::string argv = "", bool supress_ld_env = false); + SystemExec (std::string cmd, char** argv, bool supress_ld_env = false); + SystemExec (std::string cmd, const std::map subs, bool supress_ld_env = false); ~SystemExec (); int start (StdErrMode stderr_mode = IgnoreAndClose) diff --git a/libs/ardour/system_exec.cc b/libs/ardour/system_exec.cc index 3ab8fd45dc..aa1f66bd80 100644 --- a/libs/ardour/system_exec.cc +++ b/libs/ardour/system_exec.cc @@ -56,20 +56,20 @@ SystemExec::initialize () _initialized = true; } -SystemExec::SystemExec (std::string c, char** a) - : PBD::SystemExec (c, a) +SystemExec::SystemExec (std::string cmd, char** argv, bool supress_ld_env) + : PBD::SystemExec (cmd, argv, supress_ld_env) { initialize (); } -SystemExec::SystemExec (std::string c, std::string a) - : PBD::SystemExec (c, a) +SystemExec::SystemExec (std::string cmd, std::string argv, bool supress_ld_env) + : PBD::SystemExec (cmd, argv, supress_ld_env) { initialize (); } -SystemExec::SystemExec (std::string c, const std::map subs) - : PBD::SystemExec (c, subs) +SystemExec::SystemExec (std::string cmd, const std::map subs, bool supress_ld_env) + : PBD::SystemExec (cmd, subs, supress_ld_env) { initialize (); } diff --git a/libs/pbd/pbd/system_exec.h b/libs/pbd/pbd/system_exec.h index 6a4fe05e00..e7fec70f5d 100644 --- a/libs/pbd/pbd/system_exec.h +++ b/libs/pbd/pbd/system_exec.h @@ -82,22 +82,23 @@ class LIBPBD_API SystemExec * The alternative constructor below allows to specify quoted parameters * incl. whitespace. * - * @param c program pathname that identifies the new process image file. - * @param a string of commandline-arguments to be passed to the new program. + * @param cmd program pathname that identifies the new process image file. + * @param argv string of commandline-arguments to be passed to the new program. + * @param supress_ld_env On Linux, unset LD_LIBRARY_PATH environment variable */ - SystemExec (std::string c, std::string a = ""); + SystemExec (std::string cmd, std::string argv = "", bool supress_ld_env = false); /** similar to \ref SystemExec but allows to specify custom arguments * - * @param c program pathname that identifies the new process image file. - * @param a array of argument strings passed to the new program as 'argv'. + * @param cmd program pathname that identifies the new process image file. + * @param argv array of argument strings passed to the new program as 'argv'. * it must be terminated by a null pointer (see the 'evecve' * POSIX-C documentation for more information) * The array must be dynamically allocated using malloc or strdup. * Unless they're NULL, the array itself and each of its content * memory is freed() in the destructor. - * + * @param supress_ld_env On Linux, unset LD_LIBRARY_PATH environment variable */ - SystemExec (std::string c, char ** a); + SystemExec (std::string cmd, char **argv, bool supress_ld_env = false); /** similar to \ref SystemExec but expects a whole command line, and * handles some simple escape sequences. @@ -111,10 +112,9 @@ class LIBPBD_API SystemExec * "\ " is non-splitting space, "\\" (and "\" at end of command) as "\", * for "%", \ is looked up in subs and the corresponding string * substituted. "%%" (and "%" at end of command) - * - * @returns an argv array suitable for creating a new SystemExec with + * @param supress_ld_env On Linux, unset LD_LIBRARY_PATH environment variable */ - SystemExec (std::string command, const std::map subs); + SystemExec (std::string command, const std::map subs, bool supress_ld_env = false); virtual ~SystemExec (); @@ -231,7 +231,7 @@ class LIBPBD_API SystemExec void make_argp(std::string); void make_argp_escaped(std::string command, const std::map subs); - void make_envp(); + void make_envp (bool supress_ld_env); char **argp; char **envp; diff --git a/libs/pbd/system_exec.cc b/libs/pbd/system_exec.cc index 70ea91b847..140340f55f 100644 --- a/libs/pbd/system_exec.cc +++ b/libs/pbd/system_exec.cc @@ -79,17 +79,17 @@ SystemExec::init () #endif } -SystemExec::SystemExec (std::string c, std::string a) +SystemExec::SystemExec (std::string c, std::string a, bool supress_ld_env) : cmd(c) { init (); argp = NULL; - make_envp(); + make_envp (supress_ld_env); make_argp(a); } -SystemExec::SystemExec (std::string c, char **a) +SystemExec::SystemExec (std::string c, char **a, bool supress_ld_env) : cmd(c) , argp(a) { init (); @@ -97,10 +97,10 @@ SystemExec::SystemExec (std::string c, char **a) #ifdef PLATFORM_WINDOWS make_wargs(a); #endif - make_envp(); + make_envp (supress_ld_env); } -SystemExec::SystemExec (std::string command, const std::map subs) +SystemExec::SystemExec (std::string command, const std::map subs, bool supress_ld_env) { init (); make_argp_escaped(command, subs); @@ -141,7 +141,7 @@ SystemExec::SystemExec (std::string command, const std::map s // Glib::find_program_in_path () is only available in Glib >= 2.28 // cmd = Glib::find_program_in_path (argp[0]); #endif - make_envp(); + make_envp (supress_ld_env); } char* @@ -364,7 +364,7 @@ CALLBACK my_terminateApp(HWND hwnd, LPARAM procId) /* PROCESS API */ void -SystemExec::make_envp() +SystemExec::make_envp (bool) { ; /* environemt is copied over with CreateProcess(...,env=0 ,..) */ } @@ -594,12 +594,17 @@ SystemExec::write_to_stdin (const void* data, size_t bytes) extern char **environ; void -SystemExec::make_envp() +SystemExec::make_envp (bool supress_ld_env) { int i = 0; envp = (char **) calloc(1, sizeof(char*)); /* copy current environment */ for (i = 0; environ[i]; ++i) { +#ifndef __APPLE__ + if (supress_ld_env && 0 == strncmp (environ[i], "LD_LIBRARY_PATH=", 17)) { + continue; + } +#endif envp[i] = strdup(environ[i]); envp = (char **) realloc(envp, (i+2) * sizeof(char*)); }