summaryrefslogtreecommitdiffstats
path: root/logwrapper
diff options
context:
space:
mode:
authorRom Lemarchand <romlem@google.com>2013-01-04 16:20:36 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-01-04 16:21:14 -0800
commitb10c7b4e3daadd0e8fccade8d8064f622b509eef (patch)
tree293681532335a0d3e4d1aa768224e0202e347135 /logwrapper
parentd7c52a458e1c93b539ebd94f341f842d32d36937 (diff)
downloadsystem_core-b10c7b4e3daadd0e8fccade8d8064f622b509eef.zip
system_core-b10c7b4e3daadd0e8fccade8d8064f622b509eef.tar.gz
system_core-b10c7b4e3daadd0e8fccade8d8064f622b509eef.tar.bz2
Revert "Remove -d option from logwrapper"
This reverts commit 4d74bcf4458c4b2c902a3d4f45afbd51f5a3be1e Change-Id: Ibcd19400cd2589b52df2b3acaba25f02676ba9e0
Diffstat (limited to 'logwrapper')
-rw-r--r--logwrapper/logwrapper.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/logwrapper/logwrapper.c b/logwrapper/logwrapper.c
index 3b876d4..dd777c0 100644
--- a/logwrapper/logwrapper.c
+++ b/logwrapper/logwrapper.c
@@ -35,14 +35,17 @@ void fatal(const char *msg) {
void usage() {
fatal(
- "Usage: logwrapper BINARY [ARGS ...]\n"
+ "Usage: logwrapper [-d] BINARY [ARGS ...]\n"
"\n"
"Forks and executes BINARY ARGS, redirecting stdout and stderr to\n"
"the Android logging system. Tag is set to BINARY, priority is\n"
- "always LOG_INFO.\n");
+ "always LOG_INFO.\n"
+ "\n"
+ "-d: Causes logwrapper to SIGSEGV when BINARY terminates\n"
+ " fault address is set to the status of wait()\n");
}
-void parent(const char *tag, int parent_read) {
+void parent(const char *tag, int seg_fault_on_exit, int parent_read) {
int status;
char buffer[4096];
@@ -102,6 +105,8 @@ void parent(const char *tag, int parent_read) {
} else
ALOG(LOG_INFO, "logwrapper", "%s wait() failed: %s (%d)", tag,
strerror(errno), errno);
+ if (seg_fault_on_exit)
+ *(int *)status = 0; // causes SIGSEGV with fault_address = status
}
void child(int argc, char* argv[]) {
@@ -119,6 +124,7 @@ void child(int argc, char* argv[]) {
int main(int argc, char* argv[]) {
pid_t pid;
+ int seg_fault_on_exit = 0;
int parent_ptty;
int child_ptty;
@@ -128,6 +134,16 @@ int main(int argc, char* argv[]) {
usage();
}
+ if (strncmp(argv[1], "-d", 2) == 0) {
+ seg_fault_on_exit = 1;
+ argc--;
+ argv++;
+ }
+
+ if (argc < 2) {
+ usage();
+ }
+
/* Use ptty instead of socketpair so that STDOUT is not buffered */
parent_ptty = open("/dev/ptmx", O_RDWR);
if (parent_ptty < 0) {
@@ -163,7 +179,7 @@ int main(int argc, char* argv[]) {
setgid(AID_LOG);
setuid(AID_LOG);
- parent(argv[1], parent_ptty);
+ parent(argv[1], seg_fault_on_exit, parent_ptty);
}
return 0;