summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWei Liu <luciferleo@google.com>2016-08-26 14:51:42 -0700
committerFelipe Leme <felipeal@google.com>2016-10-03 17:43:12 -0700
commit2cc37eaaa7f76b690987a09b0674161583403c84 (patch)
treef56d041e79ff9adc34de006391e2c2f336e7af4b
parenta4bb5c7173ceaf58893924e84187bb97c88d10a1 (diff)
downloadnative-2cc37eaaa7f76b690987a09b0674161583403c84.tar.gz
Dumpstate should hold a wakelock to save bug report time. DO NOT MERGE.
BUG: 31828706 BUG: 30832947 Change-Id: I0a4b1fcce91caa96ccbc4e890d9968e3033487de (cherry picked from commit f87959e00732d7d737527f1248a71adea99ae29d)
-rw-r--r--cmds/dumpstate/Android.mk2
-rw-r--r--cmds/dumpstate/dumpstate.cpp41
-rw-r--r--cmds/dumpstate/utils.cpp8
3 files changed, 39 insertions, 12 deletions
diff --git a/cmds/dumpstate/Android.mk b/cmds/dumpstate/Android.mk
index 791a7c4a61..7a9f9adcb3 100644
--- a/cmds/dumpstate/Android.mk
+++ b/cmds/dumpstate/Android.mk
@@ -14,7 +14,7 @@ LOCAL_SRC_FILES := dumpstate.cpp utils.cpp
LOCAL_MODULE := dumpstate
-LOCAL_SHARED_LIBRARIES := libcutils liblog libselinux libbase
+LOCAL_SHARED_LIBRARIES := libcutils liblog libselinux libbase libhardware_legacy
# ZipArchive support, the order matters here to get all symbols.
LOCAL_STATIC_LIBRARIES := libziparchive libz libmincrypt
LOCAL_HAL_STATIC_LIBRARIES := libdumpstate
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index 538f0b4330..0ff693375c 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -22,6 +22,7 @@
#include <memory>
#include <regex>
#include <set>
+#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -36,6 +37,7 @@
#include <android-base/stringprintf.h>
#include <cutils/properties.h>
+#include <hardware_legacy/power.h>
#include "private/android_filesystem_config.h"
@@ -81,6 +83,7 @@ static std::string suffix;
#define TOMBSTONE_MAX_LEN (sizeof(TOMBSTONE_FILE_PREFIX) + 4)
#define NUM_TOMBSTONES 10
#define WLUTIL "/vendor/xbin/wlutil"
+#define WAKE_LOCK_NAME "dumpstate_wakelock"
typedef struct {
char name[TOMBSTONE_MAX_LEN];
@@ -1016,11 +1019,31 @@ static void usage() {
VERSION_DEFAULT.c_str());
}
-static void sigpipe_handler(int n) {
- // don't complain to stderr or stdout
+static void wake_lock_releaser() {
+ if (release_wake_lock(WAKE_LOCK_NAME) < 0) {
+ MYLOGE("Failed to release wake lock: %s \n", strerror(errno));
+ } else {
+ MYLOGD("Wake lock released.\n");
+ }
+}
+
+static void sig_handler(int signo) {
+ wake_lock_releaser();
_exit(EXIT_FAILURE);
}
+static void register_sig_handler() {
+ struct sigaction sa;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = sig_handler;
+ sigaction(SIGPIPE, &sa, NULL); // broken pipe
+ sigaction(SIGSEGV, &sa, NULL); // segment fault
+ sigaction(SIGINT, &sa, NULL); // ctrl-c
+ sigaction(SIGTERM, &sa, NULL); // killed
+ sigaction(SIGQUIT, &sa, NULL); // quit
+}
+
/* adds the temporary report to the existing .zip file, closes the .zip file, and removes the
temporary file.
*/
@@ -1088,7 +1111,6 @@ static std::string SHA256_file_hash(std::string filepath) {
}
int main(int argc, char *argv[]) {
- struct sigaction sigact;
int do_add_date = 0;
int do_zip_file = 0;
int do_vibrate = 1;
@@ -1105,6 +1127,14 @@ int main(int argc, char *argv[]) {
MYLOGI("begin\n");
+ if (acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_NAME) < 0) {
+ MYLOGE("Failed to acquire wake lock: %s \n", strerror(errno));
+ } else {
+ MYLOGD("Wake lock acquired.\n");
+ atexit(wake_lock_releaser);
+ register_sig_handler();
+ }
+
/* gets the sequential id */
char last_id[PROPERTY_VALUE_MAX];
property_get("dumpstate.last_id", last_id, "0");
@@ -1113,11 +1143,6 @@ int main(int argc, char *argv[]) {
property_set("dumpstate.last_id", last_id);
MYLOGI("dumpstate id: %lu\n", id);
- /* clear SIGPIPE handler */
- memset(&sigact, 0, sizeof(sigact));
- sigact.sa_handler = sigpipe_handler;
- sigaction(SIGPIPE, &sigact, NULL);
-
/* set as high priority, and protect from OOM killer */
setpriority(PRIO_PROCESS, 0, -20);
diff --git a/cmds/dumpstate/utils.cpp b/cmds/dumpstate/utils.cpp
index fd6413d562..1035cde9d4 100644
--- a/cmds/dumpstate/utils.cpp
+++ b/cmds/dumpstate/utils.cpp
@@ -828,7 +828,7 @@ bool drop_root_user() {
}
gid_t groups[] = { AID_LOG, AID_SDCARD_R, AID_SDCARD_RW,
- AID_MOUNT, AID_INET, AID_NET_BW_STATS, AID_READPROC };
+ AID_MOUNT, AID_INET, AID_NET_BW_STATS, AID_READPROC, AID_WAKELOCK };
if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) != 0) {
MYLOGE("Unable to setgroups, aborting: %s\n", strerror(errno));
return false;
@@ -849,8 +849,10 @@ bool drop_root_user() {
capheader.version = _LINUX_CAPABILITY_VERSION_3;
capheader.pid = 0;
- capdata[CAP_TO_INDEX(CAP_SYSLOG)].permitted = CAP_TO_MASK(CAP_SYSLOG);
- capdata[CAP_TO_INDEX(CAP_SYSLOG)].effective = CAP_TO_MASK(CAP_SYSLOG);
+ capdata[CAP_TO_INDEX(CAP_SYSLOG)].permitted =
+ (CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_BLOCK_SUSPEND));
+ capdata[CAP_TO_INDEX(CAP_SYSLOG)].effective =
+ (CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_BLOCK_SUSPEND));
capdata[0].inheritable = 0;
capdata[1].inheritable = 0;