summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-11-06 16:28:46 +0100
committerGitHub <noreply@github.com>2019-11-06 16:28:46 +0100
commit581a7ec2984c2c125ff255c9aca62f2547c7d46f (patch)
tree49e98d2e47210e63f087f737f9ba3f6dfaff119c
parent6f7c290f70dc42dc33dd65a8a6a42b08e83caae5 (diff)
parent0a8dcd7112cdddadebc0af4795e77e3db69bbf26 (diff)
downloadpodman-581a7ec2984c2c125ff255c9aca62f2547c7d46f.tar.gz
podman-581a7ec2984c2c125ff255c9aca62f2547c7d46f.tar.bz2
podman-581a7ec2984c2c125ff255c9aca62f2547c7d46f.zip
Merge pull request #4459 from giuseppe/fix-renameat-definition
rootless: use SYS_renameat2 instead of __NR_renameat2
-rw-r--r--pkg/rootless/rootless_linux.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/pkg/rootless/rootless_linux.c b/pkg/rootless/rootless_linux.c
index 94933ddd0..9604de638 100644
--- a/pkg/rootless/rootless_linux.c
+++ b/pkg/rootless/rootless_linux.c
@@ -24,12 +24,16 @@
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;
- 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