utilities: fixup infinite wait in waiting for path
The function to wait for a path to exist never exited if the path
did not exist. Fix that to have a proper timeout, and make the
timeout accurate.
Tested:
put on an nvl32-obmc and tested with a path that doesn't
exist
```
root@nvl32-obmc:~# ./platform init nvidia-nvl32
waiting for /sys/bus/i2c-300 to exist
Failed to wait for /sys/bus/i2c-300 to exist
```
Change-Id: Ibf083a2ecd5d1b1b0a29644767c87086139682ec
Signed-off-by: Marc Olberding <molberding@nvidia.com>
diff --git a/utilities.cpp b/utilities.cpp
index e27ceb3..cadaa84 100644
--- a/utilities.cpp
+++ b/utilities.cpp
@@ -21,6 +21,9 @@
void wait_for_path_to_exist(std::string_view path,
std::chrono::milliseconds timeout)
{
+ auto now = std::chrono::steady_clock::now();
+ auto end = now + timeout;
+ std::cerr << std::format("waiting for {} to exist\n", path);
while (true)
{
std::error_code ec;
@@ -29,8 +32,13 @@
{
return;
}
- sleep_milliseconds(1ms);
- timeout -= 1ms;
+ std::this_thread::sleep_for(1ms);
+
+ now = std::chrono::steady_clock::now();
+ if (now > end)
+ {
+ break;
+ }
}
- std::cerr << std::format("Failed to wait for {} to exist", path);
+ std::cerr << std::format("Failed to wait for {} to exist\n", path);
}