summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2015-09-01 00:14:16 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-09-01 00:14:16 +0000
commit70c958c414204b195d4195cdcafe33932087e6b1 (patch)
treee2ca4574f304dd73a00cea6c249e2c3f76baf2ec
parent9e25e1645f5e436c88ceab7d7eaf9f21c7fa845b (diff)
parenta8a795428acf5cbe1cd348aa766243203ca78b80 (diff)
downloadframeworks_base-70c958c414204b195d4195cdcafe33932087e6b1.zip
frameworks_base-70c958c414204b195d4195cdcafe33932087e6b1.tar.gz
frameworks_base-70c958c414204b195d4195cdcafe33932087e6b1.tar.bz2
Merge "Save/restore errno in SIGCHLD handler." into mnc-dr-dev
-rw-r--r--core/jni/com_android_internal_os_Zygote.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp
index 4c920dc..b431a3f 100644
--- a/core/jni/com_android_internal_os_Zygote.cpp
+++ b/core/jni/com_android_internal_os_Zygote.cpp
@@ -83,6 +83,14 @@ static void SigChldHandler(int /*signal_number*/) {
pid_t pid;
int status;
+ // It's necessary to save and restore the errno during this function.
+ // Since errno is stored per thread, changing it here modifies the errno
+ // on the thread on which this signal handler executes. If a signal occurs
+ // between a call and an errno check, it's possible to get the errno set
+ // here.
+ // See b/23572286 for extra information.
+ int saved_errno = errno;
+
while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
// Log process-death status that we care about. In general it is
// not safe to call LOG(...) from a signal handler because of
@@ -118,6 +126,8 @@ static void SigChldHandler(int /*signal_number*/) {
if (pid < 0 && errno != ECHILD) {
ALOGW("Zygote SIGCHLD error in waitpid: %s", strerror(errno));
}
+
+ errno = saved_errno;
}
// Configures the SIGCHLD handler for the zygote process. This is configured