Merge "init: support wait timeout with more precision"

This commit is contained in:
Treehugger Robot 2020-05-18 13:14:36 +00:00 committed by Gerrit Code Review
commit fba5028d56
3 changed files with 10 additions and 6 deletions

View file

@ -644,7 +644,8 @@ provides the `aidl_lazy_test_1` interface.
`wait <path> [ <timeout> ]`
> Poll for the existence of the given file and return when found,
or the timeout has been reached. If timeout is not specified it
currently defaults to five seconds.
currently defaults to five seconds. The timeout value can be
fractional seconds, specified in floating point notation.
`wait_for_prop <name> <value>`
> Wait for system property _name_ to be _value_. Properties are expanded

View file

@ -49,6 +49,7 @@
#include <android-base/chrono_utils.h>
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/parsedouble.h>
#include <android-base/parseint.h>
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
@ -1065,11 +1066,12 @@ static Result<void> do_load_system_props(const BuiltinArguments& args) {
static Result<void> do_wait(const BuiltinArguments& args) {
auto timeout = kCommandRetryTimeout;
if (args.size() == 3) {
int timeout_int;
if (!android::base::ParseInt(args[2], &timeout_int)) {
double timeout_double;
if (!android::base::ParseDouble(args[2], &timeout_double, 0)) {
return Error() << "failed to parse timeout";
}
timeout = std::chrono::seconds(timeout_int);
timeout = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::duration<double>(timeout_double));
}
if (wait_for_file(args[1].c_str(), timeout) != 0) {

View file

@ -25,6 +25,7 @@
#include <sys/time.h>
#include <android-base/logging.h>
#include <android-base/parsedouble.h>
#include <android-base/parseint.h>
#include <android-base/strings.h>
@ -205,8 +206,8 @@ Result<void> check_sysclktz(const BuiltinArguments& args) {
Result<void> check_wait(const BuiltinArguments& args) {
if (args.size() == 3 && !args[2].empty()) {
int timeout_int;
if (!android::base::ParseInt(args[2], &timeout_int)) {
double timeout_double;
if (!android::base::ParseDouble(args[2], &timeout_double, 0)) {
return Error() << "failed to parse timeout";
}
}