Skip to content

Fix check of statx and handle EPERM - #65685

Merged
bors merged 2 commits into
rust-lang:masterfrom
oxalica:statx-eperm
Oct 25, 2019
Merged

Fix check of statx and handle EPERM#65685
bors merged 2 commits into
rust-lang:masterfrom
oxalica:statx-eperm

Conversation

@oxalica

Copy link
Copy Markdown
Contributor

Should fix#65662

#65662 (comment)

I think a reasonable solution might be to do something like try to stat AT_CWD initially and if that fails with EPERM or ENOSYS we disable the syscall entirely, otherwise it's cached as always good to use.

r? @alexcrichton

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 22, 2019
@lnicola

Copy link
Copy Markdown
Member

I suppose a micro-optimization would be to only do the AT_CWD check if it fails for the argument, but maybe it's not worth it.

@alexcrichtonalexcrichton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great to me, thanks again for helping to handle this @oxalica!

.err()
.and_then(|e| e.raw_os_error());
// `seccomp` will emit `EPERM` on denied syscall.
// See: https://github.com/rust-lang/rust/issues/65662

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could this expand the comment inline to explain why EPERM is handled specially and why we attempt to stat a "known good" location, along with the pitfalls of this could still return a false negative?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

... along with the pitfalls of this could still return a false negative?

Will it? The manual said it never returns EPERM. So it should be the only case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps! I've come to not trust man pages on errors though, they basically never describe the exhaustive set of errors, only some possible ones.

Comment threadsrc/libstd/sys/unix/fs.rs Outdated
Comment threadsrc/libstd/sys/unix/fs.rs Outdated
_ => {
let mut buf: libc::statx = mem::zeroed();
if let Err(err) = cvt(statx(fd, path, flags, mask, &mut buf)) {
return Some(Err(err));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Although not part of this PR, it might be nice to change this to return io::Result<Option<FileAttr>> to use ? here instead of if let

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

To be honest, Ok(None) for "unavailable" seems weird to me...
Option<Result<T>> is for the syscall may be unavailable, or available with a result.

Changing the type does not simplify much more code. Instead, we need an extra ? after every calls below.

Comment threadsrc/libstd/sys/unix/fs.rs Outdated
@rust-highfive

Copy link
Copy Markdown
Contributor

Your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-10-22T19:53:44.6812391Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-10-22T19:53:44.7000920Z ##[command]git config gc.auto 0
2019-10-22T19:53:44.7081513Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-10-22T19:53:44.7140390Z ##[command]git config --get-all http.proxy
2019-10-22T19:53:45.5040678Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/65685/merge:refs/remotes/pull/65685/merge

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@alexcrichton

Copy link
Copy Markdown
Member

@bors: r+

Looks good to me!

@bors

bors commented Oct 22, 2019

Copy link
Copy Markdown
Collaborator

📌 Commit 10f1bc7 has been approved by alexcrichton

@bors

bors commented Oct 22, 2019

Copy link
Copy Markdown
Collaborator

🌲 The tree is currently closed for pull requests below priority 1000, this pull request will be tested once the tree is reopened

@borsbors 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 Oct 22, 2019
Centril added a commit to Centril/rust that referenced this pull request Oct 25, 2019
Fix check of `statx` and handle EPERM
Should fixrust-lang#65662rust-lang#65662 (comment)
> I think a reasonable solution might be to do something like try to stat AT_CWD initially and if that fails with EPERM or ENOSYS we disable the syscall entirely, otherwise it's cached as always good to use.
r? @alexcrichton
@CentrilCentril mentioned this pull request Oct 25, 2019
Centril added a commit to Centril/rust that referenced this pull request Oct 25, 2019
Fix check of `statx` and handle EPERM
Should fixrust-lang#65662rust-lang#65662 (comment)
> I think a reasonable solution might be to do something like try to stat AT_CWD initially and if that fails with EPERM or ENOSYS we disable the syscall entirely, otherwise it's cached as always good to use.
r? @alexcrichton
@CentrilCentril mentioned this pull request Oct 25, 2019
bors added a commit that referenced this pull request Oct 25, 2019
Rollup of 9 pull requests
Successful merges:
- #64639 (Stabilize `#[non_exhaustive]` (RFC 2008))
- #65074 (Fix the start/end byte positions in the compiler JSON output)
- #65315 (Intern place projection)
- #65685 (Fix check of `statx` and handle EPERM)
- #65731 (Prevent unnecessary allocation in PathBuf::set_extension.)
- #65740 (Fix default "disable-shortcuts" feature value)
- #65787 (move panictry! to where it is used.)
- #65789 (move Attribute::with_desugared_doc to librustdoc)
- #65790 (move report_invalid_macro_expansion_item to item.rs)
Failed merges:
r? @ghost
@bors
bors merged commit 10f1bc7 into rust-lang:masterOct 25, 2019
@oxalica
oxalica deleted the statx-eperm branch January 1, 2020 12:12
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler doesn't work when using Docker

5 participants

@oxalica@lnicola@rust-highfive@alexcrichton@bors