diff options
author | Andreas Kling <awesomekling@gmail.com> | 2018-11-16 22:14:40 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2018-11-16 22:14:40 +0100 |
commit | 2cf477a1512a1ca3f0571cb6de42b7a89a3a4565 (patch) | |
tree | 00dac1b645aa32bc3ece2e26ab314da43b38f553 /Kernel | |
parent | 6cedb8815380a1f6000fb4a1fed74afa6c32117f (diff) | |
download | serenity-2cf477a1512a1ca3f0571cb6de42b7a89a3a4565.zip |
Add fcntl() F_DUPFD which is slightly different from dup2().
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/Process.cpp | 16 | ||||
-rwxr-xr-x | Kernel/sync.sh | 5 |
2 files changed, 21 insertions, 0 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 892e2228de..29a63cb669 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -1090,6 +1090,22 @@ int Process::sys$fcntl(int fd, int cmd, dword arg) // NOTE: The FD flags are not shared between FileDescriptor objects. // This means that dup() doesn't copy the FD_CLOEXEC flag! switch (cmd) { + case F_DUPFD: { + int arg_fd = (int)arg; + if (arg_fd < 0) + return -EINVAL; + int new_fd = -1; + for (int i = arg_fd; i < (int)m_max_open_file_descriptors; ++i) { + if (!m_fds[i]) { + new_fd = i; + break; + } + } + if (new_fd == -1) + return -EMFILE; + m_fds[new_fd].set(descriptor); + break; + } case F_GETFD: return m_fds[fd].flags; case F_SETFD: diff --git a/Kernel/sync.sh b/Kernel/sync.sh index f7a313fc10..37fc24edbc 100755 --- a/Kernel/sync.sh +++ b/Kernel/sync.sh @@ -3,6 +3,11 @@ rm -vf _fs_contents cp -vp _fs_contents.stock _fs_contents mkdir -vp mnt mount -o loop _fs_contents mnt/ +mkdir -vp mnt/dev +mknod mnt/dev/tty0 c 4 0 +mknod mnt/dev/tty1 c 4 1 +mknod mnt/dev/tty2 c 4 2 +mknod mnt/dev/tty3 c 4 3 cp -R ../Base/* mnt/ cp -v ../Userland/sh mnt/bin/sh cp -v ../Userland/id mnt/bin/id |