Skip to content

Commit cb115fc

Browse files
committed
dumpstate: use /system/xbin/su directly
This avoids accidentally picking up very common "su" alternatives that developers use. It also avoids having to search the PATH for su. Change-Id: Ib9a3eeca7f4d892f2c9ea9ca1132304ef8e8484b
1 parent 5265466 commit cb115fc

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

cmds/dumpstate/dumpstate.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ static void dumpstate() {
8888

8989
if (screenshot_path[0]) {
9090
ALOGI("taking screenshot\n");
91-
run_command(NULL, 5, "su", "root", "screenshot", screenshot_path, NULL);
91+
run_command(NULL, 5, SU_PATH, "root", "screenshot", screenshot_path, NULL);
9292
ALOGI("wrote screenshot: %s\n", screenshot_path);
9393
}
9494

95-
run_command("SYSTEM SETTINGS", 20, "su", "root", "sqlite3",
95+
run_command("SYSTEM SETTINGS", 20, SU_PATH, "root", "sqlite3",
9696
"/data/data/com.android.providers.settings/databases/settings.db",
9797
"pragma user_version; select * from system; select * from secure;", NULL);
9898
run_command("SYSTEM LOG", 20, "logcat", "-v", "threadtime", "-d", "*:v", NULL);
@@ -118,7 +118,7 @@ static void dumpstate() {
118118
run_command("EVENT LOG", 20, "logcat", "-b", "events", "-v", "threadtime", "-d", "*:v", NULL);
119119
run_command("RADIO LOG", 20, "logcat", "-b", "radio", "-v", "threadtime", "-d", "*:v", NULL);
120120

121-
run_command("NETWORK INTERFACES", 10, "su", "root", "netcfg", NULL);
121+
run_command("NETWORK INTERFACES", 10, SU_PATH, "root", "netcfg", NULL);
122122
dump_file("NETWORK DEV INFO", "/proc/net/dev");
123123
dump_file("QTAGUID NETWORK INTERFACES INFO", "/proc/net/xt_qtaguid/iface_stat_all");
124124
dump_file("QTAGUID CTRL INFO", "/proc/net/xt_qtaguid/ctrl");
@@ -133,28 +133,28 @@ static void dumpstate() {
133133
run_command("ROUTE TABLE 61", 10, "ip", "route", "show", "table", "61", NULL);
134134
run_command("ROUTE TABLE 61 v6", 10, "ip", "-6", "route", "show", "table", "61", NULL);
135135
dump_file("ARP CACHE", "/proc/net/arp");
136-
run_command("IPTABLES", 10, "su", "root", "iptables", "-L", "-nvx", NULL);
137-
run_command("IP6TABLES", 10, "su", "root", "ip6tables", "-L", "-nvx", NULL);
138-
run_command("IPTABLE NAT", 10, "su", "root", "iptables", "-t", "nat", "-L", "-n", NULL);
139-
run_command("IPT6ABLE NAT", 10, "su", "root", "ip6tables", "-t", "nat", "-L", "-n", NULL);
136+
run_command("IPTABLES", 10, SU_PATH, "root", "iptables", "-L", "-nvx", NULL);
137+
run_command("IP6TABLES", 10, SU_PATH, "root", "ip6tables", "-L", "-nvx", NULL);
138+
run_command("IPTABLE NAT", 10, SU_PATH, "root", "iptables", "-t", "nat", "-L", "-n", NULL);
139+
run_command("IPT6ABLE NAT", 10, SU_PATH, "root", "ip6tables", "-t", "nat", "-L", "-n", NULL);
140140

141141
run_command("WIFI NETWORKS", 20,
142-
"su", "root", "wpa_cli", "list_networks", NULL);
142+
SU_PATH, "root", "wpa_cli", "list_networks", NULL);
143143

144144
property_get("dhcp.wlan0.gateway", network, "");
145145
if (network[0])
146-
run_command("PING GATEWAY", 10, "su", "root", "ping", "-c", "3", "-i", ".5", network, NULL);
146+
run_command("PING GATEWAY", 10, SU_PATH, "root", "ping", "-c", "3", "-i", ".5", network, NULL);
147147
property_get("dhcp.wlan0.dns1", network, "");
148148
if (network[0])
149-
run_command("PING DNS1", 10, "su", "root", "ping", "-c", "3", "-i", ".5", network, NULL);
149+
run_command("PING DNS1", 10, SU_PATH, "root", "ping", "-c", "3", "-i", ".5", network, NULL);
150150
property_get("dhcp.wlan0.dns2", network, "");
151151
if (network[0])
152-
run_command("PING DNS2", 10, "su", "root", "ping", "-c", "3", "-i", ".5", network, NULL);
152+
run_command("PING DNS2", 10, SU_PATH, "root", "ping", "-c", "3", "-i", ".5", network, NULL);
153153
#ifdef FWDUMP_bcm4329
154154
run_command("DUMP WIFI STATUS", 20,
155-
"su", "root", "dhdutil", "-i", "wlan0", "dump", NULL);
155+
SU_PATH, "root", "dhdutil", "-i", "wlan0", "dump", NULL);
156156
run_command("DUMP WIFI INTERNAL COUNTERS", 20,
157-
"su", "root", "wlutil", "counters", NULL);
157+
SU_PATH, "root", "wlutil", "counters", NULL);
158158
#endif
159159

160160
char ril_dumpstate_timeout[PROPERTY_VALUE_MAX] = {0};
@@ -168,7 +168,7 @@ static void dumpstate() {
168168
"vril-dump", NULL);
169169
} else {
170170
run_command("DUMP VENDOR RIL LOGS", atoi(ril_dumpstate_timeout),
171-
"su", "root", "vril-dump", NULL);
171+
SU_PATH, "root", "vril-dump", NULL);
172172
}
173173
}
174174

@@ -192,7 +192,7 @@ static void dumpstate() {
192192
dump_file("BINDER STATS", "/sys/kernel/debug/binder/stats");
193193
dump_file("BINDER STATE", "/sys/kernel/debug/binder/state");
194194

195-
run_command("FILESYSTEMS & FREE SPACE", 10, "su", "root", "df", NULL);
195+
run_command("FILESYSTEMS & FREE SPACE", 10, SU_PATH, "root", "df", NULL);
196196

197197
dump_file("PACKAGE SETTINGS", "/data/system/packages.xml");
198198
dump_file("PACKAGE UID ERRORS", "/data/system/uiderrors.txt");
@@ -218,7 +218,7 @@ static void dumpstate() {
218218
dump_file(NULL, "/sys/class/leds/lcd-backlight/registers");
219219
printf("\n");
220220

221-
run_command("LIST OF OPEN FILES", 10, "su", "root", "lsof", NULL);
221+
run_command("LIST OF OPEN FILES", 10, SU_PATH, "root", "lsof", NULL);
222222

223223
for_each_pid(do_showmap, "SMAPS OF ALL PROCESSES");
224224

cmds/dumpstate/dumpstate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <unistd.h>
2222
#include <stdio.h>
2323

24+
#define SU_PATH "/system/xbin/su"
25+
2426
/* prints the contents of a file */
2527
int dump_file(const char *title, const char* path);
2628

cmds/dumpstate/utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void do_showmap(int pid, const char *name) {
127127

128128
sprintf(title, "SHOW MAP %d (%s)", pid, name);
129129
sprintf(arg, "%d", pid);
130-
run_command(title, 10, "su", "root", "showmap", arg, NULL);
130+
run_command(title, 10, SU_PATH, "root", "showmap", arg, NULL);
131131
}
132132

133133
/* prints the contents of a file */

0 commit comments

Comments
 (0)