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

Merged
merged 1 commit into from
Apr 24, 2025

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
Tracking issue rust-lang#139324

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
@NobodyXu NobodyXu force-pushed the new-api/make-fifo branch from 331e311 to 780f95d Compare April 23, 2025 13:03
@tgross35
Copy link
Contributor

Looks great, thanks!

@tgross35
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Apr 24, 2025

📌 Commit 780f95d has been approved by tgross35

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 24, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 24, 2025
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#134446 (Stabilize the `cell_update` feature)
 - rust-lang#139307 (std: Add performance warnings to HashMap::get_disjoint_mut)
 - rust-lang#139450 (Impl new API `std::os::unix::fs::mkfifo` under feature `unix_fifo`)
 - rust-lang#139809 (Don't warn about `v128` in wasm ABI transition)
 - rust-lang#139852 (StableMIR: Implement `CompilerInterface`)
 - rust-lang#139945 (Extend HIR to track the source and syntax of a lifetime)
 - rust-lang#140028 (`deref_patterns`: support string and byte string literals in explicit `deref!("...")` patterns)
 - rust-lang#140181 (Remove `synstructure::Structure::underscore_const` calls.)
 - rust-lang#140232 (Remove unnecessary clones)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 10732e1 into rust-lang:master Apr 24, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone Apr 24, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 24, 2025
Rollup merge of rust-lang#139450 - NobodyXu:new-api/make-fifo, r=tgross35

Impl new API `std::os::unix::fs::mkfifo` under feature `unix_fifo`

Tracking issue rust-lang#139324
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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

5 participants