Created
May 8, 2011 06:57
-
-
Save rbochet/961177 to your computer and use it in GitHub Desktop.
Option cachée dans Logcat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case 'Q': | |
/* this is a *hidden* option used to start a version of logcat */ | |
/* in an emulated device only. it basically looks for androidboot.logcat= */ | |
/* on the kernel command line. If something is found, it extracts a log filter */ | |
/* and uses it to run the program. If nothing is found, the program should */ | |
/* quit immediately */ | |
#define KERNEL_OPTION "androidboot.logcat=" | |
#define CONSOLE_OPTION "androidboot.console=" | |
{ | |
int fd; | |
char* logcat; | |
char* console; | |
int force_exit = 1; | |
static char cmdline[1024]; | |
fd = open("/proc/cmdline", O_RDONLY); | |
if (fd >= 0) { | |
int n = read(fd, cmdline, sizeof(cmdline)-1 ); | |
if (n < 0) n = 0; | |
cmdline[n] = 0; | |
close(fd); | |
} else { | |
cmdline[0] = 0; | |
} | |
logcat = strstr( cmdline, KERNEL_OPTION ); | |
console = strstr( cmdline, CONSOLE_OPTION ); | |
if (logcat != NULL) { | |
char* p = logcat + sizeof(KERNEL_OPTION)-1;; | |
char* q = strpbrk( p, " \t\n\r" );; | |
if (q != NULL) | |
*q = 0; | |
forceFilters = p; | |
force_exit = 0; | |
} | |
/* if nothing found or invalid filters, exit quietly */ | |
if (force_exit) | |
exit(0); | |
/* redirect our output to the emulator console */ | |
if (console) { | |
char* p = console + sizeof(CONSOLE_OPTION)-1; | |
char* q = strpbrk( p, " \t\n\r" ); | |
char devname[64]; | |
int len; | |
if (q != NULL) { | |
len = q - p; | |
} else | |
len = strlen(p); | |
len = snprintf( devname, sizeof(devname), "/dev/%.*s", len, p ); | |
fprintf(stderr, "logcat using %s (%d)\n", devname, len); | |
if (len < (int)sizeof(devname)) { | |
fd = open( devname, O_WRONLY ); | |
if (fd >= 0) { | |
dup2(fd, 1); | |
dup2(fd, 2); | |
close(fd); | |
} | |
} | |
} | |
} | |
break; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment