summaryrefslogtreecommitdiffstats
path: root/logwrapper/logwrapper.c
diff options
context:
space:
mode:
authorKen Sumrall <ksumrall@android.com>2013-04-03 13:45:10 -0700
committerKen Sumrall <ksumrall@android.com>2013-04-14 17:10:55 -0700
commit96e11b5bc473918d61b088f1840e4d1ec48fd3ab (patch)
tree9571af9ff057714214028fb7f5d431869580e0a6 /logwrapper/logwrapper.c
parent7425fd1b231fcdb3c260877a13f794a0c7361e80 (diff)
downloadsystem_core-96e11b5bc473918d61b088f1840e4d1ec48fd3ab.zip
system_core-96e11b5bc473918d61b088f1840e4d1ec48fd3ab.tar.gz
system_core-96e11b5bc473918d61b088f1840e4d1ec48fd3ab.tar.bz2
logwrapper: Add ability to log to kernel log
Also add ability to do abbreviated logging where only the first 4K bytes and last 4K bytes of output are added to the desginated log. Also update standalog logwrapper command to support the new options. Change-Id: Ia49cbe58479b9f9ed077498d6852e20b21287bad
Diffstat (limited to 'logwrapper/logwrapper.c')
-rw-r--r--logwrapper/logwrapper.c45
1 files changed, 33 insertions, 12 deletions
diff --git a/logwrapper/logwrapper.c b/logwrapper/logwrapper.c
index ed71a29..d1c6240 100644
--- a/logwrapper/logwrapper.c
+++ b/logwrapper/logwrapper.c
@@ -17,8 +17,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
+#include <unistd.h>
#include <logwrap/logwrap.h>
+#include <cutils/klog.h>
#include "cutils/log.h"
@@ -30,36 +32,55 @@ void fatal(const char *msg) {
void usage() {
fatal(
- "Usage: logwrapper [-d] BINARY [ARGS ...]\n"
+ "Usage: logwrapper [-a] [-d] [-k] 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"
"\n"
+ "-a: Causes logwrapper to do abbreviated logging.\n"
+ " This logs up to the first 4K and last 4K of the command\n"
+ " being run, and logs the output when the command exits\n"
"-d: Causes logwrapper to SIGSEGV when BINARY terminates\n"
- " fault address is set to the status of wait()\n");
+ " fault address is set to the status of wait()\n"
+ "-k: Causes logwrapper to log to the kernel log instead of\n"
+ " the Android system log\n");
}
int main(int argc, char* argv[]) {
int seg_fault_on_exit = 0;
+ int log_target = LOG_ALOG;
+ bool abbreviated = false;
+ int ch;
int status = 0xAAAA;
int rc;
- if (argc < 2) {
- usage();
- }
-
- if (strncmp(argv[1], "-d", 2) == 0) {
- seg_fault_on_exit = 1;
- argc--;
- argv++;
+ while ((ch = getopt(argc, argv, "adk")) != -1) {
+ switch (ch) {
+ case 'a':
+ abbreviated = true;
+ break;
+ case 'd':
+ seg_fault_on_exit = 1;
+ break;
+ case 'k':
+ log_target = LOG_KLOG;
+ klog_set_level(6);
+ break;
+ case '?':
+ default:
+ usage();
+ }
}
+ argc -= optind;
+ argv += optind;
- if (argc < 2) {
+ if (argc < 1) {
usage();
}
- rc = android_fork_execvp(argc - 1, &argv[1], &status, true, true);
+ rc = android_fork_execvp_ext(argc, &argv[0], &status, true,
+ log_target, abbreviated);
if (!rc) {
if (WIFEXITED(status))
rc = WEXITSTATUS(status);