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:
parent
9370ba160b
commit
eeacc5a297
|
@ -43,6 +43,11 @@ namespace Noux {
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int next_open_fd(int start_fd)
|
||||||
|
{
|
||||||
|
return call<Rpc_next_open_fd>(start_fd);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -137,6 +137,13 @@ namespace Noux {
|
||||||
*/
|
*/
|
||||||
virtual bool syscall(Syscall syscall) = 0;
|
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 **
|
** RPC declaration **
|
||||||
|
@ -144,8 +151,9 @@ namespace Noux {
|
||||||
|
|
||||||
GENODE_RPC(Rpc_sysio_dataspace, Dataspace_capability, sysio_dataspace);
|
GENODE_RPC(Rpc_sysio_dataspace, Dataspace_capability, sysio_dataspace);
|
||||||
GENODE_RPC(Rpc_syscall, bool, syscall, Syscall);
|
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);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -647,22 +647,20 @@ namespace {
|
||||||
|
|
||||||
class Plugin : public Libc::Plugin
|
class Plugin : public Libc::Plugin
|
||||||
{
|
{
|
||||||
private:
|
|
||||||
|
|
||||||
Libc::File_descriptor *_stdin;
|
|
||||||
Libc::File_descriptor *_stdout;
|
|
||||||
Libc::File_descriptor *_stderr;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
Plugin() :
|
Plugin()
|
||||||
_stdin (Libc::file_descriptor_allocator()->alloc(this, noux_context(0), 0)),
|
{
|
||||||
_stdout(Libc::file_descriptor_allocator()->alloc(this, noux_context(1), 1)),
|
/* register inherited open file descriptors */
|
||||||
_stderr(Libc::file_descriptor_allocator()->alloc(this, noux_context(2), 2))
|
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[],
|
bool supports_execve(char const *, char *const[],
|
||||||
char *const[]) { return true; }
|
char *const[]) { return true; }
|
||||||
|
|
|
@ -386,6 +386,15 @@ namespace Noux {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool syscall(Syscall sc);
|
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;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue