You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, once an OwnedFd has been passed to rustix::fs::Dir, there is no way to reuse it.
My usecase is to call rustix::fs::openat() and rustix::fs::statat() on it after I’m done with the iteration (or even during, I don’t think there is any issue with that since getdents64(2) is stateless).
My current solution is to call rustix::io::dup() on the fd before creating the Dir, but that shouldn’t be needed and wastes one fd. Another solution would be to rustix::fs::open() it again once the iteration is done, but that’s wasteful too.
rustix::fs::Dir::read_from has the same issue, it implements dup(2) manually by calling fcntl(4, F_GETFL) then openat(4, ".", …) with 4 being the fd being passed to it.
And since getdents64(2) is stateless, I believe there is no unsoundness issue with e.g. multiple rustix::fs::Dir being created around the same fd.
The text was updated successfully, but these errors were encountered:
The tricky thing here is that rustix is aiming to have the same API across both the libc and linux-raw backends, and in the libc backend, it uses opendir/readdir/closedir. libc doesn't have a way to free a DIR object without closing the fd.
One option might be to have the libc backend implement into_fd by calling dup before calling closedir, however I'm not sure if it's too awkward if into_fd() has to be fallible.
Uh oh!
There was an error while loading. Please reload this page.
Currently, once an
OwnedFd
has been passed torustix::fs::Dir
, there is no way to reuse it.My usecase is to call
rustix::fs::openat()
andrustix::fs::statat()
on it after I’m done with the iteration (or even during, I don’t think there is any issue with that sincegetdents64(2)
is stateless).My current solution is to call
rustix::io::dup()
on the fd before creating theDir
, but that shouldn’t be needed and wastes one fd. Another solution would be torustix::fs::open()
it again once the iteration is done, but that’s wasteful too.rustix::fs::Dir::read_from
has the same issue, it implementsdup(2)
manually by callingfcntl(4, F_GETFL)
thenopenat(4, ".", …)
with 4 being the fd being passed to it.And since
getdents64(2)
is stateless, I believe there is no unsoundness issue with e.g. multiplerustix::fs::Dir
being created around the same fd.The text was updated successfully, but these errors were encountered: