Skip to content

Commit

Permalink
Merge pull request containers#4459 from giuseppe/fix-renameat-definition
Browse files Browse the repository at this point in the history
rootless: use SYS_renameat2 instead of __NR_renameat2
  • Loading branch information
openshift-merge-robot authored Nov 6, 2019
2 parents 6f7c290 + 0a8dcd7 commit 581a7ec
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pkg/rootless/rootless_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 581a7ec

Please sign in to comment.