diff --git a/repos/libports/include/libc-plugin/plugin.h b/repos/libports/include/libc-plugin/plugin.h index c1b6b6b70e..8ed89c2d18 100644 --- a/repos/libports/include/libc-plugin/plugin.h +++ b/repos/libports/include/libc-plugin/plugin.h @@ -23,11 +23,14 @@ #include #include /* for 'struct statfs' */ +namespace Genode { class Env; } + namespace Libc { using namespace Genode; class File_descriptor; + typedef Genode::Path Absolute_path; @@ -70,6 +73,11 @@ namespace Libc { virtual bool supports_unlink(const char *path); virtual bool supports_mmap(); + /* + * Should be overwritten for plugins that require the Genode environment + */ + virtual void init(Genode::Env &env) { } + virtual File_descriptor *accept(File_descriptor *, struct ::sockaddr *addr, socklen_t *addrlen); diff --git a/repos/libports/include/libc-plugin/plugin_registry.h b/repos/libports/include/libc-plugin/plugin_registry.h index f1257c3d44..6185f54320 100644 --- a/repos/libports/include/libc-plugin/plugin_registry.h +++ b/repos/libports/include/libc-plugin/plugin_registry.h @@ -46,6 +46,15 @@ struct Libc::Plugin_registry : List Plugin *get_plugin_for_stat(const char *path, struct stat *); Plugin *get_plugin_for_symlink(const char *oldpath, const char *newpath); Plugin *get_plugin_for_unlink(const char *path); + + template + void for_each_plugin(FUNC const &fn) const + { + for (Plugin *plugin = plugin_registry()->first(); plugin; + plugin = plugin->next()) { + fn(*plugin); + } + } }; #endif /* _LIBC_PLUGIN__PLUGIN_REGISTRY_H_ */ diff --git a/repos/libports/src/lib/libc/task.cc b/repos/libports/src/lib/libc/task.cc index 0eef86a12e..38c6077944 100644 --- a/repos/libports/src/lib/libc/task.cc +++ b/repos/libports/src/lib/libc/task.cc @@ -26,6 +26,7 @@ /* libc includes */ #include +#include /* libc-internal includes */ #include @@ -656,6 +657,12 @@ void Component::construct(Genode::Env &env) Libc::init_mem_alloc(env); Libc::init_dl(env); + /* initialize plugins that require Genode::Env */ + auto init_plugin = [&] (Libc::Plugin &plugin) { + plugin.init(env); + }; + Libc::plugin_registry()->for_each_plugin(init_plugin); + kernel = unmanaged_singleton(env); kernel->run(); }