yagehu added the bug label to Issue #7671.
yagehu opened issue #7671:
Not sure this is a bug, but I can't find any previous discussion about this particular case.
Calling
fd_filestat_set_times
with a directory fd, e.g. a preopened directory fd, returnebadf
. I'm aware there is a conformance test that assert certainfd_*
calls should fail with dir fds, but it's not immediately clear to me why this should be the case forfd_filestat_set_times
.I have a simple fix ready to go if folks think it's reasonable to permit this behavior.
Test Case
Adding this snippet to
crates/test-programs/src/bin/preview1_fd_filestat_set.rs
should cause the test to fail.wasi::fd_filestat_set_times( dir_fd, new_mtim.as_nanos() as u64, new_mtim.as_nanos() as u64, wasi::FSTFLAGS_MTIM, ) .expect("fd_filestat_set_times on dirfd");
Steps to Reproduce
With the above snippet,
cargo test -p wasmtime-wasi
.Expected Results
It should be possible to set times on a directory.
Actual Results
fd_filestat_set_times
returnbadf
.Versions and Environment
Wasmtime version or commit:
4f2d634ca4291a09003eaba26f989cd544c1a289
Operating system: Darwin, Fedora 39
Architecture: amd64
Extra Info
Anything else you'd like to add?
yagehu edited issue #7671:
Not sure this is a bug, but I can't find any previous discussion about this particular case.
Calling
fd_filestat_set_times
with a preopened directory fd returnsbadf
. I'm aware there is a conformance test that assert certainfd_*
calls should fail with dir fds, but it's not immediately clear to me why this should be the case forfd_filestat_set_times
and preopened directories.Test Case
#include <dirent.h> #include <fcntl.h> #include <sys/stat.h> #include <stdio.h> #include <string.h> int main() { struct timespec times[2]; times[0].tv_nsec = UTIME_NOW; times[1].tv_nsec = UTIME_NOW; int ret = futimens(3, times); if (ret != 0 ) { perror("futimens"); return 1; } return 0; }
Steps to Reproduce
Compile the snippet with wasi-sdk and run with Wasmtime, preopen a directory.
Expected Results
It should be possible to set times on a directory.
Actual Results
fd_filestat_set_times
returnbadf
.Versions and Environment
Wasmtime version or commit:
4f2d634ca4291a09003eaba26f989cd544c1a289
Operating system: Darwin, Fedora 39
Architecture: amd64
Extra Info
Anything else you'd like to add?
yagehu commented on issue #7671:
This is probably a result of including
O_PATH
when preopening directories: https://github.com/bytecodealliance/cap-std/blob/3663202c6de1bc440764282524a21e14b924925d/cap-primitives/src/rustix/fs/dir_utils.rs#L117
yagehu edited a comment on issue #7671:
This is probably a result of including
O_PATH
when preopening directories: https://github.com/bytecodealliance/cap-std/blob/3663202c6de1bc440764282524a21e14b924925d/cap-primitives/src/rustix/fs/dir_utils.rs#L117EDIT: I just tested.
fd_filestat_set_times
indeed works if we omit theO_PATH
in cap-std.
Last updated: Dec 23 2024 at 12:05 UTC