Start snapuserd if needed as soon as possible during second-stage init.
snapuserd is used as a user-space block device implementation during Virtual A/B Compression-enabled updates. It has to be started in first-stage init, so that updated partitions can be mounted. Once init reaches second-stage, and sepolicy is loaded, we want to re-launch snapuserd at the correct privilege level. We accomplish this by rebuilding the device-mapper tables of each block device, which allows us to re-bind the kernel driver to a new instance of snapuserd. After this, the old daemon can be shut down. Ideally this transition happens as soon as possible, before any .rc scripts are run. This minimizes the amount of time the original snapuserd is running, as well as any ambiguity about which instance of snapuserd is the correct one. The original daemon is sent a SIGTERM signal once the transition is complete. The pid is stored in an environment variable to make this possible (these details are implemented in libsnapshot). Bug: 168259959 Test: manual test Change-Id: Ife9518e502ce02f11ec54e7f3e6adc6f04d94133
This commit is contained in:
parent
f57fd97df3
commit
b031def229
1 changed files with 29 additions and 0 deletions
|
|
@ -53,6 +53,7 @@
|
|||
#include <keyutils.h>
|
||||
#include <libavb/libavb.h>
|
||||
#include <libgsi/libgsi.h>
|
||||
#include <libsnapshot/snapshot.h>
|
||||
#include <processgroup/processgroup.h>
|
||||
#include <processgroup/setup.h>
|
||||
#include <selinux/android.h>
|
||||
|
|
@ -94,6 +95,7 @@ using android::base::StringPrintf;
|
|||
using android::base::Timer;
|
||||
using android::base::Trim;
|
||||
using android::fs_mgr::AvbHandle;
|
||||
using android::snapshot::SnapshotManager;
|
||||
|
||||
namespace android {
|
||||
namespace init {
|
||||
|
|
@ -722,6 +724,32 @@ void SendLoadPersistentPropertiesMessage() {
|
|||
}
|
||||
}
|
||||
|
||||
static Result<void> TransitionSnapuserdAction(const BuiltinArguments&) {
|
||||
if (!SnapshotManager::IsSnapshotManagerNeeded() ||
|
||||
!android::base::GetBoolProperty(android::snapshot::kVirtualAbCompressionProp, false)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto sm = SnapshotManager::New();
|
||||
if (!sm) {
|
||||
LOG(FATAL) << "Failed to create SnapshotManager, will not transition snapuserd";
|
||||
return {};
|
||||
}
|
||||
|
||||
ServiceList& service_list = ServiceList::GetInstance();
|
||||
auto svc = service_list.FindService("snapuserd");
|
||||
if (!svc) {
|
||||
LOG(FATAL) << "Failed to find snapuserd service, aborting transition";
|
||||
return {};
|
||||
}
|
||||
svc->Start();
|
||||
|
||||
if (!sm->PerformSecondStageTransition()) {
|
||||
LOG(FATAL) << "Failed to transition snapuserd to second-stage";
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
int SecondStageMain(int argc, char** argv) {
|
||||
if (REBOOT_BOOTLOADER_ON_PANIC) {
|
||||
InstallRebootSignalHandlers();
|
||||
|
|
@ -847,6 +875,7 @@ int SecondStageMain(int argc, char** argv) {
|
|||
SetProperty(gsi::kGsiInstalledProp, is_installed);
|
||||
|
||||
am.QueueBuiltinAction(SetupCgroupsAction, "SetupCgroups");
|
||||
am.QueueBuiltinAction(TransitionSnapuserdAction, "TransitionSnapuserd");
|
||||
am.QueueBuiltinAction(SetKptrRestrictAction, "SetKptrRestrict");
|
||||
am.QueueBuiltinAction(TestPerfEventSelinuxAction, "TestPerfEventSelinux");
|
||||
am.QueueEventTrigger("early-init");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue