summaryrefslogtreecommitdiff
path: root/debuggerd/libdebuggerd/utility.cpp
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2017-03-15 23:23:22 -0700
committerJosh Gao <jmgao@google.com>2017-03-15 23:30:14 -0700
commit57f58f8e4a143f1208593c8b397b9a17d055dad0 (patch)
tree6760dea6ea2582cf8edfc527a0addf525142fca6 /debuggerd/libdebuggerd/utility.cpp
parente7b335b4712bc650c93b5b5777a6f8b1d85ad83f (diff)
crash_dump: fetch process/thread names before dropping privileges.
Processes that don't have dumpable set to 1 cannot have their process/thread names read by processes that don't have all of their capabilities. Fetch these names in crash_dump before dropping privileges. Bug: http://b/36237221 Test: debuggerd_test Test: debuggerd -b `pidof android.hardware.bluetooth@1.0-service` Change-Id: I174769e7b3c1ea9f11f9c8cbdff83028a4225783
Diffstat (limited to 'debuggerd/libdebuggerd/utility.cpp')
-rw-r--r--debuggerd/libdebuggerd/utility.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/debuggerd/libdebuggerd/utility.cpp b/debuggerd/libdebuggerd/utility.cpp
index 744cd72af..22fde5ea4 100644
--- a/debuggerd/libdebuggerd/utility.cpp
+++ b/debuggerd/libdebuggerd/utility.cpp
@@ -28,6 +28,7 @@
#include <string>
#include <android-base/stringprintf.h>
+#include <android-base/unique_fd.h>
#include <backtrace/Backtrace.h>
#include <log/log.h>
@@ -202,3 +203,20 @@ void dump_memory(log_t* log, Backtrace* backtrace, uintptr_t addr, const char* f
_LOG(log, logtype::MEMORY, "%s %s\n", logline.c_str(), ascii.c_str());
}
}
+
+void read_with_default(const char* path, char* buf, size_t len, const char* default_value) {
+ android::base::unique_fd fd(open(path, O_RDONLY));
+ if (fd != -1) {
+ int rc = TEMP_FAILURE_RETRY(read(fd.get(), buf, len - 1));
+ if (rc != -1) {
+ buf[rc] = '\0';
+
+ // Trim trailing newlines.
+ if (rc > 0 && buf[rc - 1] == '\n') {
+ buf[rc - 1] = '\0';
+ }
+ return;
+ }
+ }
+ strcpy(buf, default_value);
+}