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
diff --git a/init/builtins.cpp b/init/builtins.cpp
index 1186e9d..965a81f 100644
--- a/init/builtins.cpp
+++ b/init/builtins.cpp
@@ -1003,6 +1003,29 @@
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 @@
{"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;