summaryrefslogtreecommitdiff
path: root/init/builtins.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/builtins.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/builtins.cpp')
-rw-r--r--init/builtins.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/init/builtins.cpp b/init/builtins.cpp
index 1186e9db9..965a81fbe 100644
--- a/init/builtins.cpp
+++ b/init/builtins.cpp
@@ -1003,6 +1003,29 @@ static int do_wait(const std::vector<std::string>& args) {
return -1;
}
+static int do_wait_for_prop(const std::vector<std::string>& args) {
+ const char* name = args[1].c_str();
+ const char* value = args[2].c_str();
+ size_t value_len = strlen(value);
+
+ if (!is_legal_property_name(name)) {
+ LOG(ERROR) << "do_wait_for_prop(\"" << name << "\", \"" << value
+ << "\") failed: bad name";
+ return -1;
+ }
+ if (value_len >= PROP_VALUE_MAX) {
+ LOG(ERROR) << "do_wait_for_prop(\"" << name << "\", \"" << value
+ << "\") failed: value too long";
+ return -1;
+ }
+ if (!wait_property(name, value)) {
+ LOG(ERROR) << "do_wait_for_prop(\"" << name << "\", \"" << value
+ << "\") failed: init already in waiting";
+ return -1;
+ }
+ return 0;
+}
+
/*
* Callback to make a directory from the ext4 code
*/
@@ -1074,6 +1097,7 @@ BuiltinFunctionMap::Map& BuiltinFunctionMap::map() const {
{"verity_load_state", {0, 0, do_verity_load_state}},
{"verity_update_state", {0, 0, do_verity_update_state}},
{"wait", {1, 2, do_wait}},
+ {"wait_for_prop", {2, 2, do_wait_for_prop}},
{"write", {2, 2, do_write}},
};
return builtin_functions;