-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Impl new API std::os::unix::fs::mkfifo
under feature unix_fifo
#139450
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?
Conversation
This comment has been minimized.
This comment has been minimized.
/// # }; | ||
/// # fn main() -> std::io::Result<()> { | ||
/// # remove_file("/tmp/fifo")?; | ||
/// mkfifo("/tmp/fifo", Permissions::from_mode(0o774))?; |
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.
If this test is to be run (I think it's a good idea to have some form of test), it may be better to call mkdtemp
and create the FIFO there to ensure it doesn't interfere with anyone who actually has a /tmp/fifo
.
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'm not sure if we can use libc::mktemp
here...honestly maybe we should also add a function for that
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.
Agreed, it would be nice to have. libc
isn't available but the binding is pretty easy, the setup is a bit clunky but I think it's worth avoiding any possible issues
/// # // Use a temporary file to avoid conflicts or cleanup issues
/// # extern "C" { fn mktemp(template: *mut c_char) -> *mut c_char; }
/// # let mut buf = b"rust-fifo-XXXXXX\0";
/// # let fname = unsafe {
/// # let ptr = mktemp(buf.as_ptr().cast::<c_char>()) };
/// # assert!(!ptr.is_null(), "could not create tempfile");
/// # CStr::from_ptr(ptr).to_str().unwrap()
/// # };
/// mkfifo(fname, Permissions::from_mode(0o774))?;
/// // ...
The rest LGTM
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.
My problem with this is portability, not sure if it would work on musl, and probably android and other libc reliably.
If we want to do this, might be easier to random generate the filename using std::random
?
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.
Fair point. We have tempfile for the std testsuite, maybe just make the doc example no_run and then add the actual test there?
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.
Yeah that makes more sense, I would do that
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 see this was made no_run but it doesn't look like a test wasn't added. If you don't have it yet, just copy+paste this example to std/src/os/unix/fs/tests.rs using a file name from crate_helpers::tmpdir().join("fifo")
.
@rustbot author for the failing test and review |
Reminder, once the PR becomes ready for a review, use |
71bfad0
to
68fa5cc
Compare
I really have no idea why this fails on x86_64-unknown-linux-gnu, I added the new function for all unix target, but somehow it's missing on linux... |
This comment has been minimized.
This comment has been minimized.
68fa5cc
to
5e8b43b
Compare
This comment has been minimized.
This comment has been minimized.
5e8b43b
to
c55e152
Compare
This comment has been minimized.
This comment has been minimized.
c55e152
to
88e10a3
Compare
This comment has been minimized.
This comment has been minimized.
88e10a3
to
9200a12
Compare
@rustbot ready |
Tracking issue rust-lang#139324 Signed-off-by: Jiahao XU <[email protected]>
9200a12
to
331e311
Compare
Tracking issue #139324