From 6443a858a688286d8f65150720a48415d8e6d729 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Thu, 23 Feb 2017 18:46:49 -0800 Subject: [PATCH] Open /data/anr/traces.txt with O_APPEND. Should fix selinux denial: audit(0.0:7893): avc: denied { write } for path="/data/anr/traces.txt" dev="sda35" ino=679938 scontext=u:r:crash_dump:s0 tcontext=u:object_r:anr_data_file:s0 tclass=file permissive=0 Bug: 35727090 Test: none Change-Id: I5c131ca1ee48ed00934a9aa7c611ee35fc4f9f2a --- core/jni/android_os_Debug.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/core/jni/android_os_Debug.cpp b/core/jni/android_os_Debug.cpp index 3a2df75c90f91..a75848973b064 100644 --- a/core/jni/android_os_Debug.cpp +++ b/core/jni/android_os_Debug.cpp @@ -1027,17 +1027,13 @@ static void android_os_Debug_dumpNativeBacktraceToFileTimeout(JNIEnv* env, jobje env->ReleaseStringCritical(fileName, str); } - int fd = open(fileName8.string(), O_CREAT | O_WRONLY | O_NOFOLLOW, 0666); /* -rw-rw-rw- */ + int fd = open(fileName8.string(), O_CREAT | O_WRONLY | O_NOFOLLOW | O_CLOEXEC | O_APPEND, 0666); if (fd < 0) { fprintf(stderr, "Can't open %s: %s\n", fileName8.string(), strerror(errno)); return; } - if (lseek(fd, 0, SEEK_END) < 0) { - fprintf(stderr, "lseek: %s\n", strerror(errno)); - } else { - dump_backtrace_to_file_timeout(pid, fd, timeoutSecs); - } + dump_backtrace_to_file_timeout(pid, fd, timeoutSecs); close(fd); }