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

Clone dirhandles without fchdir #23019

Draft
wants to merge 1 commit into
base: blead
Choose a base branch
from
Draft

Clone dirhandles without fchdir #23019

wants to merge 1 commit into from

Conversation

Leont
Copy link
Contributor

@Leont Leont commented Feb 20, 2025

This is a WIP for fixing #23010 based on @ilmari's suggestion. There currently are two problems with it.

  1. It doesn't have a Configure check yet for fdopendir
  2. t/op/threads-dirh.t fails because it's assuming that the dirhandles in different threads are independent. Given that the same isn't true of filehandles, I think this is the wrong thing to aim at anyway.

@tonycoz
Copy link
Contributor

tonycoz commented Feb 24, 2025

I think it's one reasonable fix, though I think it would be an entry in incompatible changes in perldelta.

I'm not sure it's safe for multiple threads to readdir() from the same underlying fd: It's UB for both parent and child of a fork() to read from their corresponding copies of the DIR, which is the closest case I can think of to this, so I'm not sure this will be thread safe.

From my testing with simple test code, glibc gets confused about the telldir() position for the new handle.

One option might be to openat(orig_dir_fd, ".", O_DIRECTORY | ...) which, assuming no permission change on ., should give us an independent handle, which can be positioned like we do in the current code.

Of course, the simplest option is to just not pass the DIR * into the new interpreter, which resolves the original issue in #10387, but is as backward (in)compatible as this change.

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.

2 participants