Deprecate run_command() and dump_file().
This change will break dumpstate_board() implementations that were not
refactored to use the equivalent functions in the Dumpstate
class. For example:
void dumpstate_board() {
dump_file("INTERRUPTS", "/proc/interrupts");
run_command("SUBSYSTEM TOMBSTONES", 5, SU_PATH, "root",
"ls", "-l", "/data/tombstones/ramdump", NULL);
}
Should be refactored to:
void dumpstate_board(){
Dumpstate& ds = Dumpstate::GetInstance();
ds.DumpFile("INTERRUPTS", "/proc/interrupts");
ds.RunCommand("SUBSYSTEM TOMBSTONES",
{"ls", "-l", "/data/tombstones/ramdump"},
CommandOptions::AS_ROOT_5);
}
BUG: 26379932
Test: manual / refactored code
Change-Id: Ia74515cc57abc18bc6966a5aed71dd679422fd0e
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index d1a96c1..f3e68b3 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -367,7 +367,7 @@
if (RunCommand("SYSTRACE", {"/system/bin/atrace", "--async_dump", "-o", systrace_path},
CommandOptions::WithTimeout(120).Build())) {
MYLOGE("systrace timed out, its zip entry will be incomplete\n");
- // TODO: run_command tries to kill the process, but atrace doesn't die
+ // TODO: RunCommand tries to kill the process, but atrace doesn't die
// peacefully; ideally, we should call strace to stop itself, but there is no such option
// yet (just a --async_stop, which stops and dump
// if (RunCommand("SYSTRACE", {"/system/bin/atrace", "--kill"})) {
@@ -1621,7 +1621,7 @@
dump_iptables();
// Run ss as root so we can see socket marks.
- run_command("DETAILED SOCKET STATE", 10, "ss", "-eionptu", NULL);
+ RunCommand("DETAILED SOCKET STATE", {"ss", "-eionptu"}, CommandOptions::WithTimeout(10).Build());
if (!drop_root_user()) {
return -1;
diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h
index 9292cb4..70af270 100644
--- a/cmds/dumpstate/dumpstate.h
+++ b/cmds/dumpstate/dumpstate.h
@@ -300,11 +300,6 @@
/* adds all files from a directory to the zipped bugreport file */
void add_dir(const std::string& dir, bool recursive);
-/* prints the contents of a file
- * DEPRECATED: will be removed once device-specific implementations use
- * dumpFile */
-int dump_file(const char *title, const char *path);
-
/* saves the the contents of a file as a long */
int read_file_as_long(const char *path, long int *output);
@@ -322,11 +317,6 @@
int dump_files(const std::string& title, const char* dir, bool (*skip)(const char* path),
int (*dump_from_fd)(const char* title, const char* path, int fd));
-/* forks a command and waits for it to finish -- terminate args with NULL
- * DEPRECATED: will be removed once device-specific implementations use
- * RunCommand */
-int run_command(const char *title, int timeout_seconds, const char *command, ...);
-
/* switch to non-root user and group */
bool drop_root_user();
diff --git a/cmds/dumpstate/utils.cpp b/cmds/dumpstate/utils.cpp
index 476392e..e29d90d 100644
--- a/cmds/dumpstate/utils.cpp
+++ b/cmds/dumpstate/utils.cpp
@@ -576,11 +576,6 @@
return 0;
}
-// DEPRECATED: will be removed once device-specific implementations use dumpFile
-int dump_file(const char *title, const char *path) {
- return ds.DumpFile(title, path);
-}
-
int Dumpstate::DumpFile(const std::string& title, const std::string& path) {
DurationReporter durationReporter(title);
int fd = TEMP_FAILURE_RETRY(open(path.c_str(), O_RDONLY | O_NONBLOCK | O_CLOEXEC));
@@ -748,24 +743,6 @@
return true;
}
-// DEPRECATED: will be removed once device-specific implementations use RunCommand
-int run_command(const char* title, int timeout_seconds, const char* command, ...) {
- std::vector<std::string> fullCommand = {command};
- size_t arg;
- va_list ap;
- va_start(ap, command);
- for (arg = 0; arg < MAX_ARGS_ARRAY_SIZE; ++arg) {
- const char* ptr = va_arg(ap, const char*);
- if (ptr == nullptr) {
- break;
- }
- fullCommand.push_back(ptr);
- }
- va_end(ap);
-
- return ds.RunCommand(title, fullCommand, CommandOptions::WithTimeout(timeout_seconds).Build());
-}
-
int Dumpstate::RunCommand(const std::string& title, const std::vector<std::string>& fullCommand,
const CommandOptions& options) {
if (fullCommand.empty()) {
@@ -1271,7 +1248,7 @@
DurationReporter duration_reporter("DUMP ROUTE TABLES");
if (is_dry_run()) return;
const char* const RT_TABLES_PATH = "/data/misc/net/rt_tables";
- dump_file("RT_TABLES", RT_TABLES_PATH);
+ ds.DumpFile("RT_TABLES", RT_TABLES_PATH);
FILE* fp = fopen(RT_TABLES_PATH, "re");
if (!fp) {
printf("*** %s: %s\n", RT_TABLES_PATH, strerror(errno));