Skip to content

virtio/fs/macos: duplicate fd for fdopendir#540

Closed
slp wants to merge 1 commit intocontainers:mainfrom
slp:fs-macos-fix-opendir
Closed

virtio/fs/macos: duplicate fd for fdopendir#540
slp wants to merge 1 commit intocontainers:mainfrom
slp:fs-macos-fix-opendir

Conversation

@slp
Copy link
Collaborator

@slp slp commented Feb 10, 2026

fdopendir() takes ownership of the fd passed as argument to it, so passing the fd of the HandleData->File will cause the fd to be closed twice, first when closedir() is called and second when Arc is dropped.

If the library is built with debug-assertions enabled, this issue will trigger an error like:

fatal runtime error: IO Safety violation: owned file descriptor already closed, aborting

To avoid this issue, let's use dup() to obtain a new descriptor from HandleData->File to be donated to fdopendir().

Fixes: #539

fdopendir() takes ownership of the fd passed as argument to it, so
passing the fd of the HandleData->File will cause the fd to be closed
twice, first when closedir() is called and second when Arc<HandleData>
is dropped.

If the library is built with debug-assertions enabled, this issue will
trigger an error like:

fatal runtime error: IO Safety violation: owned file descriptor already closed, aborting

To avoid this issue, let's use dup() to obtain a new descriptor from
HandleData->File to be donated to fdopendir().

Fixes: containers#539

Signed-off-by: Sergio Lopez <slp@redhat.com>
@pftbest
Copy link
Contributor

pftbest commented Feb 10, 2026

Checked this PR on my system, the assertion no longer happens, so the change is good. But the ghost files still appear so it is probably a separate issue.

Copy link
Collaborator

@mtjhrc mtjhrc left a comment

Choose a reason for hiding this comment

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

LGTM, good find!

@slp slp marked this pull request as draft February 10, 2026 14:07
@slp
Copy link
Collaborator Author

slp commented Feb 10, 2026

Let's put this one on hold, because I'm preparing another one that fixes both this and the ghost files.

@slp
Copy link
Collaborator Author

slp commented Feb 10, 2026

Superseded by #542

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.

macOS virtio-fs fatal runtime error: IO Safety violation: owned file descriptor already closed, aborting

3 participants