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

fs: Use readdir() instead of readdir_r() on Linux and Android #92778

Merged
merged 3 commits into from
Jan 27, 2022

Conversation

tavianator
Copy link
Contributor

@tavianator tavianator commented Jan 11, 2022

See #40021 for more details. Fixes #86649. Fixes #34668.

@rust-highfive
Copy link
Collaborator

r? @joshtriplett

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 11, 2022
@joshtriplett
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jan 11, 2022

📌 Commit ea9181b has been approved by joshtriplett

@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 Jan 11, 2022
@tavianator
Copy link
Contributor Author

Hang on, there's a bug in metadata()

@tavianator tavianator marked this pull request as draft January 11, 2022 20:19
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 11, 2022
…shtriplett

fs: Use readdir() instead of readdir_r() on Linux

readdir() is preferred over readdir_r() on Linux and many other
platforms because it more gracefully supports long file names.  Both
glibc and musl (and presumably all other Linux libc implementations)
guarantee that readdir() is thread-safe as long as a single DIR* is not
accessed concurrently, which is enough to make a readdir()-based
implementation of ReadDir safe.  This implementation is already used for
some other OSes including Fuchsia, Redox, and Solaris.

See rust-lang#40021 for more details.  Fixes rust-lang#86649.
@matthiaskrgr
Copy link
Member

@bors r-

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 11, 2022
@tavianator tavianator marked this pull request as ready for review January 11, 2022 20:40
@tavianator
Copy link
Contributor Author

Okay, should be fixed.

r? @joshtriplett

@joshtriplett
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jan 11, 2022

📌 Commit 4839b81 has been approved by joshtriplett

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 11, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 14, 2022
…shtriplett

fs: Use readdir() instead of readdir_r() on Linux

readdir() is preferred over readdir_r() on Linux and many other
platforms because it more gracefully supports long file names.  Both
glibc and musl (and presumably all other Linux libc implementations)
guarantee that readdir() is thread-safe as long as a single DIR* is not
accessed concurrently, which is enough to make a readdir()-based
implementation of ReadDir safe.  This implementation is already used for
some other OSes including Fuchsia, Redox, and Solaris.

See rust-lang#40021 for more details.  Fixes rust-lang#86649.
@ehuss
Copy link
Contributor

ehuss commented Jan 14, 2022

@bors r-

Failed in rollup: #92878 (comment)

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 14, 2022
@tavianator tavianator changed the title fs: Use readdir() instead of readdir_r() on Linux fs: Use readdir() instead of readdir_r() on Linux and Android Jan 14, 2022
@tavianator
Copy link
Contributor Author

I switched Android over too, and split up the commits a bit. I would test the Android build locally but I have no idea how. Is there documentation for building Rust for Android or should I just try to follow the CI script?

r? @joshtriplett

@ehuss
Copy link
Contributor

ehuss commented Jan 14, 2022

To test android, it needs the NDK. There is a script here for getting it, but I would just use the docker image. That can be done with src/ci/docker/run.sh dist-android. There is documentation at https://rustc-dev-guide.rust-lang.org/tests/intro.html#testing-with-docker-images for testing with docker.

@tavianator
Copy link
Contributor Author

Thanks! I ran the library tests in that Docker image and they passed.

@bors
Copy link
Contributor

bors commented Jan 20, 2022

☔ The latest upstream changes (presumably #93119) made this pull request unmergeable. Please resolve the merge conflicts.

readdir() is preferred over readdir_r() on Linux and many other
platforms because it more gracefully supports long file names.  Both
glibc and musl (and presumably all other Linux libc implementations)
guarantee that readdir() is thread-safe as long as a single DIR* is not
accessed concurrently, which is enough to make a readdir()-based
implementation of ReadDir safe.  This implementation is already used for
some other OSes including Fuchsia, Redox, and Solaris.

See rust-lang#40021 for more details.  Fixes rust-lang#86649.  Fixes rust-lang#34668.
Bionic also guarantees that readdir() is thread-safe enough.
@tavianator
Copy link
Contributor Author

Rebased! Linux and Android tests still pass

@tavianator
Copy link
Contributor Author

@rustbot label -S-waiting-on-author +S-waiting-on-review

@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 Jan 26, 2022
@joshtriplett
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jan 26, 2022

📌 Commit 3eeb3ca has been approved by joshtriplett

@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 Jan 26, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 26, 2022
…askrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#90247 (Improve Duration::try_from_secs_f32/64 accuracy by directly processing exponent and mantissa)
 - rust-lang#91861 (Replace iterator-based construction of collections by `Into<T>`)
 - rust-lang#92098 (add OpenBSD platform-support page)
 - rust-lang#92134 (Add x86_64-pc-windows-msvc linker-plugin-lto instructions)
 - rust-lang#92256 (Improve selection errors for `~const` trait bounds)
 - rust-lang#92778 (fs: Use readdir() instead of readdir_r() on Linux and Android)
 - rust-lang#93338 (Update minifier crate version to 0.0.42)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 253f64c into rust-lang:master Jan 27, 2022
@rustbot rustbot added this to the 1.60.0 milestone Jan 27, 2022
@tavianator tavianator deleted the linux-readdir-no-r branch January 27, 2022 20:24
bors pushed a commit to rust-lang-ci/rust that referenced this pull request Dec 18, 2022
Bug rust-lang#50619 was fixed by adding an end_of_stream flag in rust-lang#50630.
Unfortunately, that fix only applied to the readdir_r() path.  When I
switched Linux to use readdir() in rust-lang#92778, I inadvertently reintroduced
the bug on that platform.  Other platforms that had always used
readdir() were presumably never fixed.

This patch enables end_of_stream for all platforms, and adds a
Linux-specific regression test that should hopefully prevent the bug
from being reintroduced again.
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 18, 2022
…imulacrum

fs: Fix rust-lang#50619 (again) and add a regression test

Bug rust-lang#50619 was fixed by adding an end_of_stream flag in rust-lang#50630.
Unfortunately, that fix only applied to the readdir_r() path.  When I
switched Linux to use readdir() in rust-lang#92778, I inadvertently reintroduced
the bug on that platform.  Other platforms that had always used
readdir() were presumably never fixed.

This patch enables end_of_stream for all platforms, and adds a
Linux-specific regression test that should hopefully prevent the bug
from being reintroduced again.
Aaron1011 pushed a commit to Aaron1011/rust that referenced this pull request Jan 6, 2023
…imulacrum

fs: Fix rust-lang#50619 (again) and add a regression test

Bug rust-lang#50619 was fixed by adding an end_of_stream flag in rust-lang#50630.
Unfortunately, that fix only applied to the readdir_r() path.  When I
switched Linux to use readdir() in rust-lang#92778, I inadvertently reintroduced
the bug on that platform.  Other platforms that had always used
readdir() were presumably never fixed.

This patch enables end_of_stream for all platforms, and adds a
Linux-specific regression test that should hopefully prevent the bug
from being reintroduced again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
7 participants