Use MNT_DETACH when unmounting appfuse mount.
The system server requests unmount for appfuse when all opened file on
appfuse are closed. However the kernel sometimes returns EBUSY for
umount2 if it's just after closing all FDs on the mount point. To avoid
the case, specify MNT_DETACH to unmount.
Bug: 33363856
Test: mount and unmount appfuse repeatedly and see if unmount succeed.
Change-Id: I802e1c048357cc445febf3b95341999463a0ec65
diff --git a/CommandListener.cpp b/CommandListener.cpp
index a312af2..36249e7 100644
--- a/CommandListener.cpp
+++ b/CommandListener.cpp
@@ -749,7 +749,13 @@
if (command == "mount") {
_exit(mountInNamespace(uid, device_fd, path));
} else if (command == "unmount") {
- android::vold::ForceUnmount(path);
+ // If it's just after all FD opened on mount point are closed, umount2 can fail with
+ // EBUSY. To avoid the case, specify MNT_DETACH.
+ if (umount2(path.c_str(), UMOUNT_NOFOLLOW | MNT_DETACH) != 0 &&
+ errno != EINVAL && errno != ENOENT) {
+ PLOG(ERROR) << "Failed to unmount directory.";
+ _exit(-errno);
+ }
_exit(android::OK);
} else {
LOG(ERROR) << "Unknown appfuse command " << command;