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

Commit 3a7774d6 authored by Akilesh Kailash's avatar Akilesh Kailash Committed by Gerrit Code Review
Browse files

Merge "libsnapshot: Detach the daemon explicitly before stopping the service" into main

parents db6cb42d 1752c5f2
Loading
Loading
Loading
Loading
+16 −8
Original line number Diff line number Diff line
@@ -2864,15 +2864,23 @@ void SnapshotTestEnvironment::TearDown() {
}

void KillSnapuserd() {
    auto status = android::base::GetProperty("init.svc.snapuserd", "stopped");
    if (status == "stopped") {
        return;
    // Detach the daemon if it's alive
    auto snapuserd_client = SnapuserdClient::TryConnect(kSnapuserdSocket, 5s);
    if (snapuserd_client) {
        snapuserd_client->DetachSnapuserd();
    }
    auto snapuserd_client = SnapuserdClient::Connect(kSnapuserdSocket, 5s);
    if (!snapuserd_client) {
        return;

    // Now stop the service - Init will send a SIGKILL to the daemon. However,
    // process state will move from "running" to "stopping". Only after the
    // process is reaped by init, the service state is moved to "stopped".
    //
    // Since the tests involve starting the daemon immediately, wait for the
    // process to completely stop (aka. wait until init reaps the terminated
    // process).
    android::base::SetProperty("ctl.stop", "snapuserd");
    if (!android::base::WaitForProperty("init.svc.snapuserd", "stopped", 10s)) {
        LOG(ERROR) << "Timed out waiting for snapuserd to stop.";
    }
    snapuserd_client->DetachSnapuserd();
}

}  // namespace snapshot