Refactored use of ON_DRY_RUN macros.

BUG: 26379932
Change-Id: Ie032d468540da3c4ac0df1ea2d88a0aac4c722a7
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index 52c6e56..d005d59 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -296,7 +296,10 @@
     printf("------ %s (%s) ------\n", title.c_str(), args_string.c_str());
     fflush(stdout);
 
-    ON_DRY_RUN({ update_progress(timeout_seconds); return; });
+    if (is_dry_run()) {
+        update_progress(timeout_seconds);
+        return;
+    }
 
     run_command_always(title.c_str(), root_mode, NORMAL_STDOUT, timeout_seconds, dumpsys_args);
 }
diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h
index 389444e..0b87368 100644
--- a/cmds/dumpstate/dumpstate.h
+++ b/cmds/dumpstate/dumpstate.h
@@ -17,14 +17,6 @@
 #ifndef FRAMEWORK_NATIVE_CMD_DUMPSTATE_H_
 #define FRAMEWORK_NATIVE_CMD_DUMPSTATE_H_
 
-#ifndef ON_DRY_RUN_RETURN
-#define ON_DRY_RUN_RETURN(X) if (is_dry_run()) return X
-#endif
-
-#ifndef ON_DRY_RUN
-#define ON_DRY_RUN(code) if (is_dry_run()) code
-#endif
-
 #ifndef MYLOGD
 #define MYLOGD(...) fprintf(stderr, __VA_ARGS__); ALOGD(__VA_ARGS__);
 #endif
diff --git a/cmds/dumpstate/utils.cpp b/cmds/dumpstate/utils.cpp
index 3c9693f..4076f6a 100644
--- a/cmds/dumpstate/utils.cpp
+++ b/cmds/dumpstate/utils.cpp
@@ -99,7 +99,8 @@
 }
 
 void for_each_userid(void (*func)(int), const char *header) {
-    ON_DRY_RUN_RETURN();
+    if (is_dry_run()) return;
+
     DIR *d;
     struct dirent *de;
 
@@ -181,7 +182,8 @@
 }
 
 void for_each_pid(for_each_pid_func func, const char *header) {
-    ON_DRY_RUN_RETURN();
+    if (is_dry_run()) return;
+
     __for_each_pid(for_each_pid_helper, header, (void *) func);
 }
 
@@ -234,12 +236,14 @@
 }
 
 void for_each_tid(for_each_tid_func func, const char *header) {
-    ON_DRY_RUN_RETURN();
+    if (is_dry_run()) return;
+
     __for_each_pid(for_each_tid_helper, header, (void *) func);
 }
 
 void show_wchan(int pid, int tid, const char *name) {
-    ON_DRY_RUN_RETURN();
+    if (is_dry_run()) return;
+
     char path[255];
     char buffer[255];
     int fd, ret, save_errno;
@@ -305,7 +309,8 @@
 }
 
 void show_showtime(int pid, const char *name) {
-    ON_DRY_RUN_RETURN();
+    if (is_dry_run()) return;
+
     char path[255];
     char buffer[1023];
     int fd, ret, save_errno;
@@ -372,7 +377,8 @@
     DurationReporter duration_reporter(title);
     printf("------ %s ------\n", title);
 
-    ON_DRY_RUN_RETURN();
+    if (is_dry_run()) return;
+
     /* Get size of kernel buffer */
     int size = klogctl(KLOG_SIZE_BUFFER, NULL, 0);
     if (size <= 0) {
@@ -423,7 +429,11 @@
         }
         printf(") ------\n");
     }
-    ON_DRY_RUN({ update_progress(WEIGHT_FILE); close(fd); return 0; });
+    if (is_dry_run()) {
+        update_progress(WEIGHT_FILE);
+        close(fd);
+        return 0;
+    }
 
     bool newline = false;
     fd_set read_set;
@@ -522,7 +532,7 @@
     if (title) {
         printf("------ %s (%s) ------\n", title, dir);
     }
-    ON_DRY_RUN_RETURN(0);
+    if (is_dry_run()) return 0;
 
     if (dir[strlen(dir) - 1] == '/') {
         ++slash;
@@ -579,7 +589,8 @@
  * stuck.
  */
 int dump_file_from_fd(const char *title, const char *path, int fd) {
-    ON_DRY_RUN_RETURN(0);
+    if (is_dry_run()) return 0;
+
     int flags = fcntl(fd, F_GETFL);
     if (flags == -1) {
         printf("*** %s: failed to get flags on fd %d: %s\n", path, fd, strerror(errno));
@@ -671,9 +682,12 @@
         return -1;
     }
 
-    ON_DRY_RUN({ update_progress(timeout_seconds); va_end(ap); return 0; });
-
-    int status = run_command_always(title, DONT_DROP_ROOT, NORMAL_STDOUT, timeout_seconds, args);
+    int status = 0;
+    if (is_dry_run()) {
+        update_progress(timeout_seconds);
+    } else {
+        status = run_command_always(title, DONT_DROP_ROOT, NORMAL_STDOUT, timeout_seconds, args);
+    }
     va_end(ap);
     return status;
 }
@@ -709,9 +723,12 @@
         return -1;
     }
 
-    ON_DRY_RUN({ update_progress(timeout_seconds); va_end(ap); return 0; });
-
-    int status = run_command_always(title, DROP_ROOT, NORMAL_STDOUT, timeout_seconds, args);
+    int status = 0;
+    if (is_dry_run()) {
+        update_progress(timeout_seconds);
+    } else {
+        status = run_command_always(title, DROP_ROOT, NORMAL_STDOUT, timeout_seconds, args);
+    }
     va_end(ap);
     return status;
 }
@@ -910,7 +927,7 @@
     const char* title = "SYSTEM PROPERTIES";
     DurationReporter duration_reporter(title);
     printf("------ %s ------\n", title);
-    ON_DRY_RUN_RETURN();
+    if (is_dry_run()) return;
     size_t i;
     num_props = 0;
     property_list(print_prop, NULL);
@@ -1016,7 +1033,8 @@
 /* dump Dalvik and native stack traces, return the trace file location (NULL if none) */
 const char *dump_traces() {
     DurationReporter duration_reporter("DUMP TRACES", NULL);
-    ON_DRY_RUN_RETURN(NULL);
+    if (is_dry_run()) return NULL;
+
     const char* result = NULL;
 
     char traces_path[PROPERTY_VALUE_MAX] = "";
@@ -1171,7 +1189,7 @@
 
 void dump_route_tables() {
     DurationReporter duration_reporter("DUMP ROUTE TABLES");
-    ON_DRY_RUN_RETURN();
+    if (is_dry_run()) return;
     const char* const RT_TABLES_PATH = "/data/misc/net/rt_tables";
     dump_file("RT_TABLES", RT_TABLES_PATH);
     FILE* fp = fopen(RT_TABLES_PATH, "re");