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

Commit 1324002f authored by Akilesh Kailash's avatar Akilesh Kailash Committed by Gerrit Code Review
Browse files

Merge "libsnapshot: Wait for daemon to terminate after snapshot unamp"

parents 6f9a9092 d2063ad7
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ class SnapuserdClient {
    bool ValidateConnection();
    std::string GetDaemonAliveIndicatorPath();

    void WaitForServiceToTerminate(std::chrono::milliseconds timeout_ms);

  public:
    explicit SnapuserdClient(android::base::unique_fd&& sockfd);
    SnapuserdClient(){};
+17 −0
Original line number Diff line number Diff line
@@ -94,6 +94,21 @@ std::unique_ptr<SnapuserdClient> SnapuserdClient::Connect(const std::string& soc
    return client;
}

void SnapuserdClient::WaitForServiceToTerminate(std::chrono::milliseconds timeout_ms) {
    auto start = std::chrono::steady_clock::now();
    while (android::base::GetProperty("init.svc.snapuserd", "") == "running") {
        auto now = std::chrono::steady_clock::now();
        auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(now - start);
        if (elapsed >= timeout_ms) {
            LOG(ERROR) << "Timed out - Snapuserd service did not stop - Forcefully terminating the "
                          "service";
            android::base::SetProperty("ctl.stop", "snapuserd");
            return;
        }
        std::this_thread::sleep_for(100ms);
    }
}

bool SnapuserdClient::ValidateConnection() {
    if (!Sendmsg("query")) {
        return false;
@@ -238,6 +253,8 @@ bool SnapuserdClient::DetachSnapuserd() {
        LOG(ERROR) << "Failed to detach snapuserd.";
        return false;
    }

    WaitForServiceToTerminate(3s);
    return true;
}