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

Commit ab91ee98 authored by Nikita Ioffe's avatar Nikita Ioffe
Browse files

userspace reboot: unmount apexes and switch to bootstrap namespace

This will bring device to the state closer to the one during normal boot

Bug: 135984674
Test: adb install system/apex/shim/com.android.apex.cts.shim.v1.apex
Test: adb reboot userspace
Test: verified install succeeded
Change-Id: I6ef73bde2ca817c8a62bf19b8f1895dd0d6d2829
parent dbee3618
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@
#include "action_manager.h"
#include "builtin_arguments.h"
#include "init.h"
#include "mount_namespace.h"
#include "property_service.h"
#include "reboot_utils.h"
#include "service.h"
@@ -713,6 +714,18 @@ static void LeaveShutdown() {
    SendStartSendingMessagesMessage();
}

static Result<void> UnmountAllApexes() {
    const char* args[] = {"/system/bin/apexd", "--unmount-all"};
    int status;
    if (logwrap_fork_execvp(arraysize(args), args, &status, false, LOG_KLOG, true, nullptr) != 0) {
        return ErrnoError() << "Failed to call '/system/bin/apexd --unmount-all'";
    }
    if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
        return {};
    }
    return Error() << "'/system/bin/apexd --unmount-all' failed : " << status;
}

static Result<void> DoUserspaceReboot() {
    LOG(INFO) << "Userspace reboot initiated";
    auto guard = android::base::make_scope_guard([] {
@@ -754,7 +767,12 @@ static Result<void> DoUserspaceReboot() {
        // TODO(b/135984674): store information about offending services for debugging.
        return Error() << r << " debugging services are still running";
    }
    // TODO(b/135984674): deactivate APEX modules and switch back to bootstrap namespace.
    if (auto result = UnmountAllApexes(); !result) {
        return result;
    }
    if (!SwitchToBootstrapMountNamespaceIfNeeded()) {
        return Error() << "Failed to switch to bootstrap namespace";
    }
    // Re-enable services
    for (const auto& s : were_enabled) {
        LOG(INFO) << "Re-enabling service '" << s->name() << "'";