summaryrefslogtreecommitdiff
path: root/libcutils/trace-dev.inc
diff options
context:
space:
mode:
Diffstat (limited to 'libcutils/trace-dev.inc')
-rw-r--r--libcutils/trace-dev.inc38
1 files changed, 25 insertions, 13 deletions
diff --git a/libcutils/trace-dev.inc b/libcutils/trace-dev.inc
index 3b459e094..654342649 100644
--- a/libcutils/trace-dev.inc
+++ b/libcutils/trace-dev.inc
@@ -21,7 +21,6 @@
#include <errno.h>
#include <fcntl.h>
-#include <fnmatch.h>
#include <limits.h>
#include <pthread.h>
#include <stdatomic.h>
@@ -52,6 +51,7 @@ constexpr uint32_t kSeqNoNotInit = static_cast<uint32_t>(-1);
atomic_bool atrace_is_ready = ATOMIC_VAR_INIT(false);
int atrace_marker_fd = -1;
uint64_t atrace_enabled_tags = ATRACE_TAG_NOT_READY;
+static bool atrace_is_debuggable = false;
static atomic_bool atrace_is_enabled = ATOMIC_VAR_INIT(true);
static pthread_mutex_t atrace_tags_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -95,6 +95,15 @@ uint64_t atrace_get_enabled_tags()
return atrace_enabled_tags;
}
+// Set whether this process is debuggable, which determines whether
+// application-level tracing is allowed when the ro.debuggable system property
+// is not set to '1'.
+void atrace_set_debuggable(bool debuggable)
+{
+ atrace_is_debuggable = debuggable;
+ atrace_update_tags();
+}
+
// Check whether the given command line matches one of the comma-separated
// values listed in the app_cmdlines property.
static bool atrace_is_cmdline_match(const char* cmdline)
@@ -107,7 +116,7 @@ static bool atrace_is_cmdline_match(const char* cmdline)
for (int i = 0; i < count; i++) {
snprintf(buf, sizeof(buf), "debug.atrace.app_%d", i);
property_get(buf, value, "");
- if (fnmatch(value, cmdline, FNM_NOESCAPE) == 0) {
+ if (strcmp(value, "*") == 0 || strcmp(value, cmdline) == 0) {
return true;
}
}
@@ -118,21 +127,24 @@ static bool atrace_is_cmdline_match(const char* cmdline)
// Determine whether application-level tracing is enabled for this process.
static bool atrace_is_app_tracing_enabled()
{
+ bool sys_debuggable = property_get_bool("ro.debuggable", 0);
bool result = false;
- // Check whether tracing is enabled for this process.
- FILE * file = fopen("/proc/self/cmdline", "re");
- if (file) {
- char cmdline[4096];
- if (fgets(cmdline, sizeof(cmdline), file)) {
- result = atrace_is_cmdline_match(cmdline);
+ if (sys_debuggable || atrace_is_debuggable) {
+ // Check whether tracing is enabled for this process.
+ FILE * file = fopen("/proc/self/cmdline", "re");
+ if (file) {
+ char cmdline[4096];
+ if (fgets(cmdline, sizeof(cmdline), file)) {
+ result = atrace_is_cmdline_match(cmdline);
+ } else {
+ ALOGE("Error reading cmdline: %s (%d)", strerror(errno), errno);
+ }
+ fclose(file);
} else {
- ALOGE("Error reading cmdline: %s (%d)", strerror(errno), errno);
+ ALOGE("Error opening /proc/self/cmdline: %s (%d)", strerror(errno),
+ errno);
}
- fclose(file);
- } else {
- ALOGE("Error opening /proc/self/cmdline: %s (%d)", strerror(errno),
- errno);
}
return result;