Skip to content
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

What does "before-main stdio file descriptors are not guaranteed to be open on unix platforms" mean? #137490

Closed
nabijaczleweli opened this issue Feb 23, 2025 · 3 comments · Fixed by #137492
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@nabijaczleweli
Copy link
Contributor

nabijaczleweli commented Feb 23, 2025

Location

library/std/src/lib.rs, module-level rustdoc

  • before-main stdio file descriptors are not guaranteed to be open on unix platforms

Summary

What does this mean? I'm assuming this was supposed to be "before main, " since file descriptors are a property of the process at all times, but even then... this implies that fd0/1/2 may be... closed? between exec returning and the runtime calling main? and then become open somehow? on main entry? I don't believe there to be any UNIX system ever in history where this is true?

@nabijaczleweli nabijaczleweli added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Feb 23, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 23, 2025
@nabijaczleweli
Copy link
Contributor Author

I don't see this discussed in #115247 or #110708 or #110897 where this language originates, so I don't know what it's trying to say.

@zopsicle
Copy link
Contributor

this implies that fd0/1/2 may be... closed?

close(0);
close(1);
close(2);
exec("a-rust-program");

and then become open somehow?

// The standard streams might be closed on application startup. To prevent
// std::io::{stdin, stdout,stderr} objects from using other unrelated file
// resources opened later, we reopen standards streams when they are closed.
sanitize_standard_fds();

@nabijaczleweli
Copy link
Contributor Author

Thanks, this indicates what this should say instead.

nabijaczleweli added a commit to nabijaczleweli/rust that referenced this issue Feb 23, 2025
@jieyouxu jieyouxu added T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 23, 2025
jieyouxu added a commit to jieyouxu/rust that referenced this issue Mar 16, 2025
libstd: rustdoc: correct note on fds 0/1/2 pre-main

Closes: rust-lang#137490
@bors bors closed this as completed in 74ec862 Mar 16, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 16, 2025
Rollup merge of rust-lang#137492 - nabijaczleweli:master, r=thomcc

libstd: rustdoc: correct note on fds 0/1/2 pre-main

Closes: rust-lang#137490
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this issue Mar 19, 2025
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this issue Mar 19, 2025
libstd: rustdoc: correct note on fds 0/1/2 pre-main

Closes: rust-lang#137490
tautschnig pushed a commit to model-checking/verify-rust-std that referenced this issue Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants