Use unique_fd

Also allow the state just before doMount() as a valid state for setting
fuse fd.
Test: manual
BUG:140173712

Change-Id: I012f8a83fef00e68f33010954fbc2ebc53cf8f1d
diff --git a/Utils.cpp b/Utils.cpp
index bd3d452..5e284b2 100644
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -985,7 +985,8 @@
     return true;
 }
 
-int MountUserFuse(userid_t user_id, const std::string& relative_path, int* device_fd) {
+int MountUserFuse(userid_t user_id, const std::string& relative_path,
+                  android::base::unique_fd* fuse_fd) {
     std::string path(StringPrintf("/mnt/user/%d/%s", user_id, relative_path.c_str()));
 
     // Force remove the existing mount before we attempt to prepare the
@@ -1004,9 +1005,9 @@
         return -1;
     }
 
-    // Open device fd.
-    *device_fd = open("/dev/fuse", O_RDWR | O_CLOEXEC);
-    if (*device_fd == -1) {
+    // Open fuse fd.
+    fuse_fd->reset(open("/dev/fuse", O_RDWR | O_CLOEXEC));
+    if (fuse_fd->get() == -1) {
         PLOG(ERROR) << "Failed to open /dev/fuse";
         return -1;
     }
@@ -1018,7 +1019,7 @@
         "rootmode=40000,"
         "allow_other,"
         "user_id=0,group_id=0,",
-        *device_fd);
+        fuse_fd->get());
 
     const int result_int =
         TEMP_FAILURE_RETRY(mount("/dev/fuse", path.c_str(), "fuse",