Merge pull request #4459 from giuseppe/fix-renameat-definition
rootless: use SYS_renameat2 instead of __NR_renameat2
This commit is contained in:
commit
581a7ec298
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue