提交 e195aa84 编写于 作者: B bors

Auto merge of #27971 - tbu-:pr_cloexec, r=alexcrichton

On Linux the flag is just ignored if it is not supported:
https://lwn.net/Articles/588444/

Still needs the values of O_CLOEXEC on the BSDs.

Touches #24237.
......@@ -102,6 +102,7 @@
pub use consts::os::c95::*;
pub use consts::os::posix88::*;
pub use consts::os::posix01::*;
pub use consts::os::posix08::*;
pub use consts::os::bsd44::*;
pub use consts::os::extra::*;
......@@ -3611,6 +3612,8 @@ pub mod posix01 {
pub const RUSAGE_THREAD: c_int = 1;
}
pub mod posix08 {
use types::os::arch::c95::c_int;
pub const O_CLOEXEC: c_int = 0x80000;
}
#[cfg(any(target_arch = "arm",
target_arch = "aarch64",
......@@ -4270,7 +4273,15 @@ pub mod posix01 {
pub const RUSAGE_CHILDREN: c_int = -1;
pub const RUSAGE_THREAD: c_int = 1;
}
#[cfg(target_os = "freebsd")]
pub mod posix08 {
use types::os::arch::c95::c_int;
pub const O_CLOEXEC: c_int = 0x100000;
}
#[cfg(target_os = "dragonfly")]
pub mod posix08 {
use types::os::arch::c95::c_int;
pub const O_CLOEXEC: c_int = 0x20000;
}
pub mod bsd44 {
use types::os::arch::c95::c_int;
......@@ -4713,7 +4724,15 @@ pub mod posix01 {
pub const RUSAGE_CHILDREN: c_int = -1;
pub const RUSAGE_THREAD: c_int = 1;
}
#[cfg(any(target_os = "bitrig", target_os = "openbsd"))]
pub mod posix08 {
use types::os::arch::c95::c_int;
pub const O_CLOEXEC: c_int = 0x10000;
}
#[cfg(target_os = "netbsd")]
pub mod posix08 {
use types::os::arch::c95::c_int;
pub const O_CLOEXEC: c_int = 0x400000;
}
pub mod bsd44 {
use types::os::arch::c95::c_int;
......@@ -5151,6 +5170,8 @@ pub mod posix01 {
pub const RUSAGE_THREAD: c_int = 1;
}
pub mod posix08 {
use types::os::arch::c95::c_int;
pub const O_CLOEXEC: c_int = 0x1000000;
}
pub mod bsd44 {
use types::os::arch::c95::c_int;
......
......@@ -212,7 +212,7 @@ fn dirent(&self) -> *mut libc::dirent_t {
impl OpenOptions {
pub fn new() -> OpenOptions {
OpenOptions {
flags: 0,
flags: libc::O_CLOEXEC,
read: false,
write: false,
mode: 0o666,
......@@ -269,6 +269,9 @@ pub fn open_c(path: &CStr, opts: &OpenOptions) -> io::Result<File> {
libc::open(path.as_ptr(), flags, opts.mode)
}));
let fd = FileDesc::new(fd);
// Even though we open with the O_CLOEXEC flag, still set CLOEXEC here,
// in case the open flag is not supported (it's just ignored by the OS
// in that case).
fd.set_cloexec();
Ok(File(fd))
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册