diff options
author | Mike Kasick <mike@kasick.org> | 2012-10-31 18:53:58 -0400 |
---|---|---|
committer | Mike Kasick <mike@kasick.org> | 2012-12-12 21:04:17 -0500 |
commit | 18aefe944472f2def2ace61a46f5002773413b43 (patch) | |
tree | c60dd5a3b8401b42f4fae7ea783283adff1b7fec /cmds | |
parent | 6efc967ff5e0bb33a9116aee9846b041b80d0594 (diff) | |
download | frameworks_native-18aefe944472f2def2ace61a46f5002773413b43.zip frameworks_native-18aefe944472f2def2ace61a46f5002773413b43.tar.gz frameworks_native-18aefe944472f2def2ace61a46f5002773413b43.tar.bz2 |
dumpstate: Squash fixes from CM 10.0
commit ba3723de8d13126027706bbbe6f9657da231b9bd
Author: Mike Kasick <mike@kasick.org>
Date: Wed Oct 31 20:31:05 2012 -0400
dumpstate: Fix calls to su to specify a shell command
Superuser's su requires that shell commands be specified with the "-c"
option. Fix calls to su to explicitly specify this option.
commit 78cd73fce82fd0b5ee98a6136c847932ba8c636b
Author: Mike Kasick <mike@kasick.org>
Date: Wed Oct 31 18:53:58 2012 -0400
dumpstate: Skip subsequent showmaps if the first run fails.
dumpstate takes over six minutes to run as each call to "su" (which
dumpstate uses opportunistically on states that require root privileges to
access) takes approximately one second to process.
The vast majority of these "su" calls are made to "showmap", which is
called for every running process. These calls nearly always fail, either
because dumpstate is denied root access, or because "showmap" isn't
installed.
This greatly speeds up the dumpstate process by skipping subsequent
"showmap" attempts if the first run (on process init) fails.
Change-Id: Ibdfa996afff541dc30251da7ab01ac4987ae2ebc
Diffstat (limited to 'cmds')
-rw-r--r-- | cmds/dumpstate/utils.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/cmds/dumpstate/utils.c b/cmds/dumpstate/utils.c index 8f132d5..2ef541d 100644 --- a/cmds/dumpstate/utils.c +++ b/cmds/dumpstate/utils.c @@ -133,12 +133,23 @@ void do_dmesg() { } void do_showmap(int pid, const char *name) { + static bool ran = false, skip = false; char title[255]; char arg[255]; sprintf(title, "SHOW MAP %d (%s)", pid, name); sprintf(arg, "%d", pid); - run_command(title, 10, SU_PATH, "root", "showmap", arg, NULL); + + if (skip) { + /* Skip due to non-zero exit status on first run. */ + printf("------ %s: Skipped. ------\n", title); + } else { + int status = run_command(title, 10, SU_PATH, "root", "showmap", arg, NULL); + if (!ran) { + ran = true; + skip = !WIFEXITED(status) || WEXITSTATUS(status) != 0; + } + } } /* prints the contents of a file */ @@ -197,14 +208,29 @@ int run_command(const char *title, int timeout_seconds, const char *command, ... /* handle child case */ if (pid == 0) { const char *args[1024] = {command}; - size_t arg; + size_t arg = 1; + char sucmd[255]; + bool su = false; + + if (strcmp(command, SU_PATH) == 0) { + /* Need to transform calls to su from: + * su LOGIN COMMAND ... + * to: + * su -c 'COMMAND "$@"' -- LOGIN COMMAND ... */ + args[arg++] = "-c"; + args[arg++] = sucmd; + args[arg++] = "--"; + sucmd[0] = '\0'; + su = true; + } va_list ap; va_start(ap, command); if (title) printf("------ %s (%s", title, command); - for (arg = 1; arg < sizeof(args) / sizeof(args[0]); ++arg) { + for (; arg < sizeof(args) / sizeof(args[0]); ++arg) { args[arg] = va_arg(ap, const char *); if (args[arg] == NULL) break; + if (su && arg == 5) snprintf(sucmd, sizeof(sucmd), "%s \"$@\"", args[arg]); if (title) printf(" %s", args[arg]); } if (title) printf(") ------\n"); |