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.
This commit is contained in:
Josef Söntgen 2012-11-09 17:39:30 +01:00 committed by Norman Feske
parent d5a758ea10
commit 8f372b469a

View File

@ -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 * Utility to copy-out syscall results to buf struct
* *
@ -616,6 +602,7 @@ namespace {
Libc::File_descriptor *open(char const *, int); Libc::File_descriptor *open(char const *, int);
ssize_t write(Libc::File_descriptor *, const void *, ::size_t); ssize_t write(Libc::File_descriptor *, const void *, ::size_t);
int close(Libc::File_descriptor *); int close(Libc::File_descriptor *);
Libc::File_descriptor *dup(Libc::File_descriptor*);
int dup2(Libc::File_descriptor *, Libc::File_descriptor *); int dup2(Libc::File_descriptor *, Libc::File_descriptor *);
int execve(char const *filename, char *const argv[], int execve(char const *filename, char *const argv[],
char *const envp[]); 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) int Plugin::dup2(Libc::File_descriptor *fd, Libc::File_descriptor *new_fd)
{ {
/* /*