Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f11e56fb authored by Dan Willemsen's avatar Dan Willemsen Committed by android-build-merger
Browse files

Merge changes Ie0b30417,I8b6e802e am: ee9e5d09 am: ae587a8f

am: 8652dd2a

Change-Id: If2e0de6be32ff7bc64c0dbdfcdc4599c8b0a29d7
parents 756ee8de 8652dd2a
Loading
Loading
Loading
Loading
+0 −1
Original line number Original line Diff line number Diff line
cc_defaults {
cc_defaults {
    name: "debuggerd_defaults",
    name: "debuggerd_defaults",
    defaults: ["linux_bionic_supported"],
    cflags: [
    cflags: [
        "-Wall",
        "-Wall",
        "-Wextra",
        "-Wextra",
+15 −66
Original line number Original line Diff line number Diff line
@@ -15,9 +15,7 @@
 */
 */
/*
/*
 * Intercepts log messages intended for the Android log device.
 * Intercepts log messages intended for the Android log device.
 * When running in the context of the simulator, the messages are
 * Messages are printed to stderr.
 * passed on to the underlying (fake) log device.  When not in the
 * simulator, messages are printed to stderr.
 */
 */
#include <ctype.h>
#include <ctype.h>
#include <errno.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)
 *  tag (N bytes -- null-terminated ASCII string)
 *  message (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;
  LogState* state;


  /* Make sure that no-one frees the LogState while we're using it.
  /* 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.
 * 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);
  deleteFakeFd(fd);
  return 0;
  return 0;
}
}
@@ -635,7 +644,7 @@ static int logClose(int fd) {
/*
/*
 * Open a log output device and return a fake 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;
  LogState* logState;
  int fd = -1;
  int fd = -1;


@@ -654,66 +663,6 @@ static int logOpen(const char* pathName, int flags __unused) {
  return fd;
  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,
LIBLOG_HIDDEN ssize_t __send_log_msg(char* buf __unused,
                                     size_t buf_size __unused) {
                                     size_t buf_size __unused) {
  return -ENODEV;
  return -ENODEV;
+1 −1
Original line number Original line Diff line number Diff line
@@ -23,7 +23,7 @@


struct iovec;
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 int fakeLogClose(int fd);
LIBLOG_HIDDEN ssize_t fakeLogWritev(int fd, const struct iovec* vector,
LIBLOG_HIDDEN ssize_t fakeLogWritev(int fd, const struct iovec* vector,
                                    int count);
                                    int count);
+2 −2
Original line number Original line Diff line number Diff line
@@ -55,9 +55,9 @@ static int fakeOpen() {
      continue;
      continue;
    }
    }
    snprintf(buf, sizeof(buf), "/dev/log_%s", android_log_id_to_name(i));
    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) {
    if (logFds[i] < 0) {
      fprintf(stderr, "fakeLogOpen(%s, O_WRONLY) failed\n", buf);
      fprintf(stderr, "fakeLogOpen(%s) failed\n", buf);
    }
    }
  }
  }
  return 0;
  return 0;