summaryrefslogtreecommitdiffstats
path: root/logwrapper/logwrap.c
diff options
context:
space:
mode:
authorYusuke Sato <yusukes@google.com>2015-08-19 23:58:45 -0700
committerYusuke Sato <yusukes@google.com>2015-08-21 17:14:59 -0700
commit7980426a6ffb35567c8a7b83fe0acef2c3033bd4 (patch)
tree4d032a99954e11ac76d7b8b5680f2e307e63e9a1 /logwrapper/logwrap.c
parenta1b2036f4daf9e0de0fe616e5f371d75f6b2357d (diff)
downloadcore-7980426a6ffb35567c8a7b83fe0acef2c3033bd4.tar.gz
core-7980426a6ffb35567c8a7b83fe0acef2c3033bd4.tar.bz2
core-7980426a6ffb35567c8a7b83fe0acef2c3033bd4.zip
Add FORK_EXECVP_OPTION_CAPTURE_OUTPUT to logwrap.h
This allows raw popen calls in e.g. system/netd/ to be replaced with android_fork_execvp_ext(). Change-Id: I159ece7369fa38ff8782024bef0d7cfafe74ecee
Diffstat (limited to 'logwrapper/logwrap.c')
-rw-r--r--logwrapper/logwrap.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/logwrapper/logwrap.c b/logwrapper/logwrap.c
index c7b48358e..39bc8fd1b 100644
--- a/logwrapper/logwrap.c
+++ b/logwrapper/logwrap.c
@@ -291,7 +291,8 @@ static void print_abbr_buf(struct log_info *log_info) {
}
static int parent(const char *tag, int parent_read, pid_t pid,
- int *chld_sts, int log_target, bool abbreviated, char *file_path) {
+ int *chld_sts, int log_target, bool abbreviated, char *file_path,
+ const struct AndroidForkExecvpOption* opts, size_t opts_len) {
int status = 0;
char buffer[4096];
struct pollfd poll_fds[] = {
@@ -358,6 +359,13 @@ static int parent(const char *tag, int parent_read, pid_t pid,
sz = TEMP_FAILURE_RETRY(
read(parent_read, &buffer[b], sizeof(buffer) - 1 - b));
+ for (size_t i = 0; sz > 0 && i < opts_len; ++i) {
+ if (opts[i].opt_type == FORK_EXECVP_OPTION_CAPTURE_OUTPUT) {
+ opts[i].opt_capture_output.on_output(
+ (uint8_t*)&buffer[b], sz, opts[i].opt_capture_output.user_pointer);
+ }
+ }
+
sz += b;
// Log one line at a time
for (b = 0; b < sz; b++) {
@@ -484,7 +492,6 @@ int android_fork_execvp_ext(int argc, char* argv[], int *status, bool ignore_int
sigset_t blockset;
sigset_t oldset;
int rc = 0;
- size_t i;
rc = pthread_mutex_lock(&fd_mutex);
if (rc) {
@@ -532,7 +539,7 @@ int android_fork_execvp_ext(int argc, char* argv[], int *status, bool ignore_int
close(parent_ptty);
// redirect stdin, stdout and stderr
- for (i = 0; i < opts_len; ++i) {
+ for (size_t i = 0; i < opts_len; ++i) {
if (opts[i].opt_type == FORK_EXECVP_OPTION_INPUT) {
dup2(child_ptty, 0);
break;
@@ -554,7 +561,7 @@ int android_fork_execvp_ext(int argc, char* argv[], int *status, bool ignore_int
sigaction(SIGQUIT, &ignact, &quitact);
}
- for (i = 0; i < opts_len; ++i) {
+ for (size_t i = 0; i < opts_len; ++i) {
if (opts[i].opt_type == FORK_EXECVP_OPTION_INPUT) {
size_t left = opts[i].opt_input.input_len;
const uint8_t* input = opts[i].opt_input.input;
@@ -571,7 +578,7 @@ int android_fork_execvp_ext(int argc, char* argv[], int *status, bool ignore_int
}
rc = parent(argv[0], parent_ptty, pid, status, log_target,
- abbreviated, file_path);
+ abbreviated, file_path, opts, opts_len);
}
if (ignore_int_quit) {