aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-08-23 16:22:39 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-08-23 16:22:50 +0100
commitefe1d56f129dea213603e2f2b58c14e529f2695f (patch)
tree28e8221b28dc08af79ba84b37151b7a8dff09232
parentffb0552e3490960611ca7a90080be8ac46d3bdea (diff)
downloadpaludis-efe1d56f129dea213603e2f2b58c14e529f2695f.tar.gz
paludis-efe1d56f129dea213603e2f2b58c14e529f2695f.tar.xz
Check sandbox and sydbox at runtime
-rw-r--r--configure.ac31
-rw-r--r--paludis/util/system.cc64
2 files changed, 41 insertions, 54 deletions
diff --git a/configure.ac b/configure.ac
index d91ac4a..38db78c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -867,37 +867,6 @@ AC_SUBST([PALUDIS_CXXFLAGS_NO_DEBUGGING])
dnl }}}
-dnl {{{ sandbox and sydbox
-AC_MSG_CHECKING([whether to enable sandbox])
-AC_ARG_ENABLE([sandbox],
- AS_HELP_STRING([--enable-sandbox], [Enable sandbox]),
- [HAVE_SANDBOX=$enableval
- AC_MSG_RESULT([$enableval])],
- [AC_MSG_RESULT([autodetect])
- AC_CHECK_PROG(HAVE_SANDBOX, [sandbox], [yes], [no])])
-AC_SUBST([HAVE_SANDBOX])
-AM_CONDITIONAL([HAVE_SANDBOX], test "x$HAVE_SANDBOX" = "xyes")
-if test x"$HAVE_SANDBOX" = "xyes" ; then
- AC_DEFINE([HAVE_SANDBOX], 1, [Do we have sandbox?])
-else
- AC_DEFINE([HAVE_SANDBOX], 0)
-fi
-AC_MSG_CHECKING([whether to enable sydbox])
-AC_ARG_ENABLE([sydbox],
- AS_HELP_STRING([--enable-sydbox], [Enable sydbox]),
- [HAVE_SYDBOX=$enableval
- AC_MSG_RESULT([$enableval])],
- [AC_MSG_RESULT([autodetect])
- AC_CHECK_PROG(HAVE_SYDBOX, [sydbox], [yes], [no])])
-AC_SUBST([HAVE_SYDBOX])
-AM_CONDITIONAL([HAVE_SYDBOX], test "x$HAVE_SYDBOX" = "xyes")
-if test x"$HAVE_SYDBOX" = "xyes" ; then
- AC_DEFINE([HAVE_SYDBOX], 1, [Do we have sydbox?])
-else
- AC_DEFINE([HAVE_SYDBOX], 0)
-fi
-dnl }}}
-
dnl {{{ doxygen
AC_MSG_CHECKING([whether to enable doxygen])
AC_ARG_ENABLE([doxygen],
diff --git a/paludis/util/system.cc b/paludis/util/system.cc
index 21480ab..427019f 100644
--- a/paludis/util/system.cc
+++ b/paludis/util/system.cc
@@ -293,23 +293,38 @@ Command::with_ptys()
return *this;
}
+namespace
+{
+ bool check_cmd(const std::string & s)
+ {
+ bool result(0 == run_command(Command(s + " --version >/dev/null 2>/dev/null")));
+ 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;
+ }
+}
+
Command &
Command::with_sandbox()
{
-#if HAVE_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
+ static bool can_use_sandbox(check_cmd("sandbox"));
+
+ if (can_use_sandbox)
{
- _imp->command = "sandbox " + _imp->command;
- if (getenv_with_default("BASH_ENV", "").empty())
- with_setenv("BASH_ENV", "/dev/null");
+ 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 = "sandbox " + _imp->command;
+ if (getenv_with_default("BASH_ENV", "").empty())
+ with_setenv("BASH_ENV", "/dev/null");
+ }
}
-#endif
return *this;
}
@@ -317,17 +332,20 @@ Command::with_sandbox()
Command &
Command::with_sydbox()
{
-#if HAVE_SYDBOX
- struct stat buf;
- 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 (-1 != stat("/dev/sydbox", &buf))
- 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 = "sydbox -- " + _imp->command;
-#endif
+ static bool can_use_sydbox(check_cmd("sydbox"));
+
+ if (can_use_sydbox)
+ {
+ struct stat buf;
+ 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 (-1 != stat("/dev/sydbox", &buf))
+ 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 = "sydbox -- " + _imp->command;
+ }
return *this;
}