Skip to content
Snippets Groups Projects
Commit c8074355 authored by Michael Aaron Murphy's avatar Michael Aaron Murphy
Browse files

Merge branch 'background-fix' into 'master'

Fix background jobs that don't request TTY access

See merge request redox-os/ion!779
parents 68980d60 33c3bd66
No related branches found
No related tags found
No related merge requests found
...@@ -13,14 +13,13 @@ pub(crate) fn redir(old: RawFd, new: RawFd) { ...@@ -13,14 +13,13 @@ pub(crate) fn redir(old: RawFd, new: RawFd) {
/// Duplicates STDIN, STDOUT, and STDERR; in that order; and returns them as `File`s. /// Duplicates STDIN, STDOUT, and STDERR; in that order; and returns them as `File`s.
/// Why, you ask? A simple safety mechanism to ensure that the duplicated FDs are closed /// Why, you ask? A simple safety mechanism to ensure that the duplicated FDs are closed
/// when dropped. /// when dropped.
pub(crate) fn duplicate_streams() -> io::Result<(File, File, File)> { pub(crate) fn duplicate_streams() -> io::Result<(Option<File>, File, File)> {
// Duplicates STDIN and converts it into a `File`. // STDIN may have been closed for a background shell, so it is ok if it cannot be duplicated.
sys::dup(sys::STDIN_FILENO).map(|fd| unsafe { File::from_raw_fd(fd) }) let stdin = sys::dup(sys::STDIN_FILENO).ok().map(|fd| unsafe { File::from_raw_fd(fd) });
// Do the same for stdout, and then meld the result with stdin
.and_then(|stdin| sys::dup(sys::STDOUT_FILENO) sys::dup(sys::STDOUT_FILENO)
.map(|fd| unsafe { File::from_raw_fd(fd) }) .map(|fd| unsafe { File::from_raw_fd(fd) })
.map(|stdout| (stdin, stdout)) .map(|stdout| (stdin, stdout))
)
// And then meld stderr alongside stdin and stdout // And then meld stderr alongside stdin and stdout
.and_then(|(stdin, stdout)| sys::dup(sys::STDERR_FILENO) .and_then(|(stdin, stdout)| sys::dup(sys::STDERR_FILENO)
.map(|fd| unsafe { File::from_raw_fd(fd) }) .map(|fd| unsafe { File::from_raw_fd(fd) })
...@@ -28,8 +27,10 @@ pub(crate) fn duplicate_streams() -> io::Result<(File, File, File)> { ...@@ -28,8 +27,10 @@ pub(crate) fn duplicate_streams() -> io::Result<(File, File, File)> {
) )
} }
pub(crate) fn redirect_streams(inp: File, out: File, err: File) { pub(crate) fn redirect_streams(inp: Option<File>, out: File, err: File) {
redir(inp.as_raw_fd(), sys::STDIN_FILENO); if let Some(inp) = inp {
redir(inp.as_raw_fd(), sys::STDIN_FILENO);
}
redir(out.as_raw_fd(), sys::STDOUT_FILENO); redir(out.as_raw_fd(), sys::STDOUT_FILENO);
redir(err.as_raw_fd(), sys::STDERR_FILENO); redir(err.as_raw_fd(), sys::STDERR_FILENO);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment