From d6127ef7956f01ca0378db54856302068a8560df Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Thu, 15 Jun 2017 17:13:56 -0700 Subject: [PATCH] Use WaitForProperty() to wait for restorecon We have android::base::WaitForProperty() that uses futexes to efficiently wait for property value changes, so use that instead polling. Test: Boot bullhead Change-Id: Id964eddbdbfd9b5ceac5ed83a8ed66b9e60008ca --- Utils.cpp | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/Utils.cpp b/Utils.cpp index 49b51d6..ab1b605 100644 --- a/Utils.cpp +++ b/Utils.cpp @@ -20,11 +20,11 @@ #include #include +#include #include #include -#include -#include #include +#include #include #include @@ -639,19 +639,12 @@ dev_t GetDevice(const std::string& path) { status_t RestoreconRecursive(const std::string& path) { LOG(VERBOSE) << "Starting restorecon of " << path; - // TODO: find a cleaner way of waiting for restorecon to finish - const char* cpath = path.c_str(); - property_set("selinux.restorecon_recursive", ""); - property_set("selinux.restorecon_recursive", cpath); - - char value[PROPERTY_VALUE_MAX]; - while (true) { - property_get("selinux.restorecon_recursive", value, ""); - if (strcmp(cpath, value) == 0) { - break; - } - usleep(100000); // 100ms - } + static constexpr const char* kRestoreconString = "selinux.restorecon_recursive"; + + android::base::SetProperty(kRestoreconString, ""); + android::base::SetProperty(kRestoreconString, path); + + android::base::WaitForProperty(kRestoreconString, path); LOG(VERBOSE) << "Finished restorecon of " << path; return OK; @@ -684,7 +677,7 @@ ScopedDir::~ScopedDir() { } bool IsRunningInEmulator() { - return property_get_bool("ro.kernel.qemu", 0); + return android::base::GetBoolProperty("ro.kernel.qemu", false); } } // namespace vold