From 30d3cd5c88039c831db719f553b70767296e15e7 Mon Sep 17 00:00:00 2001 From: Xavier L'Heureux Date: Fri, 13 Sep 2019 12:35:08 -0400 Subject: [PATCH] Fix the mkfifo call on Linux and add a test to avoid regression --- src/platform/linux/mod.rs | 2 +- tests/Makefile | 1 + tests/expected/mkfifo.stderr | 0 tests/expected/mkfifo.stdout | 0 tests/mkfifo.c | 40 ++++++++++++++++++++++++++++++++++++ 5 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/expected/mkfifo.stderr create mode 100644 tests/expected/mkfifo.stdout create mode 100644 tests/mkfifo.c diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs index 52ffa12535..0009bd99a8 100644 --- a/src/platform/linux/mod.rs +++ b/src/platform/linux/mod.rs @@ -287,7 +287,7 @@ impl Pal for Sys { } fn mkfifo(path: &CStr, mode: mode_t) -> c_int { - e(unsafe { syscall!(MKNODAT, AT_FDCWD, path.as_ptr(), mode, 0) }) as c_int + e(unsafe { syscall!(MKNODAT, AT_FDCWD, path.as_ptr(), mode | S_IFIFO, 0) }) as c_int } unsafe fn mmap( diff --git a/tests/Makefile b/tests/Makefile index 4f5e83f67b..9061aa6016 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -15,6 +15,7 @@ EXPECT_NAMES=\ libgen \ locale \ math \ + mkfifo \ ptrace \ regex \ select \ diff --git a/tests/expected/mkfifo.stderr b/tests/expected/mkfifo.stderr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/mkfifo.stdout b/tests/expected/mkfifo.stdout new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/mkfifo.c b/tests/mkfifo.c new file mode 100644 index 0000000000..6fb40ceef3 --- /dev/null +++ b/tests/mkfifo.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char** argv) { + char temp[] = "/tmp/stattest-XXXXXX"; + const char file[] = "/mkfifo_fifo"; + int len = sizeof(temp) + sizeof(file); + char* path = malloc(len * sizeof(char)); + + if (path == NULL) { + fprintf(stderr, "Could not allocate: %s\n", strerror(errno)); + exit(1); + } + + path = strncat(path, mktemp(temp), sizeof(temp)); + path = strncat(path, file, sizeof(file)); + if (mkdir(temp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) { + fprintf(stderr, "mkdir %s: %s\n", temp, strerror(errno)); + exit(1); + } + if (mkfifo(path, S_IRUSR) == -1) { + fprintf(stderr, "mkfifo %s: %s\n", path, strerror(errno)); + exit(1); + } + struct stat sb; + if (stat(path, &sb) != 0) { + fprintf(stderr, "stat: %s\n", strerror(errno)); + exit(1); + } + if (!(sb.st_mode & S_IFIFO)) { + fprintf(stderr, "Not a FIFO: %d\n", sb.st_mode); + exit(1); + } +}