fdtrack: don't do anything while vforked.

Bug: http://b/153926671
Test: 32/64-bit bionic-unit-tests on blueline, x86_64 emulator
Change-Id: If42905f3d6a76ed70a45e5b9edd029ffd7789045
diff --git a/libc/private/bionic_fdtrack.h b/libc/private/bionic_fdtrack.h
index 174ba1d..752dd8d 100644
--- a/libc/private/bionic_fdtrack.h
+++ b/libc/private/bionic_fdtrack.h
@@ -47,7 +47,8 @@
 #define FDTRACK_CREATE_NAME(name, fd_value)                       \
   ({                                                              \
     int __fd = (fd_value);                                        \
-    if (__fd != -1 && __predict_false(__android_fdtrack_hook)) {  \
+    if (__fd != -1 && __predict_false(__android_fdtrack_hook) &&  \
+        !__predict_false(__get_thread()->is_vforked())) {         \
       bionic_tls& tls = __get_bionic_tls();                       \
       /* fdtrack_disabled is only true during reentrant calls. */ \
       if (!__predict_false(tls.fdtrack_disabled)) {               \
@@ -76,7 +77,8 @@
 #define FDTRACK_CLOSE(fd_value)                                  \
   ({                                                             \
     int __fd = (fd_value);                                       \
-    if (__fd != -1 && __predict_false(__android_fdtrack_hook)) { \
+    if (__fd != -1 && __predict_false(__android_fdtrack_hook) && \
+        !__predict_false(__get_thread()->is_vforked())) {        \
       bionic_tls& tls = __get_bionic_tls();                      \
       if (!__predict_false(tls.fdtrack_disabled)) {              \
         int saved_errno = errno;                                 \
diff --git a/tests/fdtrack_test.cpp b/tests/fdtrack_test.cpp
index bfa3dd1..44aa033 100644
--- a/tests/fdtrack_test.cpp
+++ b/tests/fdtrack_test.cpp
@@ -257,4 +257,24 @@
   ASSERT_EQ(3, ReceiveFileDescriptors(sockets[1], buf, sizeof(buf), &received_fd));
   received_fd.release();
 }));
+
+FDTRACK_TEST_NAME(vfork, "open", ({
+  int fd = open("/dev/null", O_RDONLY);
+
+  pid_t rc = vfork();
+  ASSERT_NE(-1, rc);
+
+  if (rc == 0) {
+    close(fd);
+    _exit(0);
+  }
+
+  int status;
+  pid_t wait_result = waitpid(rc, &status, 0);
+  ASSERT_EQ(wait_result, rc);
+  ASSERT_TRUE(WIFEXITED(status));
+  ASSERT_EQ(0, WEXITSTATUS(status));
+
+  fd;
+}));
 // clang-format on