Don't initialize atrace if it's already disabled.
For processes that start very early, atrace initialization can cause
an selinux denial, so make sure it's possible to disable it and avoid
the call to open "trace_marker".
Bug: 63927601
Test: disable atrace early in vold, ensure that selinux denial is
avoided.
Change-Id: I2422e6d0db323bc13c6d6ed1896435151fca21f7
diff --git a/libcutils/trace-dev.cpp b/libcutils/trace-dev.cpp
index 4da8215..27255c2 100644
--- a/libcutils/trace-dev.cpp
+++ b/libcutils/trace-dev.cpp
@@ -25,6 +25,7 @@
void atrace_set_tracing_enabled(bool enabled)
{
atomic_store_explicit(&atrace_is_enabled, enabled, memory_order_release);
+ atomic_store_explicit(&atrace_is_ready, false, memory_order_release);
atrace_update_tags();
}
@@ -34,18 +35,17 @@
if (atrace_marker_fd == -1) {
ALOGE("Error opening trace file: %s (%d)", strerror(errno), errno);
atrace_enabled_tags = 0;
- goto done;
+ return;
}
-
atrace_enabled_tags = atrace_get_property();
-
-done:
- atomic_store_explicit(&atrace_is_ready, true, memory_order_release);
}
void atrace_setup()
{
- pthread_once(&atrace_once_control, atrace_init_once);
+ if (atomic_load_explicit(&atrace_is_enabled, memory_order_acquire)) {
+ pthread_once(&atrace_once_control, atrace_init_once);
+ }
+ atomic_store_explicit(&atrace_is_ready, true, memory_order_release);
}
void atrace_begin_body(const char* name)