From 8f372b469a0cf1c8576cb78d4cfe33f3fac66e46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Fri, 9 Nov 2012 17:39:30 +0100 Subject: [PATCH] Noux: fix dup() in libc_noux The previous implementation disregards the fact that we actually have to use libc's plugin mechanism if we play with fds. So in the end the libc did not know to which plugin the fd belonged. Fixes #493. --- ports/src/lib/libc_noux/plugin.cc | 32 +++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/ports/src/lib/libc_noux/plugin.cc b/ports/src/lib/libc_noux/plugin.cc index e5480e4a67..693087592f 100644 --- a/ports/src/lib/libc_noux/plugin.cc +++ b/ports/src/lib/libc_noux/plugin.cc @@ -176,20 +176,6 @@ extern "C" uid_t geteuid() } -extern "C" int dup(int ofd) -{ - sysio()->dup2_in.fd = ofd; - sysio()->dup2_in.to_fd = -1; - - if (!noux()->syscall(Noux::Session::SYSCALL_DUP2)) { - errno = EINVAL; - return -1; - } - - return sysio()->dup2_out.fd; -} - - /** * Utility to copy-out syscall results to buf struct * @@ -616,6 +602,7 @@ namespace { Libc::File_descriptor *open(char const *, int); ssize_t write(Libc::File_descriptor *, const void *, ::size_t); int close(Libc::File_descriptor *); + Libc::File_descriptor *dup(Libc::File_descriptor*); int dup2(Libc::File_descriptor *, Libc::File_descriptor *); int execve(char const *filename, char *const argv[], char *const envp[]); @@ -1025,6 +1012,23 @@ namespace { } + Libc::File_descriptor *Plugin::dup(Libc::File_descriptor* fd) + { + sysio()->dup2_in.fd = noux_fd(fd->context); + sysio()->dup2_in.to_fd = -1; + + if (!noux()->syscall(Noux::Session::SYSCALL_DUP2)) { + PERR("dup error"); + /* XXX set errno */ + return 0; + } + + Libc::Plugin_context *context = noux_context(sysio()->dup2_out.fd); + return Libc::file_descriptor_allocator()->alloc(this, context, + sysio()->dup2_out.fd); + } + + int Plugin::dup2(Libc::File_descriptor *fd, Libc::File_descriptor *new_fd) { /*