Skip to content

std::io::process::StdioContainer::Ignored doesn't attach streams to /dev/null with libnative #14456

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

Closed
glandium opened this issue May 27, 2014 · 0 comments · Fixed by #14477
Closed

Comments

@glandium
Copy link
Contributor

Consider the following program:

use std::io::process;
use std::io::process::Command;

fn main() {
    Command::new("ls")
        .args(["-l", "/proc/self/fd"])
        .stdin(process::Ignored)
        .stdout(process::InheritFd(1))
        .stderr(process::Ignored)
        .status()
        .ok();
}

The output with libnative is:

total 0
lr-x------ 1 glandium glandium 64 May 27 20:24 0 -> /proc/31431/fd
lrwx------ 1 glandium glandium 64 May 27 20:24 1 -> /dev/pts/6

IOW, stdin and stderr weren't attached to /dev/null in the subprocess, and whatever open the subprocess did took fd 0, which, in the case of ls, ends up being assigned by opendir() to the directory being listed. Fun failures could follow with processes that use stdin/stdout/stderr.

With rustuv, it looks like the expected result:

total 0
lr-x------ 1 glandium glandium 64 May 27 20:28 0 -> /dev/null
lrwx------ 1 glandium glandium 64 May 27 20:28 1 -> /dev/pts/6
lrwx------ 1 glandium glandium 64 May 27 20:28 2 -> /dev/null
lr-x------ 1 glandium glandium 64 May 27 20:28 3 -> /proc/31466/fd
@huonw huonw added the A-io label May 27, 2014
alexcrichton added a commit to alexcrichton/rust that referenced this issue May 28, 2014
When spawning a process, stdio file descriptors can be configured to be ignored,
which basically means that they'll be closed. Currently this is done by
literally closing the file descriptors in the child, but this can have adverse
side effects if the child process then opens a new file descriptor, assigning it
to a stdio number.

To work around the problems of the child, this commit alters the process
spawning code to map stdio fds to /dev/null on unix (and a similar equivalent on
windows) when they are specified as being ignored. This should allow spawned
programs to have more expected behavior when opening new files.

Closes rust-lang#14456
bors added a commit that referenced this issue May 29, 2014
When spawning a process, stdio file descriptors can be configured to be ignored,
which basically means that they'll be closed. Currently this is done by
literally closing the file descriptors in the child, but this can have adverse
side effects if the child process then opens a new file descriptor, assigning it
to a stdio number.

To work around the problems of the child, this commit alters the process
spawning code to map stdio fds to /dev/null on unix (and a similar equivalent on
windows) when they are specified as being ignored. This should allow spawned
programs to have more expected behavior when opening new files.

Closes #14456
bors added a commit to rust-lang-ci/rust that referenced this issue Jun 5, 2023
Use async block in async fn type inference

fix rust-lang#14456

At some point we should probably go further and completely desugar async fn in hir lowering.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants