Created functions to run dumpsys.
Such functions not only are less error prone (for example, uses just one
variable for both timeouts) but also will make it easier to pass
additional commands to dumpsys.
BUG: 28980245
Change-Id: Ib0a14eaafd83e71a50f5548f86144ac6403fa84b
diff --git a/cmds/dumpstate/utils.cpp b/cmds/dumpstate/utils.cpp
index c546f4b..3c9693f 100644
--- a/cmds/dumpstate/utils.cpp
+++ b/cmds/dumpstate/utils.cpp
@@ -644,7 +644,7 @@
DurationReporter duration_reporter(title);
fflush(stdout);
- const char *args[1024] = {command};
+ const char *args[ARG_MAX] = {command};
size_t arg;
va_list ap;
va_start(ap, command);
@@ -682,7 +682,7 @@
DurationReporter duration_reporter(title);
fflush(stdout);
- const char *args[1024] = {command};
+ const char *args[ARG_MAX] = {command};
size_t arg;
va_list ap;
va_start(ap, command);
@@ -871,14 +871,18 @@
MYLOGE("send_broadcast: too many arguments (%d)\n", (int) args.size());
return;
}
- const char *am_args[1024] = { "/system/bin/am", "broadcast", "--user", "0", "-a",
- action.c_str() };
+ const char *am_args[ARG_MAX] = { "/system/bin/am", "broadcast", "--user", "0", "-a",
+ action.c_str() };
size_t am_index = 5; // Starts at the index of last initial value above.
for (const std::string& arg : args) {
+ if (am_index > ARG_MAX - 2) {
+ MYLOGE("send_broadcast: too many arguments (%d)\n", (int) args.size());
+ return;
+ }
am_args[++am_index] = arg.c_str();
}
- // Always terminate with NULL.
- am_args[am_index + 1] = NULL;
+ // Always terminate with nullptr.
+ am_args[am_index + 1] = nullptr;
std::string args_string;
format_args(am_index + 1, am_args, &args_string);
MYLOGD("send_broadcast command: %s\n", args_string.c_str());