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

Commit ec35efbb authored by Tom Cherry's avatar Tom Cherry Committed by Automerger Merge Worker
Browse files

Merge "liblog: add a timeout for logd command socket operations" am:...

Merge "liblog: add a timeout for logd command socket operations" am: 368c70da am: 1c999633 am: a44090fb

Original change: https://android-review.googlesource.com/c/platform/system/core/+/1389398

Change-Id: I47d315c962466d3b9db747640701f06682290115
parents 42690560 a44090fb
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@

// Connects to /dev/socket/<name> and returns the associated fd or returns -1 on error.
// O_CLOEXEC is always set.
static int socket_local_client(const std::string& name, int type) {
static int socket_local_client(const std::string& name, int type, bool timeout) {
  sockaddr_un addr = {.sun_family = AF_LOCAL};

  std::string path = "/dev/socket/" + name;
@@ -55,6 +55,18 @@ static int socket_local_client(const std::string& name, int type) {
    return -1;
  }

  if (timeout) {
    // Sending and receiving messages should be instantaneous, but we don't want to wait forever if
    // logd is hung, so we set a gracious 2s timeout.
    struct timeval t = {2, 0};
    if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &t, sizeof(t)) == -1) {
      return -1;
    }
    if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &t, sizeof(t)) == -1) {
      return -1;
    }
  }

  if (connect(fd, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) == -1) {
    close(fd);
    return -1;
@@ -69,7 +81,7 @@ ssize_t SendLogdControlMessage(char* buf, size_t buf_size) {
  size_t len;
  char* cp;
  int errno_save = 0;
  int sock = socket_local_client("logd", SOCK_STREAM);
  int sock = socket_local_client("logd", SOCK_STREAM, true);
  if (sock < 0) {
    return sock;
  }
@@ -268,7 +280,7 @@ static int logdOpen(struct logger_list* logger_list) {
    return sock;
  }

  sock = socket_local_client("logdr", SOCK_SEQPACKET);
  sock = socket_local_client("logdr", SOCK_SEQPACKET, false);
  if (sock <= 0) {
    if ((sock == -1) && errno) {
      return -errno;