summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Leme <felipeal@google.com>2015-12-14 23:25:48 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-12-14 23:25:48 +0000
commit1f62517b3654a3c0e95ea4d5b3664fac8115acdf (patch)
tree00fe08bdaecbc99ede947ed0c6935343eee4f727
parent8b9c0e1af14bf07b216edd1b995048790ddabaca (diff)
parent515eb0db0a03de0a721ef034b3f3898e1d7e42e7 (diff)
downloadnative-1f62517b3654a3c0e95ea4d5b3664fac8115acdf.tar.gz
Merge "Migrated dumpstate to C++."
-rw-r--r--cmds/dumpstate/Android.mk4
-rw-r--r--cmds/dumpstate/dumpstate.cpp (renamed from cmds/dumpstate/dumpstate.c)2
-rw-r--r--cmds/dumpstate/dumpstate.h8
-rw-r--r--cmds/dumpstate/libdumpstate_default.cpp (renamed from cmds/dumpstate/libdumpstate_default.c)1
-rw-r--r--cmds/dumpstate/utils.cpp (renamed from cmds/dumpstate/utils.c)19
5 files changed, 22 insertions, 12 deletions
diff --git a/cmds/dumpstate/Android.mk b/cmds/dumpstate/Android.mk
index 8c7c4a840e..6442701c29 100644
--- a/cmds/dumpstate/Android.mk
+++ b/cmds/dumpstate/Android.mk
@@ -1,6 +1,6 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
-LOCAL_SRC_FILES := libdumpstate_default.c
+LOCAL_SRC_FILES := libdumpstate_default.cpp
LOCAL_MODULE := libdumpstate.default
include $(BUILD_STATIC_LIBRARY)
@@ -10,7 +10,7 @@ ifdef BOARD_WLAN_DEVICE
LOCAL_CFLAGS := -DFWDUMP_$(BOARD_WLAN_DEVICE)
endif
-LOCAL_SRC_FILES := dumpstate.c utils.c
+LOCAL_SRC_FILES := dumpstate.cpp utils.cpp
LOCAL_MODULE := dumpstate
diff --git a/cmds/dumpstate/dumpstate.c b/cmds/dumpstate/dumpstate.cpp
index 9d07b09542..12ad220a7c 100644
--- a/cmds/dumpstate/dumpstate.c
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -229,7 +229,7 @@ static unsigned long property_get_size(const char *key) {
}
/* timeout in ms */
-static unsigned long logcat_timeout(char *name) {
+static unsigned long logcat_timeout(const char *name) {
static const char global_tuneable[] = "persist.logd.size"; // Settings App
static const char global_default[] = "ro.logd.size"; // BoardConfig.mk
char key[PROP_NAME_MAX];
diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h
index 228f09cf15..3b6abc1d15 100644
--- a/cmds/dumpstate/dumpstate.h
+++ b/cmds/dumpstate/dumpstate.h
@@ -24,6 +24,10 @@
#define SU_PATH "/system/xbin/su"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
typedef void (for_each_pid_func)(int, const char *);
typedef void (for_each_tid_func)(int, int, const char *);
@@ -87,4 +91,8 @@ void dumpstate_board();
/* dump eMMC Extended CSD data */
void dump_emmc_ecsd(const char *ext_csd_path);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* _DUMPSTATE_H_ */
diff --git a/cmds/dumpstate/libdumpstate_default.c b/cmds/dumpstate/libdumpstate_default.cpp
index fd840dfd4b..415ecdc96c 100644
--- a/cmds/dumpstate/libdumpstate_default.c
+++ b/cmds/dumpstate/libdumpstate_default.cpp
@@ -19,4 +19,3 @@
void dumpstate_board(void)
{
}
-
diff --git a/cmds/dumpstate/utils.c b/cmds/dumpstate/utils.cpp
index 47acb6385c..c3e026230e 100644
--- a/cmds/dumpstate/utils.c
+++ b/cmds/dumpstate/utils.cpp
@@ -117,19 +117,19 @@ static void __for_each_pid(void (*helper)(int, const char *, void *), const char
}
static void for_each_pid_helper(int pid, const char *cmdline, void *arg) {
- for_each_pid_func *func = arg;
+ for_each_pid_func *func = (for_each_pid_func*) arg;
func(pid, cmdline);
}
void for_each_pid(for_each_pid_func func, const char *header) {
- __for_each_pid(for_each_pid_helper, header, func);
+ __for_each_pid(for_each_pid_helper, header, (void *) func);
}
static void for_each_tid_helper(int pid, const char *cmdline, void *arg) {
DIR *d;
struct dirent *de;
char taskpath[255];
- for_each_tid_func *func = arg;
+ for_each_tid_func *func = (for_each_tid_func*) arg;
sprintf(taskpath, "/proc/%d/task", pid);
@@ -174,7 +174,7 @@ static void for_each_tid_helper(int pid, const char *cmdline, void *arg) {
}
void for_each_tid(for_each_tid_func func, const char *header) {
- __for_each_pid(for_each_tid_helper, header, func);
+ __for_each_pid(for_each_tid_helper, header, (void *) func);
}
void show_wchan(int pid, int tid, const char *name) {
@@ -322,7 +322,7 @@ int dump_files(const char *title, const char *dir,
DIR *dirp;
struct dirent *d;
char *newpath = NULL;
- char *slash = "/";
+ const char *slash = "/";
int fd, retval = 0;
if (title) {
@@ -640,6 +640,10 @@ const char *dump_traces() {
return NULL;
}
+ /* Variables below must be initialized before 'goto' statements */
+ int dalvik_found = 0;
+ int ifd, wfd = -1;
+
/* walk /proc and kill -QUIT all Dalvik processes */
DIR *proc = opendir("/proc");
if (proc == NULL) {
@@ -648,20 +652,19 @@ const char *dump_traces() {
}
/* use inotify to find when processes are done dumping */
- int ifd = inotify_init();
+ ifd = inotify_init();
if (ifd < 0) {
fprintf(stderr, "inotify_init: %s\n", strerror(errno));
goto error_close_fd;
}
- int wfd = inotify_add_watch(ifd, traces_path, IN_CLOSE_WRITE);
+ wfd = inotify_add_watch(ifd, traces_path, IN_CLOSE_WRITE);
if (wfd < 0) {
fprintf(stderr, "inotify_add_watch(%s): %s\n", traces_path, strerror(errno));
goto error_close_ifd;
}
struct dirent *d;
- int dalvik_found = 0;
while ((d = readdir(proc))) {
int pid = atoi(d->d_name);
if (pid <= 0) continue;