Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

NobodyXu
Copy link
Contributor

@NobodyXu NobodyXu commented Apr 6, 2025

Tracking issue #139324

@rustbot
Copy link
Collaborator

rustbot commented Apr 6, 2025

r? @tgross35

rustbot has assigned @tgross35.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added O-unix Operating system: Unix-like S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 6, 2025
@rust-log-analyzer

This comment has been minimized.

/// # };
/// # fn main() -> std::io::Result<()> {
/// # remove_file("/tmp/fifo")?;
/// mkfifo("/tmp/fifo", Permissions::from_mode(0o774))?;
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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").

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I put it in std/tests/mkfifo.rs and forgot to git add it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tgross35 I have updated std/src/os/unix/fs/tests.rs

@tgross35
Copy link
Contributor

tgross35 commented Apr 8, 2025

@rustbot author for the failing test and review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 8, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 8, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@NobodyXu NobodyXu force-pushed the new-api/make-fifo branch from 71bfad0 to 68fa5cc Compare April 9, 2025 14:55
@NobodyXu
Copy link
Contributor Author

NobodyXu commented Apr 9, 2025

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...

@rust-log-analyzer

This comment has been minimized.

@NobodyXu NobodyXu force-pushed the new-api/make-fifo branch from 68fa5cc to 5e8b43b Compare April 12, 2025 14:24
@rust-log-analyzer

This comment has been minimized.

@NobodyXu NobodyXu force-pushed the new-api/make-fifo branch from 5e8b43b to c55e152 Compare April 13, 2025 13:56
@rust-log-analyzer

This comment has been minimized.

@NobodyXu NobodyXu force-pushed the new-api/make-fifo branch from c55e152 to 88e10a3 Compare April 15, 2025 09:12
@rust-log-analyzer

This comment has been minimized.

@NobodyXu NobodyXu force-pushed the new-api/make-fifo branch from 88e10a3 to 9200a12 Compare April 15, 2025 09:43
@NobodyXu
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 15, 2025
@NobodyXu NobodyXu force-pushed the new-api/make-fifo branch from 9200a12 to 331e311 Compare April 22, 2025 15:03
@NobodyXu NobodyXu force-pushed the new-api/make-fifo branch from 331e311 to 780f95d Compare April 23, 2025 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-unix Operating system: Unix-like S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants