From cf3989ac79665f8097f44a1a99895f754cc606e2 Mon Sep 17 00:00:00 2001 From: benrubson Date: Thu, 29 Mar 2018 17:27:57 +0200 Subject: [PATCH] Retry Apple & Cygwin unmount --- encfs/FileUtils.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/encfs/FileUtils.cpp b/encfs/FileUtils.cpp index ca3db78d..7b08e3f8 100644 --- a/encfs/FileUtils.cpp +++ b/encfs/FileUtils.cpp @@ -1737,15 +1737,27 @@ void unmountFS(const char *mountPoint) { fuse_unmount(mountPoint, nullptr); #ifdef __APPLE__ // fuse_unmount does not work on Mac OS, see #428 - unmount(mountPoint, MNT_FORCE); + int ret = 3; + while (ret-- > 0) { + if (unmount(mountPoint, MNT_FORCE) == 0) { + break; + } + } #endif #ifdef __CYGWIN__ - if(fork() == 0) - { - execl("/usr/bin/pkill", "/usr/bin/pkill", "-f", string("(^|/)encfs .*/.* ").append(mountPoint).append("?( |$)").c_str(), (char *)0); - } + int ret = 3; + pid_t pid; int status; - wait(&status); + while (ret-- > 0) { + if ((pid = fork()) == 0) { + execl("/usr/bin/pkill", "/usr/bin/pkill", "-INT", "-f", string("(^|/)encfs .*/.* ").append(mountPoint).append("?( |$)").c_str(), (char *)0); + _Exit(127); + } + // pkill returns 1 if no process has been found + if ((pid > 0) && (waitpid(pid, &status, 0) > 0) && WIFEXITED(status) && (WEXITSTATUS(status) == 1)) { + break; + } + } #endif }