diff --git a/source/backend/plugin/CarlaPluginDSSI.cpp b/source/backend/plugin/CarlaPluginDSSI.cpp index a7ffc52f3..181edace7 100644 --- a/source/backend/plugin/CarlaPluginDSSI.cpp +++ b/source/backend/plugin/CarlaPluginDSSI.cpp @@ -26,6 +26,7 @@ #ifdef HAVE_LIBLO # include "CarlaOscUtils.hpp" +# include "CarlaPipeUtils.hpp" # include "CarlaThread.hpp" #endif @@ -146,55 +147,33 @@ public: { #ifdef CARLA_OS_LINUX - const ScopedEngineEnvironmentLocker _seel(kEngine); + /* + * If the frontend uses winId parent, set LD_PRELOAD to auto-map the DSSI UI. + * If not, unset LD_PRELOAD. + */ + const uintptr_t winId(kEngine->getOptions().frontendWinId); - // get current LD_PRELOAD, will restore it later - const char* const oldPreload(std::getenv("LD_PRELOAD")); + // for CARLA_ENGINE_OPTION_FRONTEND_WIN_ID + char winIdStr[STR_MAX+1]; + winIdStr[STR_MAX] = '\0'; -# ifdef HAVE_X11 - // if the frontend uses winId parent, set LD_PRELOAD to auto-map the DSSI UI - const uintptr_t winId = kEngine->getOptions().frontendWinId; + // for LD_PRELOAD + CarlaString ldPreloadValue; if (winId != 0) { - char strBuf[STR_MAX+1]; - strBuf[STR_MAX] = '\0'; - std::snprintf(strBuf, STR_MAX, P_UINTPTR, kEngine->getOptions().frontendWinId); - ::setenv("CARLA_ENGINE_OPTION_FRONTEND_WIN_ID", strBuf, 1); - - CarlaString interposerPath(CarlaString(kEngine->getOptions().binaryDir) + - CARLA_OS_SEP_STR "libcarla_interposer-x11.so"); - ::setenv("LD_PRELOAD", interposerPath.buffer(), 1); + std::snprintf(winIdStr, STR_MAX, P_UINTPTR, kEngine->getOptions().frontendWinId); + ldPreloadValue = (CarlaString(kEngine->getOptions().binaryDir) + CARLA_OS_SEP_STR "libcarla_interposer-x11.so"); } - else -# else - // if no X11 or winId set, simply unset LD_PRELOAD - // (it might be set to libcarla_interposer-safe) - if (oldPreload != nullptr) - ::unsetenv("LD_PRELOAD"); -# endif + + const ScopedEngineEnvironmentLocker _seel(kEngine); + const ScopedEnvVar _sev1("CARLA_ENGINE_OPTION_FRONTEND_WIN_ID", winIdStr[0] != '\0' ? winIdStr : nullptr); + const ScopedEnvVar _sev2("LD_PRELOAD", ldPreloadValue.isNotEmpty() ? ldPreloadValue.buffer() : nullptr); #endif // CARLA_OS_LINUX // start the DSSI UI application carla_stdout("starting DSSI UI..."); started = fProcess->start(arguments); - -#ifdef CARLA_OS_LINUX - // restore initial state - if (oldPreload != nullptr) - { - ::setenv("LD_PRELOAD", oldPreload, 1); - } -# ifdef HAVE_X11 - if (winId != 0) - { - ::unsetenv("CARLA_ENGINE_OPTION_FRONTEND_WIN_ID"); - - if (oldPreload == nullptr) - ::unsetenv("LD_PRELOAD"); - } -# endif -#endif // CARLA_OS_LINUX } if (! started)