diff options
author | Elliott Hughes <enh@google.com> | 2016-11-14 21:20:59 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2016-11-14 21:21:00 +0000 |
commit | 601bf9e7c978ce70711adb185a200b6ecb75073e (patch) | |
tree | 3c781d73b1bf7b7ccc484ed4bb82a18de71d4fb6 /init/util.cpp | |
parent | f96e7446fda3be741a10a640b35221bb3d477264 (diff) | |
parent | 9605a945f7a497c0307b512b9cd762f2d23973ca (diff) | |
download | system_core-601bf9e7c978ce70711adb185a200b6ecb75073e.tar.gz system_core-601bf9e7c978ce70711adb185a200b6ecb75073e.tar.bz2 system_core-601bf9e7c978ce70711adb185a200b6ecb75073e.zip |
Merge "init start time tracking."
Diffstat (limited to 'init/util.cpp')
-rw-r--r-- | init/util.cpp | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/init/util.cpp b/init/util.cpp index ff46e4f42..bde4efb62 100644 --- a/init/util.cpp +++ b/init/util.cpp @@ -258,16 +258,11 @@ int write_file(const char* path, const char* content) { return result; } -time_t gettime() { - timespec now; - clock_gettime(CLOCK_MONOTONIC, &now); - return now.tv_sec; -} - -uint64_t gettime_ns() { - timespec now; - clock_gettime(CLOCK_MONOTONIC, &now); - return static_cast<uint64_t>(now.tv_sec) * UINT64_C(1000000000) + now.tv_nsec; +boot_clock::time_point boot_clock::now() { + timespec ts; + clock_gettime(CLOCK_BOOTTIME, &ts); + return boot_clock::time_point(std::chrono::seconds(ts.tv_sec) + + std::chrono::nanoseconds(ts.tv_nsec)); } int mkdir_recursive(const char *pathname, mode_t mode) @@ -325,16 +320,15 @@ void sanitize(char *s) } } -int wait_for_file(const char *filename, int timeout) -{ - struct stat info; - uint64_t timeout_time_ns = gettime_ns() + timeout * UINT64_C(1000000000); - int ret = -1; +int wait_for_file(const char* filename, std::chrono::nanoseconds timeout) { + boot_clock::time_point timeout_time = boot_clock::now() + timeout; + while (boot_clock::now() < timeout_time) { + struct stat sb; + if (stat(filename, &sb) != -1) return 0; - while (gettime_ns() < timeout_time_ns && ((ret = stat(filename, &info)) < 0)) usleep(10000); - - return ret; + } + return -1; } void import_kernel_cmdline(bool in_qemu, |