Open
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:
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
// test_fifo.c
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
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;
}
Metadata
Metadata
Assignees
Labels
No labels