diff --git a/ports/include/noux_session/client.h b/ports/include/noux_session/client.h index 27310c8ad..3844a90fd 100644 --- a/ports/include/noux_session/client.h +++ b/ports/include/noux_session/client.h @@ -43,6 +43,11 @@ namespace Noux { return result; } + + int next_open_fd(int start_fd) + { + return call(start_fd); + } }; } diff --git a/ports/include/noux_session/noux_session.h b/ports/include/noux_session/noux_session.h index 14d33698a..7698eb0f1 100644 --- a/ports/include/noux_session/noux_session.h +++ b/ports/include/noux_session/noux_session.h @@ -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); }; } diff --git a/ports/src/lib/libc_noux/plugin.cc b/ports/src/lib/libc_noux/plugin.cc index 85aeb7f5c..e9bddefc0 100644 --- a/ports/src/lib/libc_noux/plugin.cc +++ b/ports/src/lib/libc_noux/plugin.cc @@ -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; } diff --git a/ports/src/noux/child.h b/ports/src/noux/child.h index 5fc6a6445..a41271d2f 100644 --- a/ports/src/noux/child.h +++ b/ports/src/noux/child.h @@ -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; + } }; };