Merge "Avoid killing the FUSE daemon during unmount"
diff --git a/Process.cpp b/Process.cpp
index 277d6a3..62d51a2 100644
--- a/Process.cpp
+++ b/Process.cpp
@@ -39,6 +39,7 @@
 #include <android-base/strings.h>
 
 #include "Process.h"
+#include "Utils.h"
 
 using android::base::StringPrintf;
 
@@ -127,7 +128,7 @@
     return pids.size();
 }
 
-int KillProcessesWithOpenFiles(const std::string& prefix, int signal) {
+int KillProcessesWithOpenFiles(const std::string& prefix, int signal, bool killFuseDaemon) {
     std::unordered_set<pid_t> pids;
 
     auto proc_d = std::unique_ptr<DIR, int (*)(DIR*)>(opendir("/proc"), closedir);
@@ -164,7 +165,11 @@
         }
 
         if (found) {
-            pids.insert(pid);
+            if (!IsFuseDaemon(pid) || killFuseDaemon) {
+                pids.insert(pid);
+            } else {
+                LOG(WARNING) << "Found FUSE daemon with open file. Skipping...";
+            }
         }
     }
     if (signal != 0) {
diff --git a/Process.h b/Process.h
index 1c59812..a56b9ce 100644
--- a/Process.h
+++ b/Process.h
@@ -20,7 +20,7 @@
 namespace android {
 namespace vold {
 
-int KillProcessesWithOpenFiles(const std::string& path, int signal);
+int KillProcessesWithOpenFiles(const std::string& path, int signal, bool killFuseDaemon = true);
 int KillProcessesWithMounts(const std::string& path, int signal);
 
 }  // namespace vold
diff --git a/Utils.cpp b/Utils.cpp
index cef0f39..9ff7920 100644
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -525,24 +525,25 @@
 }
 
 status_t KillProcessesUsingPath(const std::string& path) {
-    if (KillProcessesWithOpenFiles(path, SIGINT) == 0) {
+    if (KillProcessesWithOpenFiles(path, SIGINT, false /* killFuseDaemon */) == 0) {
         return OK;
     }
     if (sSleepOnUnmount) sleep(5);
 
-    if (KillProcessesWithOpenFiles(path, SIGTERM) == 0) {
+    if (KillProcessesWithOpenFiles(path, SIGTERM, false /* killFuseDaemon */) == 0) {
         return OK;
     }
     if (sSleepOnUnmount) sleep(5);
 
-    if (KillProcessesWithOpenFiles(path, SIGKILL) == 0) {
+    if (KillProcessesWithOpenFiles(path, SIGKILL, false /* killFuseDaemon */) == 0) {
         return OK;
     }
     if (sSleepOnUnmount) sleep(5);
 
     // Send SIGKILL a second time to determine if we've
     // actually killed everyone with open files
-    if (KillProcessesWithOpenFiles(path, SIGKILL) == 0) {
+    // This time, we also kill the FUSE daemon if found
+    if (KillProcessesWithOpenFiles(path, SIGKILL, true /* killFuseDaemon */) == 0) {
         return OK;
     }
     PLOG(ERROR) << "Failed to kill processes using " << path;