diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2020-06-10 01:03:10 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2020-06-10 01:03:10 +0000 |
commit | ea98341b5049806d56cf4a9c89b560c6f1dd3da6 (patch) | |
tree | 0836a0c8dce0e15b31fe3a9ac5e15c7f32ac2d41 | |
parent | 5a8f93001abb31df064b7d17a4c6bdc7b57848ba (diff) | |
parent | c8c3bc58a1e2acb1048e2fb4f2914f60e0977942 (diff) | |
download | bionic-ea98341b5049806d56cf4a9c89b560c6f1dd3da6.tar.gz |
Snap for 6573866 from c8c3bc58a1e2acb1048e2fb4f2914f60e0977942 to rvc-release
Change-Id: I8a13b8d03a64177fffcc01eaba75bf5968807a20
-rw-r--r-- | libc/bionic/fork.cpp | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/libc/bionic/fork.cpp b/libc/bionic/fork.cpp index cda5e8533..3814ed0ac 100644 --- a/libc/bionic/fork.cpp +++ b/libc/bionic/fork.cpp @@ -34,23 +34,27 @@ #include "pthread_internal.h" __BIONIC_WEAK_FOR_NATIVE_BRIDGE -int fork() { - __bionic_atfork_run_prepare(); - +int __clone_for_fork() { pthread_internal_t* self = __get_thread(); - int result = clone(nullptr, - nullptr, - (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD), - nullptr, - nullptr, - nullptr, - &(self->tid)); + int result = clone(nullptr, nullptr, (CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD), + nullptr, nullptr, nullptr, &(self->tid)); + if (result == 0) { - // Update the cached pid, since clone() will not set it directly (as + // Update the cached pid in child, since clone() will not set it directly (as // self->tid is updated by the kernel). self->set_cached_pid(gettid()); + } + return result; +} + +int fork() { + __bionic_atfork_run_prepare(); + + int result = __clone_for_fork(); + + if (result == 0) { // Disable fdsan post-fork, so we don't falsely trigger on processes that // fork, close all of their fds blindly, and then exec. android_fdsan_set_error_level(ANDROID_FDSAN_ERROR_LEVEL_DISABLED); |