Merge "Clean up use of pipe" am: a33b765ca0
am: 1ca8af7bad

Change-Id: I24f4e15728a0b9127753d544b8df5d3aecd8a9f5
diff --git a/Utils.cpp b/Utils.cpp
index c0b7f01..f72edbe 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) {