Open Userzxcvbvnm opened 5 months ago
Technically, this is not a bug. If we take a look at the system call manual for fdatasync
: https://linux.die.net/man/2/fdatasync it states that On some UNIX systems (but not Linux), fd must be a writable file descriptor. WAMR's implementation chosed a rather strict limitation to ensure consistent behavior across different platforms. So if you change the O_RDONLY to O_RDWR or O_WRONLY, everything will be fine
wasi-libc doesn't request DATASYNC rights for O_RDONLY. https://github.com/WebAssembly/wasi-libc/blob/320bbbcced68ce8e564b0dc4c8f80a5a5ad21a9c/libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c#L27-L42
This is what wasmtime and WasmEdge do.
wasmtime removed the most of their implementation of wasi rights while ago.
Subject of the issue
fd_datasync fails. I'm not sure whether this is a bug.
Test case
Your environment
Ubuntu 20.04 x86_64 WAMR 1.3.2
Steps to reproduce
Steps to reproduce: (1)compile to wasm:./wasi-sdk-21.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-21.0/share/wasi-sysroot test.c -o test.wasm
(2)Running wasm: (Before run the Wasm file, subdir_1/subfile_2 exists.) iwasm --dir=. test.wasm
Expected behavior
This is what wasmtime and WasmEdge do.
Actual behavior