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

Commit 4df42025 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "libpdx_uds: Handle EACCES error when connecting to PDX service" into oc-dev

parents ca0b8ccf c0fd676f
Loading
Loading
Loading
Loading
+9 −4
Original line number Original line Diff line number Diff line
@@ -65,6 +65,7 @@ Status<std::unique_ptr<pdx::ClientChannel>> ClientChannelFactory::Connect(
  auto time_end = now + std::chrono::milliseconds{timeout_ms};
  auto time_end = now + std::chrono::milliseconds{timeout_ms};


  bool connected = false;
  bool connected = false;
  int max_eaccess = 5;  // Max number of times to retry when EACCES returned.
  while (!connected) {
  while (!connected) {
    int64_t timeout = -1;
    int64_t timeout = -1;
    if (use_timeout) {
    if (use_timeout) {
@@ -84,10 +85,14 @@ Status<std::unique_ptr<pdx::ClientChannel>> ClientChannelFactory::Connect(
    if (ret == -1) {
    if (ret == -1) {
      ALOGD("ClientChannelFactory: Connect error %d: %s", errno,
      ALOGD("ClientChannelFactory: Connect error %d: %s", errno,
            strerror(errno));
            strerror(errno));
      if (errno == ECONNREFUSED) {
      // if |max_eaccess| below reaches zero when errno is EACCES, the control
        // Connection refused can be the result of connecting too early (the
      // flows into the next "else if" statement and a permanent error is
        // service socket is created but not being listened to yet).
      // returned from this function.
        ALOGD("ClientChannelFactory: Connection refused, waiting...");
      if (errno == ECONNREFUSED || (errno == EACCES && max_eaccess-- > 0)) {
        // Connection refused/Permission denied can be the result of connecting
        // too early (the service socket is created but its access rights are
        // not set or not being listened to yet).
        ALOGD("ClientChannelFactory: %s, waiting...", strerror(errno));
        using namespace std::literals::chrono_literals;
        using namespace std::literals::chrono_literals;
        std::this_thread::sleep_for(100ms);
        std::this_thread::sleep_for(100ms);
      } else if (errno != ENOENT && errno != ENOTDIR) {
      } else if (errno != ENOENT && errno != ENOTDIR) {