diff --git a/main.cpp b/main.cpp index 9cbcf88..68477ac 100644 --- a/main.cpp +++ b/main.cpp @@ -39,7 +39,7 @@ #include #include -static int process_config(VolumeManager *vm); +static int process_config(VolumeManager *vm, bool* has_adoptable); static void coldboot(const char *path); static void parse_args(int argc, char** argv); @@ -106,7 +106,9 @@ int main(int argc, char** argv) { exit(1); } - if (process_config(vm)) { + bool has_adoptable; + + if (process_config(vm, &has_adoptable)) { PLOG(ERROR) << "Error reading configuration... continuing anyways"; } @@ -131,6 +133,10 @@ int main(int argc, char** argv) { exit(1); } + // This call should go after listeners are started to avoid + // a deadlock between vold and init (see b/34278978 for details) + property_set("vold.has_adoptable", has_adoptable ? "1" : "0"); + // Eventually we'll become the monitoring thread while(1) { sleep(1000); @@ -207,7 +213,7 @@ static void coldboot(const char *path) { } } -static int process_config(VolumeManager *vm) { +static int process_config(VolumeManager *vm, bool* has_adoptable) { std::string path(android::vold::DefaultFstabPath()); fstab = fs_mgr_read_fstab(path.c_str()); if (!fstab) { @@ -216,7 +222,7 @@ static int process_config(VolumeManager *vm) { } /* Loop through entries looking for ones that vold manages */ - bool has_adoptable = false; + *has_adoptable = false; for (int i = 0; i < fstab->num_entries; i++) { if (fs_mgr_is_voldmanaged(&fstab->recs[i])) { if (fs_mgr_is_nonremovable(&fstab->recs[i])) { @@ -230,7 +236,7 @@ static int process_config(VolumeManager *vm) { if (fs_mgr_is_encryptable(&fstab->recs[i])) { flags |= android::vold::Disk::Flags::kAdoptable; - has_adoptable = true; + *has_adoptable = true; } if (fs_mgr_is_noemulatedsd(&fstab->recs[i]) || property_get_bool("vold.debug.default_primary", false)) { @@ -241,6 +247,5 @@ static int process_config(VolumeManager *vm) { new VolumeManager::DiskSource(sysPattern, nickname, flags))); } } - property_set("vold.has_adoptable", has_adoptable ? "1" : "0"); return 0; }