Skip to content

Commit

Permalink
Merge #1303
Browse files Browse the repository at this point in the history
1303: Strip out any MIR_* environment variables when launching apps r=wmww a=AlanGriffiths

Strip out any MIR_* environment variables when launching apps

These can cause annoyance when launching Mir compositors (such as tests) from a Mir Shell.

Co-authored-by: Alan Griffiths <[email protected]>
  • Loading branch information
bors[bot] and AlanGriffiths committed Feb 21, 2020
1 parent b4223f3 commit 9ce32b5
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/miral/launch_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,30 @@
#include <stdexcept>
#include <cstring>

namespace
{
void strip_mir_env_variables()
{
static char const mir_prefix[] = "MIR_";

for (auto var = environ; *var; ++var)
{
auto const var_begin = *var;
if (strncmp(var_begin, mir_prefix, sizeof(mir_prefix) - 1) == 0)
{
if (auto var_end = strchr(var_begin, '='))
{
unsetenv(std::string(var_begin, var_end).c_str());
}
else
{
unsetenv(var_begin);
}
}
}
}
}

auto miral::launch_app(
std::vector<std::string> const& app,
mir::optional_value<std::string> const& wayland_display,
Expand All @@ -39,6 +63,8 @@ auto miral::launch_app(

if (pid == 0)
{
strip_mir_env_variables();

std::string gdk_backend;
std::string qt_qpa_platform;
std::string sdl_videodriver;
Expand Down Expand Up @@ -128,6 +154,8 @@ auto miral::launch_app_env(

if (pid == 0)
{
strip_mir_env_variables();

if (x11_display)
{
setenv("DISPLAY", x11_display.value().c_str(), true); // configure X11 socket
Expand Down

0 comments on commit 9ce32b5

Please sign in to comment.