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/payload_consumer/postinstall_runner_action.cc b/payload_consumer/postinstall_runner_action.cc
index a1b6f25..11eec34 100644
--- a/payload_consumer/postinstall_runner_action.cc
+++ b/payload_consumer/postinstall_runner_action.cc
@@ -118,6 +118,13 @@
fs_mount_dir_ = temp_dir.value();
#endif // __ANDROID__
+ // Double check that the fs_mount_dir is not busy with a previous mounted
+ // filesystem from a previous crashed postinstall step.
+ if (utils::IsMountpoint(fs_mount_dir_)) {
+ LOG(INFO) << "Found previously mounted filesystem at " << fs_mount_dir_;
+ utils::UnmountFilesystem(fs_mount_dir_);
+ }
+
base::FilePath postinstall_path(partition.postinstall_path);
if (postinstall_path.IsAbsolute()) {
LOG(ERROR) << "Invalid absolute path passed to postinstall, use a relative"