-
Notifications
You must be signed in to change notification settings - Fork 716
unistd: adding linux(glibc)/freebsd close_range. #2525
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
2d8a9de
a09ca4f
78f4ca2
e67aeaa
7c83399
a3ca8a8
6542200
bc14f95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3992,3 +3992,49 @@ pub fn chflags<P: ?Sized + NixPath>(path: &P, flags: FileFlag) -> Result<()> { | |||||
| Errno::result(res).map(drop) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| #[cfg(any( | ||||||
| all(target_os = "linux", target_env = "gnu"), | ||||||
| target_os = "freebsd" | ||||||
| ))] | ||||||
| #[cfg(feature = "fs")] | ||||||
| libc_bitflags! { | ||||||
| /// Options for close_range() | ||||||
| #[cfg_attr(docsrs, doc(cfg(feature = "fs")))] | ||||||
| pub struct CloseRangeFlags : c_uint { | ||||||
| #[cfg(all(target_os = "linux", target_env = "gnu"))] | ||||||
| /// Unshare the file descriptors range before closing them | ||||||
|
||||||
| /// Unshare the file descriptors range before closing them | |
| /// Unshare the file descriptor table, then close the file descriptors specified in the range. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's be explicit:
| /// Set the close-on-exec flag on the file descriptors range | |
| /// Set the close-on-exec flag on the file descriptors range instead of closing them. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am curious why it returns a Result<Option<c_int>>, and the reason behind the code related to Errno. From the man page, it returns -1 on error, and 0 on success, looks like it is just a normal syscall👀
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1391,3 +1391,18 @@ fn test_group_from() { | |
| assert_eq!(group.gid, group_id); | ||
| assert_eq!(group.name, "wheel"); | ||
| } | ||
|
|
||
| #[test] | ||
| #[cfg(any(all(target_os = "linux", target_env = "gnu"), target_os = "freebsd"))] | ||
| fn test_close_range() { | ||
| use tempfile::NamedTempFile; | ||
| const CONTENTS: &[u8] = b"abcdef123456"; | ||
| let mut tempfile1 = NamedTempFile::new().unwrap(); | ||
| let mut tempfile2 = NamedTempFile::new().unwrap(); | ||
| let mut tempfile3 = NamedTempFile::new().unwrap(); | ||
| tempfile3.write_all(CONTENTS).unwrap(); | ||
| tempfile2.write_all(CONTENTS).unwrap(); | ||
| tempfile1.write_all(CONTENTS).unwrap(); | ||
| let areclosed = close_range(tempfile1, tempfile3, CloseRangeFlags::CLOSE_RANGE_CLOEXEC); | ||
|
||
| assert_eq!(areclosed.expect("close_range failed").expect("invalid flag"), 0); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is interesting, libc defines these 2 constants as unsigned integers. 🤔