Index: sandbox/linux/services/namespace_sandbox.h |
diff --git a/sandbox/linux/services/namespace_sandbox.h b/sandbox/linux/services/namespace_sandbox.h |
index b92f5818f1bee1b4afb3cc32e260113dd6caa48b..a784360ac3335db466bd578c4b4ecbe37fbaefae 100644 |
--- a/sandbox/linux/services/namespace_sandbox.h |
+++ b/sandbox/linux/services/namespace_sandbox.h |
@@ -5,6 +5,8 @@ |
#ifndef SANDBOX_LINUX_SERVICES_NAMESPACE_SANDBOX_H_ |
#define SANDBOX_LINUX_SERVICES_NAMESPACE_SANDBOX_H_ |
+#include <sys/types.h> |
+ |
#include <string> |
#include <vector> |
@@ -47,6 +49,38 @@ class SANDBOX_EXPORT NamespaceSandbox { |
static base::Process LaunchProcess(const std::vector<std::string>& argv, |
const base::LaunchOptions& options); |
+ // Forks a process in its own PID namespace. The child process is the init |
+ // process inside of the PID namespace, so if the child needs to fork further, |
+ // it should call CreateInitProcessReaper, which turns the init process into a |
+ // reaper process. |
+ // |
+ // Otherwise, the child should setup handlers for signals which should |
+ // terminate the process using InstallDefaultTerminationSignalHandlers or |
+ // InstallTerminationSignalHandler. This works around the fact that init |
+ // processes ignore such signals unless they have an explicit handler set. |
+ // |
+ // This function requries CAP_SYS_ADMIN. If |drop_capabilities_in_child| is |
+ // true, then capabilities are dropped in the child. |
+ static pid_t ForkInNewPidNamespace(bool drop_capabilities_in_child); |
+ |
+ // Installs a signal handler for: |
+ // |
+ // SIGHUP, SIGINT, SIGABRT, SIGQUIT, SIGPIPE, SIGTERM, SIGUSR1, SIGUSR2 |
+ // |
+ // that exits with kDefaultExitCode. These are signals whose default action is |
+ // to terminate the program (apart from SIGILL, SIGFPE, and SIGSEGV, which |
+ // will still terminate the process if e.g. an illegal instruction is |
+ // encountered, etc.) |
+ static void InstallDefaultTerminationSignalHandlers(); |
jln (very slow on Chromium)
2015/03/27 21:24:35
Add to the doc that if a signal handler already ex
rickyz (no longer on Chrome)
2015/03/27 21:48:59
Done.
|
+ |
+ // Installs a signal handler for |sig| which exits with |exit_code|. Existing |
+ // signal handlers are overridden if |override_existing_handler| is true. |
+ // Returns false if |override_existing_handler| is false and a signal handler |
+ // was already set. |
+ static bool InstallTerminationSignalHandler(int sig, |
+ int exit_code, |
+ bool override_existing_handler); |
jln (very slow on Chromium)
2015/03/26 22:01:34
I don't think we need |override_existing_handler|,
rickyz (no longer on Chrome)
2015/03/27 21:08:03
The use case I was thinking of was that a user mig
jln (very slow on Chromium)
2015/03/27 21:24:36
Well, in that case, one could simply install the s
rickyz (no longer on Chrome)
2015/03/27 21:48:59
Ah, good point, removed.
|
+ |
// Returns whether the namespace sandbox created a new user, PID, and network |
// namespace. In particular, InNewUserNamespace should return true iff the |
// process was started via this class. |
@@ -54,6 +88,8 @@ class SANDBOX_EXPORT NamespaceSandbox { |
static bool InNewPidNamespace(); |
static bool InNewNetNamespace(); |
+ static const int kDefaultExitCode = 1; |
jln (very slow on Chromium)
2015/03/26 22:01:34
Style: static const members should go to top of th
rickyz (no longer on Chrome)
2015/03/27 21:08:03
Done.
|
+ |
private: |
DISALLOW_IMPLICIT_CONSTRUCTORS(NamespaceSandbox); |
}; |