Skip to content

Don't ignore errors of syscalls in std::sys::unix::fd - #34441

Merged
bors merged 2 commits into
rust-lang:masterfrom
tbu-:pr_dont_ignore_errors
Jun 25, 2016
Merged

Don't ignore errors of syscalls in std::sys::unix::fd#34441
bors merged 2 commits into
rust-lang:masterfrom
tbu-:pr_dont_ignore_errors

Conversation

@tbu-

@tbu- tbu- commented Jun 23, 2016

Copy link
Copy Markdown
Contributor

If any of these syscalls fail, it indicates a programmer error that
should not be silently ignored.

If any of these syscalls fail, it indicates a programmer error that
should not be silently ignored.
@rust-highfive

Copy link
Copy Markdown
Contributor

r? @brson

(rust_highfive has picked a reviewer for you, use r? to override)

@tbu-

tbu- commented Jun 23, 2016

Copy link
Copy Markdown
Contributor Author

These syscalls can essentially only fail if an invalid file descriptor is passed to them.

@brson

brson commented Jun 23, 2016

Copy link
Copy Markdown
Contributor

It's not obvious to me that it's possible for these to return errors. Do you have scenarios in mind where these won't return 0? Edit: I see you mentioned they only fail when passed invalid descriptors.

(I'm not clear on how exposed to user code these are. Are these just internal implementation details or can people use them to call cloexec on arbitrary file descriptors?)

Even if it's not supposed to be possible for these to return errors it may be prudent to convert these to assert! anyway - I'd sure like to know if somebody does hit an error here, and this isn't a fast path since we've just made a syscall.

@brson

brson commented Jun 23, 2016

Copy link
Copy Markdown
Contributor

cc @alexcrichton

@alexcrichton

Copy link
Copy Markdown
Member

If we actually check for errors here then seems like we should actually punt up the error, that's what we have Result for. These were added in a time where we didn't support construction from arbitrary file descriptors, so it didn't make sense to even check for an error here. It's pretty rare to even find C code that checks for errors against functions like this.

@retep998

Copy link
Copy Markdown
Contributor

It's pretty rare to even find C code that checks for errors against functions like this.

I don't think we should base Rust's error handling on the dangerous footgun that is C.

There are a few cases where system function errors are being ignored on Windows too. If any way is thought up to allow Result to be punted up, then it should probably apply to Windows as well.

@tbu-

tbu- commented Jun 24, 2016

Copy link
Copy Markdown
Contributor Author

Now the errors a bubbled up instead of being checked locally.

@alexcrichton

Copy link
Copy Markdown
Member

@bors: r+ 9347ffc

bors added a commit that referenced this pull request Jun 25, 2016
Don't ignore errors of syscalls in std::sys::unix::fd

If any of these syscalls fail, it indicates a programmer error that
should not be silently ignored.
@bors

bors commented Jun 25, 2016

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 9347ffc with merge c128e9b...

@bors
bors merged commit 9347ffc into rust-lang:master Jun 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants