aboutsummaryrefslogtreecommitdiff
path: root/paludis/util/process.cc
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-20 21:44:30 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-21 14:58:18 +0100
commit3342ab3add1fb1a60cb60f8e0b396c07db8a9b8b (patch)
treeb187dfb051338c9c29c9408807de9b16bdbc1bee /paludis/util/process.cc
parente0829dd6ab62d8bd25308fc806072d1b378a1523 (diff)
downloadpaludis-3342ab3add1fb1a60cb60f8e0b396c07db8a9b8b.tar.gz
paludis-3342ab3add1fb1a60cb60f8e0b396c07db8a9b8b.tar.xz
Process::clearenv
Diffstat (limited to 'paludis/util/process.cc')
-rw-r--r--paludis/util/process.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/paludis/util/process.cc b/paludis/util/process.cc
index 82aa7b71b..750473e7e 100644
--- a/paludis/util/process.cc
+++ b/paludis/util/process.cc
@@ -376,6 +376,7 @@ namespace paludis
int set_stdin_fd;
std::map<std::string, std::string> setenvs;
+ bool clearenv;
std::string chdir;
uid_t setuid;
gid_t setgid;
@@ -393,6 +394,7 @@ namespace paludis
capture_output_to_fd_stream(0),
capture_output_to_fd_fd(-1),
set_stdin_fd(-1),
+ clearenv(false),
setuid(getuid()),
setgid(getgid()),
echo_command_to(0)
@@ -480,6 +482,26 @@ Process::run()
{
try
{
+ if (_imp->clearenv)
+ {
+ std::map<std::string, std::string> setenvs;
+ for (const char * const * it(environ) ; 0 != *it ; ++it)
+ {
+ std::string var(*it);
+ if (std::string::npos != var.find('=') &&
+ ("PALUDIS_" == var.substr(0, 8) ||
+ "PATH=" == var.substr(0, 5) ||
+ "HOME=" == var.substr(0, 5) ||
+ "LD_LIBRARY_PATH=" == var.substr(0, 16)))
+ setenvs.insert(std::make_pair(var.substr(0, var.find('=')), var.substr(var.find('=') + 1)));
+ }
+ ::clearenv();
+
+ for (std::map<std::string, std::string>::const_iterator it(setenvs.begin()),
+ it_end(setenvs.end()) ; it_end != it ; ++it)
+ ::setenv(it->first.c_str(), it->second.c_str(), 1);
+ }
+
if (thread && thread->capture_stdout_pipe)
{
if (-1 == ::dup2(thread->capture_stdout_pipe->write_fd(), STDOUT_FILENO))
@@ -625,6 +647,13 @@ Process::setenv(const std::string & a, const std::string & b)
}
Process &
+Process::clearenv()
+{
+ _imp->clearenv = true;
+ return *this;
+}
+
+Process &
Process::chdir(const FSEntry & f)
{
_imp->chdir = stringify(f.realpath_if_exists());