summaryrefslogtreecommitdiff
path: root/cmds/dumpstate/utils.cpp
diff options
context:
space:
mode:
author Felipe Leme <felipeal@google.com> 2016-03-21 21:56:11 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2016-03-21 21:56:12 +0000
commit7f72f4e577c8f9f88096353a60c3a2b43006f7d9 (patch)
treec8682e6ed4d384f2e4cb342def91e4fcd5476db2 /cmds/dumpstate/utils.cpp
parentb49576d5241859a3cf03c9f34b8030ad25d3806b (diff)
parent71a74ac75c8687195d27642fa0db31a796102c59 (diff)
Merge "Capture systrace buffers." into nyc-dev
Diffstat (limited to 'cmds/dumpstate/utils.cpp')
-rw-r--r--cmds/dumpstate/utils.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/cmds/dumpstate/utils.cpp b/cmds/dumpstate/utils.cpp
index d21ef7bd03..7ed51ab035 100644
--- a/cmds/dumpstate/utils.cpp
+++ b/cmds/dumpstate/utils.cpp
@@ -474,6 +474,27 @@ int dump_file(const char *title, const char *path) {
return _dump_file_from_fd(title, path, fd);
}
+int read_file_as_long(const char *path, long int *output) {
+ int fd = TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_NONBLOCK | O_CLOEXEC));
+ if (fd < 0) {
+ int err = errno;
+ MYLOGE("Error opening file descriptor for %s: %s\n", path, strerror(err));
+ return -1;
+ }
+ char buffer[50];
+ ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fd, buffer, sizeof(buffer)));
+ if (bytes_read == -1) {
+ MYLOGE("Error reading file %s: %s\n", path, strerror(errno));
+ return -2;
+ }
+ if (bytes_read == 0) {
+ MYLOGE("File %s is empty\n", path);
+ return -3;
+ }
+ *output = atoi(buffer);
+ return 0;
+}
+
/* calls skip to gate calling dump_from_fd recursively
* in the specified directory. dump_from_fd defaults to
* dump_file_from_fd above when set to NULL. skip defaults
@@ -676,7 +697,6 @@ int run_command_always(const char *title, int timeout_seconds, const char *args[
execvp(command, (char**) args);
// execvp's result will be handled after waitpid_with_timeout() below...
- _exit(-1); // ...but it doesn't hurt to force exit, just in case
}
/* handle parent case */