Added default feature `default-cloexec`: If this feature is set, file-descriptors will be created with the close-on-exec flag (`MFD_CLOEXEC` for memfds, `FD_CLOEXEC` for other pseudofiles and `O_CLOEXEC` for `open()` calls.)

This is a temporary means of adding cloexec configuration to the crate, the interface is not modified and unless the default feature is not selected ABI-compat will remain the same. NOTE: This is intended to be removed on the next interface-changing update.

Fortune for mapped-file's current commit: Future curse − 末凶
master
Avril 3 months ago
parent 5d4c9b57f7
commit 8fcd1929a4
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -2,7 +2,7 @@
name = "mapped-file"
description = "Construct a memory mapping over any file object"
keywords = ["unix", "mmap", "generic", "file", "fd"]
version = "0.0.8"
version = "0.0.8-r1"
edition = "2021"
repository="https://github.com/notflan/mapped-file"
license="MIT"
@ -10,10 +10,18 @@ license="MIT"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["default-cloexec"]
# Add support for file-descriptor operations other than simply mapping
# TODO: XXX: Incomplete, will be enabled by default when complete
file=[]
# Default to opening any internal file-descriptors as `O_CLOEXEC` (close-on-execute.)
# For `file` feature: `MFD_CLOEXEC`/`FD_CLOEXEC` will be used in creation of all memfds by default.
#
# NOTE: This is currently not configureable within the interface. To prevent API-break, this feature exists to allow some configuration of this option. (TODO: In the future, this should be in the interface for `MemoryFile`/`NamedMemoryFile` et al.)
default-cloexec = []
[dependencies]
lazy_static = "1.4.0"
libc = "0.2.132"

@ -28,7 +28,7 @@ static UNNAMED: &'static CStr = unsafe {
CStr::from_bytes_with_nul_unchecked(b"<unnamed memory file>\0")
};
const DEFAULT_FLAGS: c_uint = MFD_CLOEXEC;
const DEFAULT_FLAGS: c_uint = if cfg!(feature="default-cloexec") { MFD_CLOEXEC } else { 0 };
#[inline(always)]
//XXX: Is the static bound required here?
@ -235,3 +235,14 @@ impl From<MemoryFile> for std::fs::File
}
raw::impl_io_for_fd!(MemoryFile => .0.as_raw_fd());
#[cfg(test)]
mod test {
#[test]
fn default_flag_cloexec_visible()
{
println!("Default flags: {} (default-cloexec: {})", super::DEFAULT_FLAGS, cfg!(feature="default-cloexec"));
assert_eq!(super::DEFAULT_FLAGS, cfg!(feature="default-cloexec").then(|| super::MFD_CLOEXEC).unwrap_or_default(), "Compile-time default creation flags are not in accordance with provided global crate configuration");
}
}

Loading…
Cancel
Save