From 0a8dcd7112cdddadebc0af4795e77e3db69bbf26 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Wed, 6 Nov 2019 15:27:44 +0100 Subject: rootless: provide workaround for missing renameat2 on RHEL 7.7 renameat2 is not implemented for s390x, provide a workaround. Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1768519 Signed-off-by: Giuseppe Scrivano --- pkg/rootless/rootless_linux.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/rootless/rootless_linux.c b/pkg/rootless/rootless_linux.c index a29ea0ce1..9604de638 100644 --- a/pkg/rootless/rootless_linux.c +++ b/pkg/rootless/rootless_linux.c @@ -27,9 +27,13 @@ int renameat2 (int olddirfd, const char *oldpath, int newdirfd, const char *newp # ifdef SYS_renameat2 return (int) syscall (SYS_renameat2, olddirfd, oldpath, newdirfd, newpath, flags); # else - /* no way to implement it atomically. */ - errno = ENOSYS; - return -1; + /* This might be an issue if another process is trying to read the file while it is empty. */ + int fd = open (newpath, O_EXCL|O_CREAT, 0700); + if (fd < 0) + return fd; + close (fd); + /* We are sure we created the file, let's overwrite it. */ + return rename (oldpath, newpath); # endif } #endif -- cgit v1.2.3-54-g00ecf