From 635ca31754ae734b0c540ac5600d58ae55cd4237 Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Tue, 5 Jan 2016 14:23:02 -0800 Subject: [PATCH] Include mount info on zipped bugreport. BUG: 7280247 Change-Id: Iae2a7881c11564c8dbd3641f5ee5ab72c181da2a --- cmds/dumpstate/dumpstate.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++-- cmds/dumpstate/utils.cpp | 2 +- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index 296dad4428..8dcca3484b 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -56,6 +57,9 @@ static const char *dump_traces_path = NULL; static char build_type[PROPERTY_VALUE_MAX]; static time_t now; static std::unique_ptr zip_writer; +static std::set mount_points; +void add_mountinfo(); +static bool add_zip_entry(const std::string& entry_name, const std::string& entry_path); #define PSTORE_LAST_KMSG "/sys/fs/pstore/console-ramoops" @@ -96,6 +100,41 @@ static void get_tombstone_fds(tombstone_data_t data[NUM_TOMBSTONES]) { } } +// for_each_pid() callback to get mount info about a process. +void do_mountinfo(int pid, const char *name) { + char path[PATH_MAX]; + + // Gets the the content of the /proc/PID/ns/mnt link, so only unique mount points + // are added. + sprintf(path, "/proc/%d/ns/mnt", pid); + char linkname[PATH_MAX]; + ssize_t r = readlink(path, linkname, PATH_MAX); + if (r == -1) { + ALOGE("Unable to read link for %s: %s\n", path, strerror(errno)); + return; + } + linkname[r] = '\0'; + + if (mount_points.find(linkname) == mount_points.end()) { + // First time this mount point was found: add it + sprintf(path, "/proc/%d/mountinfo", pid); + if (add_zip_entry(ZIP_ROOT_DIR + path, path)) { + mount_points.insert(linkname); + } else { + ALOGE("Unable to add mountinfo %s to zip file\n", path); + } + } +} + +void add_mountinfo() { + if (!zip_writer) return; + const char *title = "MOUNT INFO"; + mount_points.clear(); + DurationReporter duration_reporter(title); + for_each_pid(do_mountinfo, NULL); + printf("%s: %d entries added to zip file\n", title, mount_points.size()); +} + static void dump_dev_files(const char *title, const char *driverpath, const char *filename) { DIR *d; @@ -811,7 +850,7 @@ int main(int argc, char *argv[]) { /* pointer to the actual path, be it zip or text */ std::string path; - /* pointers to the zipped file file */ + /* pointer to the zipped file */ std::unique_ptr zip_file(NULL, fclose); /* redirect output if needed */ @@ -904,9 +943,10 @@ int main(int argc, char *argv[]) { /* collect stack traces from Dalvik and native processes (needs root) */ dump_traces_path = dump_traces(); - /* Get the tombstone fds and recovery files here while we are running as root. */ + /* Get the tombstone fds, recovery files, and mount info here while we are running as root. */ get_tombstone_fds(tombstone_data); add_dir(RECOVERY_DIR, true); + add_mountinfo(); /* ensure we will keep capabilities when we drop root */ if (prctl(PR_SET_KEEPCAPS, 1) < 0) { diff --git a/cmds/dumpstate/utils.cpp b/cmds/dumpstate/utils.cpp index 78bab819b3..e49d766f1e 100644 --- a/cmds/dumpstate/utils.cpp +++ b/cmds/dumpstate/utils.cpp @@ -114,7 +114,7 @@ static void __for_each_pid(void (*helper)(int, const char *, void *), const char return; } - printf("\n------ %s ------\n", header); + if (header) printf("\n------ %s ------\n", header); while ((de = readdir(d))) { int pid; int fd; -- 2.11.0