summaryrefslogtreecommitdiff
path: root/init/init.cpp
diff options
context:
space:
mode:
authorWei Wang <wvw@google.com>2017-01-25 16:27:03 -0800
committerWei Wang <wvw@google.com>2017-02-01 16:11:33 -0800
commit132ac31b4738094e62cc1744e75f3756a035302c (patch)
treeb7d531a891dc862df3201509d7a30db0b58277c4 /init/init.cpp
parentafe25958b66f6186ada566a7c4af6b776b00cc42 (diff)
init: add wait_for_prop builtin command
There are many use cases from vendors to exec service in background and then use a shell scriprt to wait for the command done. This CL is to add a wait_for_prop command to suppor those use cases. Bug: 34746108 Test: on marlin Change-Id: Ia81290b0928f9d375710d2daa546714f0cd65b72
Diffstat (limited to 'init/init.cpp')
-rw-r--r--init/init.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/init/init.cpp b/init/init.cpp
index 850a9046e..9322eb28e 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -87,6 +87,10 @@ bool waiting_for_exec = false;
static int epoll_fd = -1;
+static std::unique_ptr<Timer> waiting_for_prop(nullptr);
+static std::string wait_prop_name;
+static std::string wait_prop_value;
+
void register_epoll_handler(int fd, void (*fn)()) {
epoll_event ev;
ev.events = EPOLLIN;
@@ -128,10 +132,34 @@ int add_environment(const char *key, const char *val)
return -1;
}
+bool wait_property(const char *name, const char *value)
+{
+ if (waiting_for_prop) {
+ return false;
+ }
+ if (property_get(name) != value) {
+ // Current property value is not equal to expected value
+ wait_prop_name = name;
+ wait_prop_value = value;
+ waiting_for_prop.reset(new Timer());
+ } else {
+ LOG(INFO) << "wait_property(\"" << name << "\", \"" << value << "\"): already set";
+ }
+ return true;
+}
+
void property_changed(const char *name, const char *value)
{
if (property_triggers_enabled)
ActionManager::GetInstance().QueuePropertyTrigger(name, value);
+ if (waiting_for_prop) {
+ if (wait_prop_name == name && wait_prop_value == value) {
+ wait_prop_name.clear();
+ wait_prop_value.clear();
+ LOG(INFO) << "Wait for property took " << *waiting_for_prop;
+ waiting_for_prop.reset();
+ }
+ }
}
static void restart_processes()
@@ -876,7 +904,7 @@ int main(int argc, char** argv) {
am.QueueBuiltinAction(queue_property_triggers_action, "queue_property_triggers");
while (true) {
- if (!waiting_for_exec) {
+ if (!(waiting_for_exec || waiting_for_prop)) {
am.ExecuteOneCommand();
restart_processes();
}