Skip to content

File descriptors created by Rust should be automatically close-on-exec #23233

Closed
@DemiMarie

Description

@DemiMarie

The following code outputs

0
1
2
3
#![feature(old_io)]
#![feature(process)]
#![feature(old_path)]
fn main () {
    use std::old_io::File;
    use std::process::Command;
    let mut file = File::create(&Path::new("message.txt"));
    let _ = file.write_all(b"hello, file!\n");
    let output = Command::new("ls").arg("/dev/fd").output().unwrap();
    let val = output.stdout;
    let _ = ::std::old_io::stdio::stdout().write_all(&val[0..]);
}

This means that Rust is setting the close-on-exec flag for the file descriptor that it created (file descriptor 3 is for the /dev/fd directory). The new io module should that this is also done, and that this is done atomically where possible.

This is mostly a tracking issue to make sure that there is no regression.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions