Unmount old postinstall mountpoint from previous runs.
When update_engine crashes, is killed or a developer runs
"stop update_engine" while we are waiting for postinstall to finish
the other partition will continue to be mounted (read-only) on the
/postinsall path. This will prevent to mount the new postinstall
step on top of it due to different SELinux labels when mounted and
unmounted. After failing to run postinstall due to the failed mount
operation we would cleanup the mountpoint, so this situation fixes
itself after one failed update attempt, which can then be resumed
from the very end.
This patch attempts to unmount /postinstall if a filesystem is mounted
there at the time we need to use the mountpoint.
Bug: 36391471
Test: Added unittests.
Change-Id: Idffd7a9319715bfb4ab6a9994c6757d27028d40a
diff --git a/common/utils.h b/common/utils.h
index d551b7b..8cccc24 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -192,6 +192,12 @@
const std::string& fs_mount_options);
bool UnmountFilesystem(const std::string& mountpoint);
+// Return whether the passed |mountpoint| path is a directory where a filesystem
+// is mounted. Due to detection mechanism limitations, when used on directories
+// where another part of the tree was bind mounted returns true only if bind
+// mounted on top of a different filesystem (not inside the same filesystem).
+bool IsMountpoint(const std::string& mountpoint);
+
// Returns a human-readable string with the file format based on magic constants
// on the header of the file.
std::string GetFileFormat(const std::string& path);