aboutsummaryrefslogtreecommitdiff
path: root/paludis/util/process.cc
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-20 21:49:58 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-08-21 14:58:18 +0100
commita4733b02576a1b82cd65e64696faff97eaee5355 (patch)
tree11cd9aff88170ef8ab676bb17629b6b915f53dda /paludis/util/process.cc
parent3342ab3add1fb1a60cb60f8e0b396c07db8a9b8b (diff)
downloadpaludis-a4733b02576a1b82cd65e64696faff97eaee5355.tar.gz
paludis-a4733b02576a1b82cd65e64696faff97eaee5355.tar.xz
Process::{syd,sand}box
Diffstat (limited to 'paludis/util/process.cc')
-rw-r--r--paludis/util/process.cc64
1 files changed, 64 insertions, 0 deletions
diff --git a/paludis/util/process.cc b/paludis/util/process.cc
index 750473e7e..25fe95ca9 100644
--- a/paludis/util/process.cc
+++ b/paludis/util/process.cc
@@ -25,6 +25,8 @@
#include <paludis/util/fs_entry.hh>
#include <paludis/util/stringify.hh>
#include <paludis/util/safe_ofstream.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/system.hh>
#include <iostream>
#include <functional>
@@ -74,6 +76,12 @@ ProcessCommand::ProcessCommand(ProcessCommand && other) :
ProcessCommand::~ProcessCommand() = default;
void
+ProcessCommand::prepend_args(const std::initializer_list<std::string> & l)
+{
+ _imp->args.insert(_imp->args.begin(), l);
+}
+
+void
ProcessCommand::exec()
{
if (_imp->args.size() < 1)
@@ -698,6 +706,62 @@ Process::prefix_stderr(const std::string & s)
return *this;
}
+namespace
+{
+ bool check_cmd(const std::string & s)
+ {
+ bool result(0 == Process(ProcessCommand({ "sh", "-c", s + " --version >/dev/null 2>/dev/null" })).run().wait());
+ if (! result)
+ Log::get_instance()->message("util.system.boxless", ll_warning, lc_context) <<
+ "I don't seem to be able to use " + s;
+ return result;
+ }
+}
+
+Process &
+Process::sandbox()
+{
+ static bool can_use_sandbox(check_cmd("sandbox"));
+
+ if (can_use_sandbox)
+ {
+ if (! getenv_with_default("PALUDIS_DO_NOTHING_SANDBOXY", "").empty())
+ Log::get_instance()->message("util.system.nothing_sandboxy", ll_debug, lc_no_context)
+ << "PALUDIS_DO_NOTHING_SANDBOXY is set, not using sandbox";
+ else if (! getenv_with_default("SANDBOX_ACTIVE", "").empty())
+ Log::get_instance()->message("util.system.sandbox_in_sandbox", ll_warning, lc_no_context)
+ << "Already inside sandbox, not spawning another sandbox instance";
+ else
+ {
+ _imp->command.prepend_args({ "sandbox" });
+ if (getenv_with_default("BASH_ENV", "").empty())
+ setenv("BASH_ENV", "/dev/null");
+ }
+ }
+
+ return *this;
+}
+
+Process &
+Process::sydbox()
+{
+ static bool can_use_sydbox(check_cmd("sydbox"));
+
+ if (can_use_sydbox)
+ {
+ if (! getenv_with_default("PALUDIS_DO_NOTHING_SANDBOXY", "").empty())
+ Log::get_instance()->message("util.system.nothing_sandboxy", ll_debug, lc_no_context)
+ << "PALUDIS_DO_NOTHING_SANDBOXY is set, not using sydbox";
+ else if (! getenv_with_default("SYDBOX_ACTIVE", "").empty())
+ Log::get_instance()->message("util.system.sandbox_in_sandbox", ll_warning, lc_no_context)
+ << "Already inside sydbox, not spawning another sydbox instance";
+ else
+ _imp->command.prepend_args({ "sydbox", "--profile", "paludis", "--" });
+ }
+
+ return *this;
+}
+
namespace paludis
{
template <>