Clean up use of pipe

Don't duplicate what's already in unique_fd.h
Also, code that tries to handle weird stdout condition won't work
because of cloexec; just don't try that.

My tests:
- Ensure Marlin device boots and vold_prepare_subdirs is called
successfully
- Try adb shell sm set-virtual-disk true, see that eg sgdisk output is
logged.

Bug: 26735063
Bug: 113796163
Test: details in commit
Change-Id: I5698ba0b4c8bd692a740a1bd445e677ad4815d11
gugelfrei
Paul Crowley 6 years ago
parent 6aaedb0dca
commit e6d7663889

@ -297,29 +297,25 @@ status_t ForkExecvp(const std::vector<std::string>& args, std::vector<std::strin
security_context_t context) { security_context_t context) {
auto argv = ConvertToArgv(args); auto argv = ConvertToArgv(args);
int fd[2]; android::base::unique_fd pipe_read, pipe_write;
if (pipe2(fd, O_CLOEXEC) != 0) { if (!android::base::Pipe(&pipe_read, &pipe_write)) {
PLOG(ERROR) << "pipe2 in ForkExecvp"; PLOG(ERROR) << "Pipe in ForkExecvp";
return -errno; return -errno;
} }
android::base::unique_fd pipe_read(fd[0]);
android::base::unique_fd pipe_write(fd[1]);
pid_t pid = fork(); pid_t pid = fork();
if (pid == 0) { if (pid == 0) {
if (context) { if (context) {
if (setexeccon(context)) { if (setexeccon(context)) {
LOG(ERROR) << "Failed to setexeccon"; LOG(ERROR) << "Failed to setexeccon in ForkExecvp";
abort(); abort();
} }
} }
pipe_read.reset(); pipe_read.reset();
if (pipe_write.get() != STDOUT_FILENO) { dup2(pipe_write.get(), STDOUT_FILENO);
dup2(pipe_write.get(), STDOUT_FILENO); pipe_write.reset();
pipe_write.reset();
}
execvp(argv[0], const_cast<char**>(argv.data())); execvp(argv[0], const_cast<char**>(argv.data()));
PLOG(ERROR) << "Failed to exec"; PLOG(ERROR) << "exec in ForkExecvp";
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
} }
if (pid == -1) { if (pid == -1) {

Loading…
Cancel
Save