Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Process::spawn with piped stdio on Redox #41353

Merged
merged 1 commit into from
Apr 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/libstd/sys/redox/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,19 +270,22 @@ impl Command {
}

if let Some(fd) = stdio.stderr.fd() {
let _ = syscall::close(2);
t!(cvt(syscall::dup(fd, &[])));
let _ = syscall::close(fd);
t!(cvt(syscall::dup2(fd, 2, &[])));
let mut flags = t!(cvt(syscall::fcntl(2, syscall::F_GETFL, 0)));
flags &= ! syscall::O_CLOEXEC;
t!(cvt(syscall::fcntl(2, syscall::F_SETFL, flags)));
}
if let Some(fd) = stdio.stdout.fd() {
let _ = syscall::close(1);
t!(cvt(syscall::dup(fd, &[])));
let _ = syscall::close(fd);
t!(cvt(syscall::dup2(fd, 1, &[])));
let mut flags = t!(cvt(syscall::fcntl(1, syscall::F_GETFL, 0)));
flags &= ! syscall::O_CLOEXEC;
t!(cvt(syscall::fcntl(1, syscall::F_SETFL, flags)));
}
if let Some(fd) = stdio.stdin.fd() {
let _ = syscall::close(0);
t!(cvt(syscall::dup(fd, &[])));
let _ = syscall::close(fd);
t!(cvt(syscall::dup2(fd, 0, &[])));
let mut flags = t!(cvt(syscall::fcntl(0, syscall::F_GETFL, 0)));
flags &= ! syscall::O_CLOEXEC;
t!(cvt(syscall::fcntl(0, syscall::F_SETFL, flags)));
}

if let Some(g) = self.gid {
Expand Down
5 changes: 5 additions & 0 deletions src/libstd/sys/redox/syscall/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ pub fn dup(fd: usize, buf: &[u8]) -> Result<usize> {
unsafe { syscall3(SYS_DUP, fd, buf.as_ptr() as usize, buf.len()) }
}

/// Copy and transform a file descriptor
pub fn dup2(fd: usize, newfd: usize, buf: &[u8]) -> Result<usize> {
unsafe { syscall4(SYS_DUP2, fd, newfd, buf.as_ptr() as usize, buf.len()) }
}

/// Replace the current process with a new executable
pub fn execve(path: &str, args: &[[usize; 2]]) -> Result<usize> {
unsafe { syscall4(SYS_EXECVE, path.as_ptr() as usize, path.len(),
Expand Down
1 change: 1 addition & 0 deletions src/libstd/sys/redox/syscall/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub const SYS_UNLINK: usize = SYS_CLASS_PATH | 10;

pub const SYS_CLOSE: usize = SYS_CLASS_FILE | 6;
pub const SYS_DUP: usize = SYS_CLASS_FILE | SYS_RET_FILE | 41;
pub const SYS_DUP2: usize = SYS_CLASS_FILE | SYS_RET_FILE | 63;
pub const SYS_READ: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 3;
pub const SYS_WRITE: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 4;
pub const SYS_LSEEK: usize = SYS_CLASS_FILE | 19;
Expand Down