1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 00:08:11 +00:00

Kernel+LibC+UserspaceEmulator: Bring back sys$dup2()

This is racy in userspace and non-racy in kernelspace so let's keep
it in kernelspace.

The behavior change where CLOEXEC is preserved when dup2() is called
with (old_fd == new_fd) was good though, let's keep that.
This commit is contained in:
Andreas Kling 2020-08-15 10:54:00 +02:00
parent bf247fb45f
commit 65f2270232
7 changed files with 59 additions and 14 deletions

View file

@ -415,20 +415,8 @@ int dup(int old_fd)
int dup2(int old_fd, int new_fd)
{
if (new_fd < 0) {
errno = EBADF;
return -1;
}
if (old_fd == new_fd)
return old_fd;
// Validate `old_fd` so we don't close `new_fd` and then fail the `F_DUPFD`.
if (fcntl(old_fd, F_GETFL) < 0)
return -1;
close(new_fd);
return fcntl(old_fd, F_DUPFD, new_fd);
int rc = syscall(SC_dup2, old_fd, new_fd);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int setgroups(size_t size, const gid_t* list)