libc: late intialization of plugins

- for-each plugin iterator
* Call 'init(Genode::env &)' for each plugin bofore 'Libc::construct' or
'main' is called
This commit is contained in:
Sebastian Sumpf 2017-02-07 10:34:49 +01:00 committed by Norman Feske
parent 549c6db064
commit 643a09b518
3 changed files with 24 additions and 0 deletions

View File

@ -23,11 +23,14 @@
#include <sys/stat.h>
#include <sys/mount.h> /* for 'struct statfs' */
namespace Genode { class Env; }
namespace Libc {
using namespace Genode;
class File_descriptor;
typedef Genode::Path<PATH_MAX> 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);

View File

@ -46,6 +46,15 @@ struct Libc::Plugin_registry : List<Plugin>
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 <typename FUNC>
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_ */

View File

@ -26,6 +26,7 @@
/* libc includes */
#include <libc/component.h>
#include <libc-plugin/plugin_registry.h>
/* libc-internal includes */
#include <internal/call_func.h>
@ -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<Libc::Kernel>(env);
kernel->run();
}