about summary refs log tree commit diff
path: root/pkgs/build-support/libredirect
diff options
context:
space:
mode:
authorDemin Dmitriy <demindf@gmail.com>2019-11-11 01:44:13 +0300
committerDemin Dmitriy <demindf@gmail.com>2019-11-12 04:29:11 +0300
commit6432f92e42d902524f1c134ece279494d97d29c8 (patch)
tree8d889da18778323ccf43c6114affef288a8fedaa /pkgs/build-support/libredirect
parentda9b3ea747cf413880f300bc8426b4e5ec1447f6 (diff)
libredirect: fix argument forwarding in open* functions
Flag `O_TMPFILE` was added in Linux 3.11. It affects whether or not
`mode` argument should be passed.
Diffstat (limited to 'pkgs/build-support/libredirect')
-rw-r--r--pkgs/build-support/libredirect/libredirect.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/pkgs/build-support/libredirect/libredirect.c b/pkgs/build-support/libredirect/libredirect.c
index 8e8da00b02a21..3a8b4b9d509f3 100644
--- a/pkgs/build-support/libredirect/libredirect.c
+++ b/pkgs/build-support/libredirect/libredirect.c
@@ -59,6 +59,11 @@ static const char * rewrite(const char * path, char * buf)
     return path;
 }
 
+static int open_needs_mode(int flags)
+{
+    return (flags & O_CREAT) || (flags & O_TMPFILE) == O_TMPFILE;
+}
+
 /* The following set of Glibc library functions is very incomplete -
    it contains only what we needed for programs in Nixpkgs. Just add
    more functions as needed. */
@@ -67,7 +72,7 @@ int open(const char * path, int flags, ...)
 {
     int (*open_real) (const char *, int, mode_t) = dlsym(RTLD_NEXT, "open");
     mode_t mode = 0;
-    if (flags & O_CREAT) {
+    if (open_needs_mode(flags)) {
         va_list ap;
         va_start(ap, flags);
         mode = va_arg(ap, mode_t);
@@ -81,7 +86,7 @@ int open64(const char * path, int flags, ...)
 {
     int (*open64_real) (const char *, int, mode_t) = dlsym(RTLD_NEXT, "open64");
     mode_t mode = 0;
-    if (flags & O_CREAT) {
+    if (open_needs_mode(flags)) {
         va_list ap;
         va_start(ap, flags);
         mode = va_arg(ap, mode_t);
@@ -95,7 +100,7 @@ int openat(int dirfd, const char * path, int flags, ...)
 {
     int (*openat_real) (int, const char *, int, mode_t) = dlsym(RTLD_NEXT, "openat");
     mode_t mode = 0;
-    if (flags & O_CREAT) {
+    if (open_needs_mode(flags)) {
         va_list ap;
         va_start(ap, flags);
         mode = va_arg(ap, mode_t);