Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

Add syscall dup() for unix target #3707

Merged
merged 2 commits into from
Jul 2, 2024
Merged

Add syscall dup() for unix target #3707

merged 2 commits into from
Jul 2, 2024

Conversation

adwinwhite
Copy link
Contributor

Add support for dup() and dup2().

Fixes #3454

src/shims/unix/fd.rs Outdated Show resolved Hide resolved
Copy link
Member

@RalfJung RalfJung left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

match this.machine.fds.dup(old_fd) {
Some(dup_fd) => {
if new_fd != old_fd {
// Close new_fs if it is previously opened.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Close new_fs if it is previously opened.
// Close new_fs if it is previously opened.
// (If old == new, then `dup_fd` ensure we keep the underlying file description alive.)

// Close new_fs if it is previously opened.
if let Some(file_descriptor) = this.machine.fds.remove(new_fd) {
// Ignore close error according to dup2() doc.
file_descriptor.close(this.machine.communicate()).ok();
Copy link
Member

Choose a reason for hiding this comment

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

Nono, we can never ignore this. This could ignore UB!

You can ignore the Scalar, but the ? that propagates interpreter errors must be present.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally. I didn't distinguish interpreter's error from program's error back then.

file_descriptor.close(this.machine.communicate()).ok();
}

this.machine.fds.fds.insert(new_fd, dup_fd);
Copy link
Member

Choose a reason for hiding this comment

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

insert returns the old value if any, so instead of calling remove first you can just use that.

@RalfJung
Copy link
Member

RalfJung commented Jul 2, 2024

Looks good, thanks a lot :)
@bors r+

@bors
Copy link
Collaborator

bors commented Jul 2, 2024

📌 Commit 71f864d has been approved by RalfJung

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Jul 2, 2024

⌛ Testing commit 71f864d with merge 6dad914...

@bors
Copy link
Collaborator

bors commented Jul 2, 2024

☀️ Test successful - checks-actions
Approved by: RalfJung
Pushing 6dad914 to master...

@bors bors merged commit 6dad914 into rust-lang:master Jul 2, 2024
8 checks passed
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.

dup() not supported
4 participants