Timeout if device isn't mounted.
If the invoked FUSE binary fails to mount the requested filesystem,
the dev_t won't actually change. To avoid getting waiting forever
and triggering the watchdog, timeout after 5 seconds.
Test: manually hang after fork and verify that we timeout
Bug: 65756209
Change-Id: I6ea5fd08ed14c72c1d7f7064bfd0d9ac81d4897b
diff --git a/model/PublicVolume.cpp b/model/PublicVolume.cpp
index 04bafed..6ad2ae1 100644
--- a/model/PublicVolume.cpp
+++ b/model/PublicVolume.cpp
@@ -24,6 +24,7 @@
#include <android-base/logging.h>
#include <cutils/fs.h>
#include <private/android_filesystem_config.h>
+#include <utils/Timers.h>
#include <fcntl.h>
#include <stdlib.h>
@@ -191,9 +192,16 @@
return -errno;
}
+ nsecs_t start = systemTime(SYSTEM_TIME_BOOTTIME);
while (before == GetDevice(mFuseWrite)) {
LOG(VERBOSE) << "Waiting for FUSE to spin up...";
usleep(50000); // 50ms
+
+ nsecs_t now = systemTime(SYSTEM_TIME_BOOTTIME);
+ if (nanoseconds_to_milliseconds(now - start) > 5000) {
+ LOG(WARNING) << "Timed out while waiting for FUSE to spin up";
+ return -ETIMEDOUT;
+ }
}
/* sdcardfs will have exited already. FUSE will still be running */
TEMP_FAILURE_RETRY(waitpid(mFusePid, nullptr, WNOHANG));