[Cocoa] Streamline sandbox code a tiny bit
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Dec 2018 16:45:42 +0000 (16:45 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Dec 2018 16:45:42 +0000 (16:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=192299

Reviewed by Anders Carlsson.

* Shared/mac/SandboxUtilities.mm:
(WebKit::processHasContainer): Removed separate function, just use the
pathForProcessContainer instead of repeating logic. This costs a tiny
bit of memory allocation overhead the first time this function is called,
but in return we can eliminate a second copy of the code to call
sandbox_container_path_for_pid.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@238797 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/Shared/mac/SandboxUtilities.mm

index cd5d405..bbd9821 100644 (file)
@@ -1,3 +1,17 @@
+2018-12-03  Darin Adler  <darin@apple.com>
+
+        [Cocoa] Streamline sandbox code a tiny bit
+        https://bugs.webkit.org/show_bug.cgi?id=192299
+
+        Reviewed by Anders Carlsson.
+
+        * Shared/mac/SandboxUtilities.mm:
+        (WebKit::processHasContainer): Removed separate function, just use the
+        pathForProcessContainer instead of repeating logic. This costs a tiny
+        bit of memory allocation overhead the first time this function is called,
+        but in return we can eliminate a second copy of the code to call
+        sandbox_container_path_for_pid.
+
 2018-12-03  Eric Carlson  <eric.carlson@apple.com>
 
         [MediaStream] 'devicechange' event when more capture device information are revealed.
index dc350fb..85d5482 100644 (file)
@@ -47,23 +47,9 @@ bool connectedProcessIsSandboxed(xpc_connection_t connectionToParent)
     return sandbox_check_by_audit_token(token, nullptr, SANDBOX_FILTER_NONE);
 }
 
-static bool processHasContainer(pid_t pid)
-{
-    std::array<char, MAXPATHLEN> path;
-
-    if (sandbox_container_path_for_pid(pid, path.data(), path.size()))
-        return false;
-
-    if (!path[0])
-        return false;
-
-    return true;
-}
-
 bool processHasContainer()
 {
-    static bool hasContainer = processHasContainer(getpid());
-
+    static bool hasContainer = !pathForProcessContainer().isEmpty();
     return hasContainer;
 }