Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1283)

Unified Diff: sandbox/linux/services/scoped_process.h

Issue 188193002: Linux sandbox: add basic Yama support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Add testing. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sandbox/linux/services/scoped_process.h
diff --git a/sandbox/linux/services/scoped_process.h b/sandbox/linux/services/scoped_process.h
new file mode 100644
index 0000000000000000000000000000000000000000..e1aeca4bbfbd010e64d3c6f50b870c4654c65339
--- /dev/null
+++ b/sandbox/linux/services/scoped_process.h
@@ -0,0 +1,43 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SANDBOX_LINUX_SERVICES_SCOPED_PROCESS_H_
+#define SANDBOX_LINUX_SERVICES_SCOPED_PROCESS_H_
+
+#include "base/basictypes.h"
+#include "base/callback.h"
+#include "base/process/process_handle.h"
+
+namespace sandbox {
+
+// fork() a child process that will run a Closure. After the Closure
+// has run, the child will exit. If this object goes out of scope, the child
+// will be destroyed, even if the closure did not finish running.
+class ScopedProcess {
+ public:
+ // |child_callback| will run in the child process. It can simply return
+ // in which case the child process will exit normally. Or it can use
+ // _exit(2) to exit.
+ explicit ScopedProcess(const base::Closure& child_callback);
+ ~ScopedProcess();
+
+ // Wait for the process to exit, that is, wait for the closure to finish
+ // running.
+ // |got_signaled| tells how to interpret the return value: either as an exit
+ // code, or as a signal number.
+ int WaitForExit(bool* got_signaled);
+ base::ProcessId GetPid() { return child_process_id_; }
+
+ private:
+ bool IsOriginalProcess();
+
+ base::Closure child_callback_;
+ base::ProcessId child_process_id_;
+ base::ProcessId process_id_;
+ DISALLOW_COPY_AND_ASSIGN(ScopedProcess);
+};
+
+} // namespace sandbox
+
+#endif // SANDBOX_LINUX_SERVICES_SCOPED_PROCESS_H_

Powered by Google App Engine
This is Rietveld 408576698