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

Unified Diff: sandbox/mac/seatbelt.cc

Issue 2914693002: Add IsSandboxed() function to seatbelt wrapper. (Closed)
Patch Set: Improve function documentation Created 3 years, 7 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
« no previous file with comments | « sandbox/mac/seatbelt.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/mac/seatbelt.cc
diff --git a/sandbox/mac/seatbelt.cc b/sandbox/mac/seatbelt.cc
index 0987faee7aa54f299cc59768b680bc944b6bd8be..dfba0bded9e34be276ed111cbab44210a95b9875 100644
--- a/sandbox/mac/seatbelt.cc
+++ b/sandbox/mac/seatbelt.cc
@@ -4,6 +4,8 @@
#include "sandbox/mac/seatbelt.h"
+#include <unistd.h>
+
extern "C" {
#include <sandbox.h>
@@ -11,6 +13,12 @@ int sandbox_init_with_parameters(const char* profile,
uint64_t flags,
const char* const parameters[],
char** errorbuf);
+
+// Not deprecated. The canonical usage to test if sandboxed is
+// sandbox_check(getpid(), NULL, SANDBOX_FILTER_NONE), which returns
+// 1 if sandboxed. Note `type` is actually a sandbox_filter_type enum value, but
+// it is unused currently.
+int sandbox_check(pid_t pid, const char* operation, int type, ...);
};
namespace sandbox {
@@ -54,4 +62,9 @@ void Seatbelt::FreeError(char* errorbuf) {
#pragma clang diagnostic pop
}
+// static
+bool Seatbelt::IsSandboxed() {
+ return ::sandbox_check(getpid(), NULL, 0);
+}
+
} // namespace sandbox
« no previous file with comments | « sandbox/mac/seatbelt.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698