diff options
Diffstat (limited to 'init/init.cpp')
-rw-r--r-- | init/init.cpp | 30 |
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(); } |