Remove old simulator support from liblog

As far as I know, this isn't used anymore, and is causing problems when
building with bionic on the host (with the cast of open).

Bug: 31559095
Test: host bionic compiles
Change-Id: I8b6e802e2d6dcc6e8476e387a5a365903aec3be1
This commit is contained in:
Dan Willemsen 2017-05-07 12:17:15 -07:00
parent 0de03b53fc
commit f3452d8178
3 changed files with 18 additions and 69 deletions

View File

@ -15,9 +15,7 @@
*/
/*
* Intercepts log messages intended for the Android log device.
* When running in the context of the simulator, the messages are
* passed on to the underlying (fake) log device. When not in the
* simulator, messages are printed to stderr.
* Messages are printed to stderr.
*/
#include <ctype.h>
#include <errno.h>
@ -561,7 +559,8 @@ static void showLog(LogState* state, int logPrio, const char* tag,
* tag (N bytes -- null-terminated ASCII string)
* message (N bytes -- null-terminated ASCII string)
*/
static ssize_t logWritev(int fd, const struct iovec* vector, int count) {
LIBLOG_HIDDEN ssize_t fakeLogWritev(int fd, const struct iovec* vector,
int count) {
LogState* state;
/* Make sure that no-one frees the LogState while we're using it.
@ -626,8 +625,18 @@ error:
/*
* Free up our state and close the fake descriptor.
*
* The logger API has no means or need to 'stop' or 'close' using the logs,
* and as such, there is no way for that 'stop' or 'close' to translate into
* a close operation to the fake log handler. fakeLogClose is provided for
* completeness only.
*
* We have no intention of adding a log close operation as it would complicate
* every user of the logging API with no gain since the only valid place to
* call is in the exit handler. Logging can continue in the exit handler to
* help debug HOST tools ...
*/
static int logClose(int fd) {
LIBLOG_HIDDEN int fakeLogClose(int fd) {
deleteFakeFd(fd);
return 0;
}
@ -635,7 +644,7 @@ static int logClose(int fd) {
/*
* Open a log output device and return a fake fd.
*/
static int logOpen(const char* pathName, int flags __unused) {
LIBLOG_HIDDEN int fakeLogOpen(const char* pathName) {
LogState* logState;
int fd = -1;
@ -654,66 +663,6 @@ static int logOpen(const char* pathName, int flags __unused) {
return fd;
}
/*
* Runtime redirection. If this binary is running in the simulator,
* just pass log messages to the emulated device. If it's running
* outside of the simulator, write the log messages to stderr.
*/
static int (*redirectOpen)(const char* pathName, int flags) = NULL;
static int (*redirectClose)(int fd) = NULL;
static ssize_t (*redirectWritev)(int fd, const struct iovec* vector,
int count) = NULL;
static void setRedirects() {
const char* ws;
/* Wrapsim sets this environment variable on children that it's
* created using its LD_PRELOAD wrapper.
*/
ws = getenv("ANDROID_WRAPSIM");
if (ws != NULL && strcmp(ws, "1") == 0) {
/* We're running inside wrapsim, so we can just write to the device. */
redirectOpen = (int (*)(const char* pathName, int flags))open;
redirectClose = close;
redirectWritev = writev;
} else {
/* There's no device to delegate to; handle the logging ourselves. */
redirectOpen = logOpen;
redirectClose = logClose;
redirectWritev = logWritev;
}
}
LIBLOG_HIDDEN int fakeLogOpen(const char* pathName, int flags) {
if (redirectOpen == NULL) {
setRedirects();
}
return redirectOpen(pathName, flags);
}
/*
* The logger API has no means or need to 'stop' or 'close' using the logs,
* and as such, there is no way for that 'stop' or 'close' to translate into
* a close operation to the fake log handler. fakeLogClose is provided for
* completeness only.
*
* We have no intention of adding a log close operation as it would complicate
* every user of the logging API with no gain since the only valid place to
* call is in the exit handler. Logging can continue in the exit handler to
* help debug HOST tools ...
*/
LIBLOG_HIDDEN int fakeLogClose(int fd) {
/* Assume that open() was called first. */
return redirectClose(fd);
}
LIBLOG_HIDDEN ssize_t fakeLogWritev(int fd, const struct iovec* vector,
int count) {
/* Assume that open() was called first. */
return redirectWritev(fd, vector, count);
}
LIBLOG_HIDDEN ssize_t __send_log_msg(char* buf __unused,
size_t buf_size __unused) {
return -ENODEV;

View File

@ -23,7 +23,7 @@
struct iovec;
LIBLOG_HIDDEN int fakeLogOpen(const char* pathName, int flags);
LIBLOG_HIDDEN int fakeLogOpen(const char* pathName);
LIBLOG_HIDDEN int fakeLogClose(int fd);
LIBLOG_HIDDEN ssize_t fakeLogWritev(int fd, const struct iovec* vector,
int count);

View File

@ -55,9 +55,9 @@ static int fakeOpen() {
continue;
}
snprintf(buf, sizeof(buf), "/dev/log_%s", android_log_id_to_name(i));
logFds[i] = fakeLogOpen(buf, O_WRONLY);
logFds[i] = fakeLogOpen(buf);
if (logFds[i] < 0) {
fprintf(stderr, "fakeLogOpen(%s, O_WRONLY) failed\n", buf);
fprintf(stderr, "fakeLogOpen(%s) failed\n", buf);
}
}
return 0;