Merge "allow dumpstate to work with dmesg_restrict=1"

This commit is contained in:
Nick Kralevich
2011-11-30 09:55:06 -08:00
committed by Android (Google) Code Review
3 changed files with 54 additions and 1 deletions

View File

@@ -25,6 +25,8 @@
#include <sys/time.h>
#include <sys/wait.h>
#include <unistd.h>
#include <linux/capability.h>
#include <linux/prctl.h>
#include <cutils/properties.h>
@@ -169,7 +171,7 @@ static void dumpstate() {
print_properties();
run_command("KERNEL LOG", 20, "dmesg", NULL);
do_dmesg();
dump_file("KERNEL WAKELOCKS", "/proc/wakelocks");
dump_file("KERNEL CPUFREQ", "/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state");
@@ -192,6 +194,7 @@ static void dumpstate() {
dump_file("PACKAGE SETTINGS", "/data/system/packages.xml");
dump_file("PACKAGE UID ERRORS", "/data/system/uiderrors.txt");
/* TODO: Make last_kmsg CAP_SYSLOG protected. b/5555691 */
dump_file("LAST KMSG", "/proc/last_kmsg");
run_command("LAST RADIO LOG", 10, "parse_radio_log", "/proc/last_radio_log", NULL);
dump_file("LAST PANIC CONSOLE", "/data/dontpanic/apanic_console");
@@ -315,6 +318,11 @@ int main(int argc, char *argv[]) {
}
if (getuid() == 0) {
if (prctl(PR_SET_KEEPCAPS, 1) < 0) {
LOGE("prctl(PR_SET_KEEPCAPS) failed: %s\n", strerror(errno));
return -1;
}
/* switch to non-root user and group */
gid_t groups[] = { AID_LOG, AID_SDCARD_RW, AID_MOUNT, AID_INET };
if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) != 0) {
@@ -329,6 +337,23 @@ int main(int argc, char *argv[]) {
LOGE("Unable to setuid, aborting: %s\n", strerror(errno));
return -1;
}
struct __user_cap_header_struct capheader;
struct __user_cap_data_struct capdata[2];
memset(&capheader, 0, sizeof(capheader));
memset(&capdata, 0, sizeof(capdata));
capheader.version = _LINUX_CAPABILITY_VERSION_3;
capheader.pid = 0;
capdata[CAP_TO_INDEX(CAP_SYSLOG)].permitted = CAP_TO_MASK(CAP_SYSLOG);
capdata[CAP_TO_INDEX(CAP_SYSLOG)].effective = CAP_TO_MASK(CAP_SYSLOG);
capdata[0].inheritable = 0;
capdata[1].inheritable = 0;
if (capset(&capheader, &capdata[0]) < 0) {
LOGE("capset failed: %s\n", strerror(errno));
return -1;
}
}
char path[PATH_MAX], tmp_path[PATH_MAX];

View File

@@ -48,6 +48,9 @@ void show_wchan(int pid, const char *name);
/* Runs "showmap" for a process */
void do_showmap(int pid, const char *name);
/* Gets the dmesg output for the kernel */
void do_dmesg();
/* Play a sound via Stagefright */
void play_sound(const char* path);

View File

@@ -28,6 +28,7 @@
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/klog.h>
#include <time.h>
#include <unistd.h>
@@ -96,6 +97,30 @@ out_close:
return;
}
void do_dmesg() {
printf("------ KERNEL LOG (dmesg) ------\n");
int size = klogctl(10, NULL, 0); /* Get size of kernel buffer */
if (size <= 0) {
printf("Unexpected klogctl return value: %d\n\n", size);
return;
}
char *buf = (char *) malloc(size + 1);
if (buf == NULL) {
printf("memory allocation failed\n\n");
return;
}
int retval = klogctl(KLOG_READ_ALL, buf, size);
if (retval < 0) {
printf("klogctl failure\n\n");
free(buf);
return;
}
buf[retval] = '\0';
printf("%s\n\n", buf);
free(buf);
return;
}
void do_showmap(int pid, const char *name) {
char title[255];
char arg[255];