Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rootless: use SYS_renameat2 instead of __NR_renameat2 #4459

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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