From 6432f92e42d902524f1c134ece279494d97d29c8 Mon Sep 17 00:00:00 2001 From: Demin Dmitriy Date: Mon, 11 Nov 2019 01:44:13 +0300 Subject: [PATCH] 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. --- pkgs/build-support/libredirect/libredirect.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkgs/build-support/libredirect/libredirect.c b/pkgs/build-support/libredirect/libredirect.c index 8e8da00b02a..3a8b4b9d509 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);