Skip to content

Commit

Permalink
Merge #1315
Browse files Browse the repository at this point in the history
1315: Don't interleave iterating over environ with unsetting environment variables r=Saviq a=AlanGriffiths

Don't interleave iterating over environ with unsetting environment variables

Co-authored-by: Alan Griffiths <alan@octopull.co.uk>
  • Loading branch information
bors[bot] and AlanGriffiths committed Feb 24, 2020
1 parent 170a05f commit d98dd7c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/miral/launch_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,36 @@

#include <stdexcept>
#include <cstring>
#include <vector>

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

std::vector<std::string> vars_to_remove;

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());
vars_to_remove.emplace_back(var_begin, var_end);
}
else
{
unsetenv(var_begin);
vars_to_remove.emplace_back(var_begin);
}
}
}

for (auto const& var : vars_to_remove)
{
unsetenv(var.c_str());
}
}
}

Expand Down

0 comments on commit d98dd7c

Please sign in to comment.