From a114e9059a660ffab9f61f49d826b1809abd77b8 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Wed, 6 Nov 2019 13:41:12 +0100 Subject: rootless: use SYS_renameat2 instead of __NR_renameat2 use the correct definition for the syscall number. Signed-off-by: Giuseppe Scrivano --- pkg/rootless/rootless_linux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pkg/rootless/rootless_linux.c') diff --git a/pkg/rootless/rootless_linux.c b/pkg/rootless/rootless_linux.c index 94933ddd0..a29ea0ce1 100644 --- a/pkg/rootless/rootless_linux.c +++ b/pkg/rootless/rootless_linux.c @@ -24,8 +24,8 @@ int renameat2 (int olddirfd, const char *oldpath, int newdirfd, const char *newpath, unsigned int flags) { -# ifdef __NR_renameat2 - return (int) syscall (__NR_renameat2, olddirfd, oldpath, newdirfd, newpath, flags); +# ifdef SYS_renameat2 + return (int) syscall (SYS_renameat2, olddirfd, oldpath, newdirfd, newpath, flags); # else /* no way to implement it atomically. */ errno = ENOSYS; -- cgit v1.2.3-54-g00ecf 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(-) (limited to 'pkg/rootless/rootless_linux.c') 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