From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samuel Attard <sattard@slack-corp.com>
Date: Mon, 4 Mar 2019 14:46:48 -0800
Subject: mas: avoid usage of pthread_fchdir_np

Disable usage of pthread_fchdir_np and pthread_chdir_np in MAS builds.

diff --git a/base/process/launch_mac.cc b/base/process/launch_mac.cc
index a8713e15329431de6445e7935710d727872fd134..8874c300fd1b556a6eab5c6f20f00e5b2db9f3bc 100644
--- a/base/process/launch_mac.cc
+++ b/base/process/launch_mac.cc
@@ -26,8 +26,10 @@ extern "C" {
 // descriptor. libpthread only exposes a syscall wrapper starting in
 // macOS 10.12, but the system call dates back to macOS 10.5. On older OSes,
 // the syscall is issued directly.
+#if !defined(MAS_BUILD)
 int pthread_chdir_np(const char* dir) API_AVAILABLE(macosx(10.12));
 int pthread_fchdir_np(int fd) API_AVAILABLE(macosx(10.12));
+#endif
 
 int responsibility_spawnattrs_setdisclaim(posix_spawnattr_t attrs, int disclaim)
     API_AVAILABLE(macosx(10.14));
@@ -95,21 +97,29 @@ class PosixSpawnFileActions {
 };
 
 int ChangeCurrentThreadDirectory(const char* path) {
+  #if defined(MAS_BUILD)
+  return syscall(SYS___pthread_chdir, path);
+  #else
   if (__builtin_available(macOS 10.12, *)) {
     return pthread_chdir_np(path);
   } else {
     return syscall(SYS___pthread_chdir, path);
   }
+  #endif
 }
 
 // The recommended way to unset a per-thread cwd is to set a new value to an
 // invalid file descriptor, per libpthread-218.1.3/private/private.h.
 int ResetCurrentThreadDirectory() {
+  #if defined(MAS_BUILD)
+  return syscall(SYS___pthread_fchdir, -1);
+  #else
   if (__builtin_available(macOS 10.12, *)) {
     return pthread_fchdir_np(-1);
   } else {
     return syscall(SYS___pthread_fchdir, -1);
   }
+  #endif
 }
 
 struct GetAppOutputOptions {
@@ -229,11 +239,13 @@ Process LaunchProcess(const std::vector<std::string>& argv,
     file_actions.Inherit(STDERR_FILENO);
   }
 
+#if 0
   if (options.disclaim_responsibility) {
     if (__builtin_available(macOS 10.14, *)) {
       DPSXCHECK(responsibility_spawnattrs_setdisclaim(attr.get(), 1));
     }
   }
+#endif
 
   std::vector<char*> argv_cstr;
   argv_cstr.reserve(argv.size() + 1);
