summaryrefslogtreecommitdiffstats
path: root/cmds/dumpstate
diff options
context:
space:
mode:
authorMike Lockwood <lockwood@android.com>2009-09-02 18:01:05 -0400
committerMike Lockwood <lockwood@android.com>2009-09-02 20:31:33 -0400
commit8d5337301b87ba84a45327f355aa768c864de021 (patch)
tree568780b6851e908dd5ee0eb5bd63946f173c5f3f /cmds/dumpstate
parent14d8e6e5d5503fe420bb3276d367cba1bfba03f9 (diff)
downloadframeworks_base-8d5337301b87ba84a45327f355aa768c864de021.zip
frameworks_base-8d5337301b87ba84a45327f355aa768c864de021.tar.gz
frameworks_base-8d5337301b87ba84a45327f355aa768c864de021.tar.bz2
dumpstate: Add option to output to socket, disable code that switched to nonroot
This will be used to allow running dumpstate as root from the init process to enable gathering debugging information that requires root to access. Change-Id: I5bb7e83071fad2b377e549058f318a5118194061 Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'cmds/dumpstate')
-rw-r--r--cmds/dumpstate/dumpstate.c80
1 files changed, 54 insertions, 26 deletions
diff --git a/cmds/dumpstate/dumpstate.c b/cmds/dumpstate/dumpstate.c
index 3ddc922..6a00e3e 100644
--- a/cmds/dumpstate/dumpstate.c
+++ b/cmds/dumpstate/dumpstate.c
@@ -25,6 +25,7 @@
#include <sys/time.h>
#include <sys/resource.h>
+#include <cutils/sockets.h>
#include "private/android_filesystem_config.h"
#include "dumpstate.h"
@@ -164,11 +165,11 @@ static int check_command_name(const char* name, const char* test) {
int main(int argc, char *argv[]) {
int dumpcrash = check_command_name(argv[0], "dumpcrash");
- int bugreport = check_command_name(argv[0], "bugreport");
int add_date = 0;
char* outfile = 0;
int vibrate = 0;
int compress = 0;
+ int socket = 0;
int c, fd, vibrate_fd, fds[2];
char path[PATH_MAX];
pid_t pid;
@@ -180,31 +181,32 @@ int main(int argc, char *argv[]) {
get_time(&now);
- if (bugreport) {
- do {
- c = getopt(argc, argv, "do:vz");
- if (c == EOF)
+ do {
+ c = getopt(argc, argv, "do:svz");
+ if (c == EOF)
+ break;
+ switch (c) {
+ case 'd':
+ add_date = 1;
break;
- switch (c) {
- case 'd':
- add_date = 1;
- break;
- case 'o':
- outfile = optarg;
- break;
- case 'v':
- vibrate = 1;
- break;
- case 'z':
- compress = 1;
- break;
- case '?':
- fprintf(stderr, "%s: invalid option -%c\n",
- argv[0], optopt);
- exit(1);
- }
- } while (1);
- }
+ case 'o':
+ outfile = optarg;
+ break;
+ case 'v':
+ vibrate = 1;
+ break;
+ case 'z':
+ compress = 1;
+ break;
+ case 's':
+ socket = 1;
+ break;
+ case '?':
+ fprintf(stderr, "%s: invalid option -%c\n",
+ argv[0], optopt);
+ exit(1);
+ }
+ } while (1);
/* open vibrator before switching user */
if (vibrate) {
@@ -214,14 +216,40 @@ int main(int argc, char *argv[]) {
} else
vibrate_fd = -1;
+#if 0
/* switch to non-root user and group */
setgroups(sizeof(groups)/sizeof(groups[0]), groups);
setuid(AID_SHELL);
+#endif
/* make it safe to use both printf and STDOUT_FILENO */
setvbuf(stdout, 0, _IONBF, 0);
- if (outfile) {
+ if (socket) {
+ struct sockaddr addr;
+ socklen_t alen;
+
+ int s = android_get_control_socket("dumpstate");
+ if (s < 0) {
+ fprintf(stderr, "could not open dumpstate socket\n");
+ exit(1);
+ }
+ if (listen(s, 4) < 0) {
+ fprintf(stderr, "could not listen on dumpstate socket\n");
+ exit(1);
+ }
+
+ alen = sizeof(addr);
+ fd = accept(s, &addr, &alen);
+ if (fd < 0) {
+ fprintf(stderr, "could not accept dumpstate socket\n");
+ exit(1);
+ }
+
+ /* redirect stdout to the socket */
+ dup2(fd, STDOUT_FILENO);
+ close(fd);
+ } else if (outfile) {
if (strlen(outfile) > sizeof(path) - 100)
exit(1);