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) {
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) {

Loading…
Cancel
Save