From a09410cd09b7d84a321053c541d1fcd14b8e7f1a Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Sat, 16 Jul 2016 11:09:55 +0200 Subject: [PATCH] server/chroot: update to new Session_label API Componentize. Fixes #24 --- src/server/chroot/{main.cc => component.cc} | 46 ++++++++++----------- src/server/chroot/target.mk | 4 +- 2 files changed, 24 insertions(+), 26 deletions(-) rename src/server/chroot/{main.cc => component.cc} (81%) diff --git a/src/server/chroot/main.cc b/src/server/chroot/component.cc similarity index 81% rename from src/server/chroot/main.cc rename to src/server/chroot/component.cc index 97172a3..d64e826 100644 --- a/src/server/chroot/main.cc +++ b/src/server/chroot/component.cc @@ -14,14 +14,15 @@ /* Genode includes */ #include #include -#include #include #include #include +#include +#include #include #include #include -#include +#include using namespace Genode; @@ -59,19 +60,23 @@ static void path_from_label(Path &path, char const *label) struct Proxy : Rpc_object> { + Genode::Attached_rom_dataspace _config_rom; Parent_service _parent_service; - Allocator_avl _fs_tx_block_alloc; - File_system::Connection _fs; + Heap _heap; + Allocator_avl _fs_tx_block_alloc { &_heap }; + File_system::Connection _fs { _fs_tx_block_alloc, 1024 }; /** * Constructor */ - Proxy() + Proxy(Genode::Env &env) : + _config_rom(env, "config"), _parent_service("File_system"), - _fs_tx_block_alloc(env()->heap()), - _fs(_fs_tx_block_alloc, 1024) - { } + _heap(env.ram(), env.rm()) + { + env.parent().announce(env.ep().rpc_ep().manage(this)); + } Session_capability chroot(char const *args, char const *path, Affinity const &affinity) { @@ -100,11 +105,11 @@ struct Proxy : Rpc_object> char tmp[MAX_LEN]; Path root_path; - Session_label label(session_args.string()); + Session_label label = label_from_args(session_args.string()); char const *label_str = label.string(); try { - Session_policy policy(label); + Session_policy policy(label, _config_rom.xml()); if (policy.has_attribute("label_prefix") && policy.attribute_value("merge", false)) @@ -126,8 +131,7 @@ struct Proxy : Rpc_object> Arg_string::find_arg(session_args.string(), "root").string( tmp, sizeof(tmp), "/"); - root_path.append(tmp); - + root_path.append_element(tmp); root_path.remove_trailing('/'); char const *args = session_args.string(); @@ -152,7 +156,7 @@ struct Proxy : Rpc_object> throw Root::Unavailable(); } - void upgrade(Session_capability cap, + void upgrade(Session_capability cap, Root::Upgrade_args const &args) override { _parent_service.upgrade(cap, args.string()); } @@ -161,16 +165,10 @@ struct Proxy : Rpc_object> }; -int main(void) -{ - static Cap_connection cap; - static Proxy proxy; +/*************** + ** Component ** + ***************/ - enum { STACK_SIZE = 4096 * 4 }; - static Rpc_entrypoint ep(&cap, STACK_SIZE, "chroot_ep"); +Genode::size_t Component::stack_size() { return 2*1024*sizeof(Genode::addr_t); } - env()->parent()->announce(ep.manage(&proxy)); - - /* let the entrypoint take over */ - sleep_forever(); -} +void Component::construct(Genode::Env &env) { static Proxy inst(env); } diff --git a/src/server/chroot/target.mk b/src/server/chroot/target.mk index 5e423da..7fd2af6 100644 --- a/src/server/chroot/target.mk +++ b/src/server/chroot/target.mk @@ -1,3 +1,3 @@ TARGET = chroot -SRC_CC = main.cc -LIBS = base config \ No newline at end of file +SRC_CC = component.cc +LIBS = base \ No newline at end of file