Merge "Fix signedness mismatch and integer underflow"
diff --git a/Utils.cpp b/Utils.cpp
index c0b7f01..3bbdf3a 100644
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -297,29 +297,25 @@
                     security_context_t context) {
     auto argv = ConvertToArgv(args);
 
-    int fd[2];
-    if (pipe2(fd, O_CLOEXEC) != 0) {
-        PLOG(ERROR) << "pipe2 in ForkExecvp";
+    android::base::unique_fd pipe_read, pipe_write;
+    if (!android::base::Pipe(&pipe_read, &pipe_write)) {
+        PLOG(ERROR) << "Pipe in ForkExecvp";
         return -errno;
     }
-    android::base::unique_fd pipe_read(fd[0]);
-    android::base::unique_fd pipe_write(fd[1]);
 
     pid_t pid = fork();
     if (pid == 0) {
         if (context) {
             if (setexeccon(context)) {
-                LOG(ERROR) << "Failed to setexeccon";
+                LOG(ERROR) << "Failed to setexeccon in ForkExecvp";
                 abort();
             }
         }
         pipe_read.reset();
-        if (pipe_write.get() != STDOUT_FILENO) {
-            dup2(pipe_write.get(), STDOUT_FILENO);
-            pipe_write.reset();
-        }
+        dup2(pipe_write.get(), STDOUT_FILENO);
+        pipe_write.reset();
         execvp(argv[0], const_cast<char**>(argv.data()));
-        PLOG(ERROR) << "Failed to exec";
+        PLOG(ERROR) << "exec in ForkExecvp";
         _exit(EXIT_FAILURE);
     }
     if (pid == -1) {
@@ -755,29 +751,10 @@
 }
 
 status_t UnmountTree(const std::string& prefix) {
-    FILE* fp = setmntent("/proc/mounts", "re");
-    if (fp == NULL) {
-        PLOG(ERROR) << "Failed to open /proc/mounts";
+    if (umount2(prefix.c_str(), MNT_DETACH)) {
+        PLOG(ERROR) << "Failed to unmount " << prefix;
         return -errno;
     }
-
-    // Some volumes can be stacked on each other, so force unmount in
-    // reverse order to give us the best chance of success.
-    std::list<std::string> toUnmount;
-    mntent* mentry;
-    while ((mentry = getmntent(fp)) != NULL) {
-        auto test = std::string(mentry->mnt_dir) + "/";
-        if (android::base::StartsWith(test, prefix)) {
-            toUnmount.push_front(test);
-        }
-    }
-    endmntent(fp);
-
-    for (const auto& path : toUnmount) {
-        if (umount2(path.c_str(), MNT_DETACH)) {
-            PLOG(ERROR) << "Failed to unmount " << path;
-        }
-    }
     return OK;
 }