Disable fdtrack post-fork.

Also delete some fdsan code that attempts to check for the post-fork
state, but never will, because we update the cached pid upon fork.

Bug: http://b/174542867
Test: /data/nativetest64/bionic-unit-tests/bionic-unit-tests
Test: treehugger
Change-Id: I9b748dac9de9b4c741897d93e64d31737e52bf8e
diff --git a/libc/bionic/fdsan.cpp b/libc/bionic/fdsan.cpp
index 043510c..48e8674 100644
--- a/libc/bionic/fdsan.cpp
+++ b/libc/bionic/fdsan.cpp
@@ -137,14 +137,6 @@
     return;
   }
 
-  // Lots of code will (sensibly) fork, call close on all of their fds,
-  // and then exec. Compare our cached pid value against the real one to detect
-  // this scenario and permit it.
-  pid_t cached_pid = __get_cached_pid();
-  if (cached_pid == 0 || cached_pid != syscall(__NR_getpid)) {
-    return;
-  }
-
   struct {
     size_t size;
     char buf[512];
diff --git a/libc/bionic/fdtrack.cpp b/libc/bionic/fdtrack.cpp
index 1123512..89a208f 100644
--- a/libc/bionic/fdtrack.cpp
+++ b/libc/bionic/fdtrack.cpp
@@ -37,8 +37,14 @@
 
 _Atomic(android_fdtrack_hook_t) __android_fdtrack_hook;
 
+bool __android_fdtrack_globally_disabled = false;
+
+void android_fdtrack_set_globally_enabled(bool new_value) {
+  __android_fdtrack_globally_disabled = !new_value;
+}
+
 bool android_fdtrack_get_enabled() {
-  return !__get_bionic_tls().fdtrack_disabled;
+  return !__get_bionic_tls().fdtrack_disabled && !__android_fdtrack_globally_disabled;
 }
 
 bool android_fdtrack_set_enabled(bool new_value) {
diff --git a/libc/bionic/fork.cpp b/libc/bionic/fork.cpp
index 8c5cf2b..d432c6d 100644
--- a/libc/bionic/fork.cpp
+++ b/libc/bionic/fork.cpp
@@ -31,6 +31,7 @@
 #include <android/fdsan.h>
 
 #include "private/bionic_defs.h"
+#include "private/bionic_fdtrack.h"
 #include "pthread_internal.h"
 
 __BIONIC_WEAK_FOR_NATIVE_BRIDGE_INLINE
@@ -55,9 +56,10 @@
   int result = __clone_for_fork();
 
   if (result == 0) {
-    // Disable fdsan post-fork, so we don't falsely trigger on processes that
+    // Disable fdsan and fdtrack post-fork, so we don't falsely trigger on processes that
     // fork, close all of their fds, and then exec.
     android_fdsan_set_error_level(ANDROID_FDSAN_ERROR_LEVEL_DISABLED);
+    android_fdtrack_set_globally_enabled(false);
 
     // Reset the stack_and_tls VMA name so it doesn't end with a tid from the
     // parent process.