diff options
author | Andreas Kling <kling@serenityos.org> | 2020-08-15 10:54:00 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-15 11:11:34 +0200 |
commit | 65f2270232ad4b02af0ed5e02ee63e8dc5ef4c0c (patch) | |
tree | 0510bdf9e8e9c0592c4dfe7c207ea4731f6f7d81 /Libraries/LibC/unistd.cpp | |
parent | bf247fb45f0c21121281609949e5891237721d62 (diff) | |
download | serenity-65f2270232ad4b02af0ed5e02ee63e8dc5ef4c0c.zip |
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.
Diffstat (limited to 'Libraries/LibC/unistd.cpp')
-rw-r--r-- | Libraries/LibC/unistd.cpp | 16 |
1 files changed, 2 insertions, 14 deletions
diff --git a/Libraries/LibC/unistd.cpp b/Libraries/LibC/unistd.cpp index 385aacff46..74299af907 100644 --- a/Libraries/LibC/unistd.cpp +++ b/Libraries/LibC/unistd.cpp @@ -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) |