Noux: register inherited file descriptors

With this patch, a Noux process registers all inherited open file
descriptors in its local libc file descriptor registry at program start.

Fixes #882.
This commit is contained in:
Christian Prochaska 2013-09-06 21:10:23 +02:00 committed by Norman Feske
parent 9370ba160b
commit eeacc5a297
4 changed files with 32 additions and 12 deletions

View File

@ -43,6 +43,11 @@ namespace Noux {
return result;
}
int next_open_fd(int start_fd)
{
return call<Rpc_next_open_fd>(start_fd);
}
};
}

View File

@ -137,6 +137,13 @@ namespace Noux {
*/
virtual bool syscall(Syscall syscall) = 0;
/*
* Return the next open file descriptor, starting from (and including)
* 'start_fd'.
*
* \return the next open file descriptor or -1
*/
virtual int next_open_fd(int start_fd) = 0;
/*********************
** RPC declaration **
@ -144,8 +151,9 @@ namespace Noux {
GENODE_RPC(Rpc_sysio_dataspace, Dataspace_capability, sysio_dataspace);
GENODE_RPC(Rpc_syscall, bool, syscall, Syscall);
GENODE_RPC(Rpc_next_open_fd, int, next_open_fd, int);
GENODE_RPC_INTERFACE(Rpc_sysio_dataspace, Rpc_syscall);
GENODE_RPC_INTERFACE(Rpc_sysio_dataspace, Rpc_syscall, Rpc_next_open_fd);
};
}

View File

@ -647,22 +647,20 @@ namespace {
class Plugin : public Libc::Plugin
{
private:
Libc::File_descriptor *_stdin;
Libc::File_descriptor *_stdout;
Libc::File_descriptor *_stderr;
public:
/**
* Constructor
*/
Plugin() :
_stdin (Libc::file_descriptor_allocator()->alloc(this, noux_context(0), 0)),
_stdout(Libc::file_descriptor_allocator()->alloc(this, noux_context(1), 1)),
_stderr(Libc::file_descriptor_allocator()->alloc(this, noux_context(2), 2))
{ }
Plugin()
{
/* register inherited open file descriptors */
int fd = 0;
while ((fd = noux()->next_open_fd(fd)) != -1) {
Libc::file_descriptor_allocator()->alloc(this, noux_context(fd), fd);
fd++;
}
}
bool supports_execve(char const *, char *const[],
char *const[]) { return true; }

View File

@ -386,6 +386,15 @@ namespace Noux {
}
bool syscall(Syscall sc);
int next_open_fd(int start_fd)
{
if (start_fd >= 0)
for (int fd = start_fd; fd < MAX_FILE_DESCRIPTORS; fd++)
if (fd_in_use(fd))
return fd;
return -1;
}
};
};