bytecodealliance / bytecodealliance/wasmtime
How to map and r/w to a fifo file?
- Dominant language
- Rust
- Stars
- 18.6k
- Forks
- 1.8k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 121
Description
I am trying to use a pipe to achieve IPC in wasm. However, it seems like fifo is not mapped as a fifo, and I failed to open it.
I am not sure if the fifo type is supported or if I did it wrong.
Here is how I run it:
```sh
mkfifo /tmp/fifo
ls /tmp/fifo
> |rw-r--r-- - x 2 May 11:42 /tmp/fifo
clang --target=wasm32-wasi --sysroot=/usr/share/wasi-sysroot -o test_fifo.wasm test_fifo.c
wasmtime run --dir=/tmp::/tmp test_fifo.wasm
> /tmp/fifo is not a FIFO
```
```c
// test_fifo.c
#include
#include
#include
#include
#include
#include
#include
int main()
{
const char *fifo_path = "/tmp/fifo";
struct stat st;
if (stat(fifo_path, &st) == -1) {
perror("stat");
exit(EXIT_FAILURE);
}
if (S_ISFIFO(st.st_mode)) {
printf("%s is a FIFO\n", fifo_path);
int fd = open(fifo_path, O_RDONLY);
if (fd == -1) {
perror("open");
exit(EXIT_FAILURE);
}
char buffer[128];
ssize_t bytes_read;
while ((bytes_read = read(fd, buffer, sizeof(buffer) - 1)) > 0) {
buffer[bytes_read] = '\0';
printf("Received: %s\n", buffer);
}
if (bytes_read == -1) {
perror("read");
}
close(fd);
} else {
printf("%s is not a FIFO\n", fifo_path);
}
return 0;
}
```
Contributor guide
Assessment
This issue has not been assessed yet.