From ea243a3015edc86428167e97a1ab50c85cf409f2 Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Thu, 21 Jan 2016 12:26:05 +0000 Subject: [PATCH] Unmount emulated filesystems before killing the fuse process. Avoid ENOTCONN for file system operations. bug: 26645585 bug: 26070583 Change-Id: I19b00db37ef7ba85a2cae16c7c4204826653f559 --- EmulatedVolume.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/EmulatedVolume.cpp b/EmulatedVolume.cpp index 230fa8b..581c322 100644 --- a/EmulatedVolume.cpp +++ b/EmulatedVolume.cpp @@ -107,17 +107,21 @@ status_t EmulatedVolume::doMount() { } status_t EmulatedVolume::doUnmount() { + // Unmount the storage before we kill the FUSE process. If we kill + // the FUSE process first, most file system operations will return + // ENOTCONN until the unmount completes. This is an exotic and unusual + // error code and might cause broken behaviour in applications. + KillProcessesUsingPath(getPath()); + ForceUnmount(mFuseDefault); + ForceUnmount(mFuseRead); + ForceUnmount(mFuseWrite); + if (mFusePid > 0) { kill(mFusePid, SIGTERM); TEMP_FAILURE_RETRY(waitpid(mFusePid, nullptr, 0)); mFusePid = 0; } - KillProcessesUsingPath(getPath()); - ForceUnmount(mFuseDefault); - ForceUnmount(mFuseRead); - ForceUnmount(mFuseWrite); - rmdir(mFuseDefault.c_str()); rmdir(mFuseRead.c_str()); rmdir(mFuseWrite.c_str());