Browse Source

Fix the mkfifo call on Linux and add a test to avoid regression

Xavier L'Heureux 5 years ago
parent
commit
30d3cd5c88
5 changed files with 42 additions and 1 deletions
  1. 1 1
      src/platform/linux/mod.rs
  2. 1 0
      tests/Makefile
  3. 0 0
      tests/expected/mkfifo.stderr
  4. 0 0
      tests/expected/mkfifo.stdout
  5. 40 0
      tests/mkfifo.c

+ 1 - 1
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(

+ 1 - 0
tests/Makefile

@@ -15,6 +15,7 @@ EXPECT_NAMES=\
 	libgen \
 	locale \
 	math \
+	mkfifo \
     ptrace \
 	regex \
 	select \

+ 0 - 0
tests/expected/mkfifo.stderr


+ 0 - 0
tests/expected/mkfifo.stdout


+ 40 - 0
tests/mkfifo.c

@@ -0,0 +1,40 @@
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/statvfs.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+
+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);
+  }
+}