summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'liblog/fake_log_device.c')
-rw-r--r--liblog/fake_log_device.c81
1 files changed, 15 insertions, 66 deletions
diff --git a/liblog/fake_log_device.c b/liblog/fake_log_device.c
index ae7a33412..1483c248e 100644
--- a/liblog/fake_log_device.c
+++ b/liblog/fake_log_device.c
@@ -15,9 +15,7 @@
15 */ 15 */
16/* 16/*
17 * Intercepts log messages intended for the Android log device. 17 * Intercepts log messages intended for the Android log device.
18 * When running in the context of the simulator, the messages are 18 * Messages are printed to stderr.
19 * passed on to the underlying (fake) log device. When not in the
20 * simulator, messages are printed to stderr.
21 */ 19 */
22#include <ctype.h> 20#include <ctype.h>
23#include <errno.h> 21#include <errno.h>
@@ -561,7 +559,8 @@ static void showLog(LogState* state, int logPrio, const char* tag,
561 * tag (N bytes -- null-terminated ASCII string) 559 * tag (N bytes -- null-terminated ASCII string)
562 * message (N bytes -- null-terminated ASCII string) 560 * message (N bytes -- null-terminated ASCII string)
563 */ 561 */
564static ssize_t logWritev(int fd, const struct iovec* vector, int count) { 562LIBLOG_HIDDEN ssize_t fakeLogWritev(int fd, const struct iovec* vector,
563 int count) {
565 LogState* state; 564 LogState* state;
566 565
567 /* Make sure that no-one frees the LogState while we're using it. 566 /* Make sure that no-one frees the LogState while we're using it.
@@ -626,8 +625,18 @@ error:
626 625
627/* 626/*
628 * Free up our state and close the fake descriptor. 627 * Free up our state and close the fake descriptor.
628 *
629 * The logger API has no means or need to 'stop' or 'close' using the logs,
630 * and as such, there is no way for that 'stop' or 'close' to translate into
631 * a close operation to the fake log handler. fakeLogClose is provided for
632 * completeness only.
633 *
634 * We have no intention of adding a log close operation as it would complicate
635 * every user of the logging API with no gain since the only valid place to
636 * call is in the exit handler. Logging can continue in the exit handler to
637 * help debug HOST tools ...
629 */ 638 */
630static int logClose(int fd) { 639LIBLOG_HIDDEN int fakeLogClose(int fd) {
631 deleteFakeFd(fd); 640 deleteFakeFd(fd);
632 return 0; 641 return 0;
633} 642}
@@ -635,7 +644,7 @@ static int logClose(int fd) {
635/* 644/*
636 * Open a log output device and return a fake fd. 645 * Open a log output device and return a fake fd.
637 */ 646 */
638static int logOpen(const char* pathName, int flags __unused) { 647LIBLOG_HIDDEN int fakeLogOpen(const char* pathName) {
639 LogState* logState; 648 LogState* logState;
640 int fd = -1; 649 int fd = -1;
641 650
@@ -654,66 +663,6 @@ static int logOpen(const char* pathName, int flags __unused) {
654 return fd; 663 return fd;
655} 664}
656 665
657/*
658 * Runtime redirection. If this binary is running in the simulator,
659 * just pass log messages to the emulated device. If it's running
660 * outside of the simulator, write the log messages to stderr.
661 */
662
663static int (*redirectOpen)(const char* pathName, int flags) = NULL;
664static int (*redirectClose)(int fd) = NULL;
665static ssize_t (*redirectWritev)(int fd, const struct iovec* vector,
666 int count) = NULL;
667
668static void setRedirects() {
669 const char* ws;
670
671 /* Wrapsim sets this environment variable on children that it's
672 * created using its LD_PRELOAD wrapper.
673 */
674 ws = getenv("ANDROID_WRAPSIM");
675 if (ws != NULL && strcmp(ws, "1") == 0) {
676 /* We're running inside wrapsim, so we can just write to the device. */
677 redirectOpen = (int (*)(const char* pathName, int flags))open;
678 redirectClose = close;
679 redirectWritev = writev;
680 } else {
681 /* There's no device to delegate to; handle the logging ourselves. */
682 redirectOpen = logOpen;
683 redirectClose = logClose;
684 redirectWritev = logWritev;
685 }
686}
687
688LIBLOG_HIDDEN int fakeLogOpen(const char* pathName, int flags) {
689 if (redirectOpen == NULL) {
690 setRedirects();
691 }
692 return redirectOpen(pathName, flags);
693}
694
695/*
696 * The logger API has no means or need to 'stop' or 'close' using the logs,
697 * and as such, there is no way for that 'stop' or 'close' to translate into
698 * a close operation to the fake log handler. fakeLogClose is provided for
699 * completeness only.
700 *
701 * We have no intention of adding a log close operation as it would complicate
702 * every user of the logging API with no gain since the only valid place to
703 * call is in the exit handler. Logging can continue in the exit handler to
704 * help debug HOST tools ...
705 */
706LIBLOG_HIDDEN int fakeLogClose(int fd) {
707 /* Assume that open() was called first. */
708 return redirectClose(fd);
709}
710
711LIBLOG_HIDDEN ssize_t fakeLogWritev(int fd, const struct iovec* vector,
712 int count) {
713 /* Assume that open() was called first. */
714 return redirectWritev(fd, vector, count);
715}
716
717LIBLOG_HIDDEN ssize_t __send_log_msg(char* buf __unused, 666LIBLOG_HIDDEN ssize_t __send_log_msg(char* buf __unused,
718 size_t buf_size __unused) { 667 size_t buf_size __unused) {
719 return -ENODEV; 668 return -ENODEV;