From db2b1a37aee3258823ea0cd9a82f2943c6232a74 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Thu, 11 Oct 2012 20:57:10 +0200 Subject: [PATCH] Propagate process labels to PD sessions On Linux, we use the session label for naming the corresponding Linux process. When looking up the processes via 'ps', the Genode process hierarchy becomes immediately visible. --- base-linux/include/linux_pd_session/client.h | 4 ++-- .../linux_pd_session/linux_pd_session.h | 6 ++---- base-linux/src/base/process/process.cc | 5 +++-- .../src/core/include/pd_session_component.h | 5 ++++- base-linux/src/core/pd_session_component.cc | 20 +++++++++++++------ .../include/okl4_pd_session/connection.h | 13 ++---------- base/include/pd_session/connection.h | 10 +++------- base/src/base/process/process.cc | 3 ++- 8 files changed, 32 insertions(+), 34 deletions(-) diff --git a/base-linux/include/linux_pd_session/client.h b/base-linux/include/linux_pd_session/client.h index 9b8bb44015..f8a7e8e16b 100644 --- a/base-linux/include/linux_pd_session/client.h +++ b/base-linux/include/linux_pd_session/client.h @@ -35,8 +35,8 @@ namespace Genode { * Linux-specific extension ** *****************************/ - void start(Capability binary, Name const &name) { - call(binary, name); } + void start(Capability binary) { + call(binary); } }; } diff --git a/base-linux/include/linux_pd_session/linux_pd_session.h b/base-linux/include/linux_pd_session/linux_pd_session.h index 42b8a05178..ed5272781e 100644 --- a/base-linux/include/linux_pd_session/linux_pd_session.h +++ b/base-linux/include/linux_pd_session/linux_pd_session.h @@ -21,16 +21,14 @@ namespace Genode { struct Linux_pd_session : Pd_session { - typedef Rpc_in_buffer<64> Name; - - void start(Capability binary, Name const &name); + void start(Capability binary); /********************* ** RPC declaration ** *********************/ - GENODE_RPC(Rpc_start, void, start, Capability, Name const &); + GENODE_RPC(Rpc_start, void, start, Capability); GENODE_RPC_INTERFACE_INHERIT(Pd_session, Rpc_start); }; } diff --git a/base-linux/src/base/process/process.cc b/base-linux/src/base/process/process.cc index d63f9cb86e..f3064c1662 100644 --- a/base-linux/src/base/process/process.cc +++ b/base-linux/src/base/process/process.cc @@ -57,9 +57,10 @@ Process::Process(Dataspace_capability elf_data_ds_cap, Cpu_session_capability cpu_session_cap, Rm_session_capability rm_session_cap, Parent_capability parent_cap, - const char *name, + char const *name, char *const argv[]) : + _pd(name), _cpu_session_client(Cpu_session_capability()), _rm_session_client(Rm_session_capability()) { @@ -75,7 +76,7 @@ Process::Process(Dataspace_capability elf_data_ds_cap, Linux_pd_session_client lx_pd(static_cap_cast(_pd.cap())); lx_pd.assign_parent(parent_cap); - lx_pd.start(elf_data_ds_cap, name); + lx_pd.start(elf_data_ds_cap); } diff --git a/base-linux/src/core/include/pd_session_component.h b/base-linux/src/core/include/pd_session_component.h index 616b2b9f3d..ac81753c17 100644 --- a/base-linux/src/core/include/pd_session_component.h +++ b/base-linux/src/core/include/pd_session_component.h @@ -27,7 +27,10 @@ namespace Genode { { private: + enum { LABEL_MAX_LEN = 1024 }; + unsigned long _pid; + char _label[LABEL_MAX_LEN]; Parent_capability _parent; Rpc_entrypoint *_ds_ep; @@ -55,7 +58,7 @@ namespace Genode { ** Linux-specific extension ** ******************************/ - void start(Capability binary, Name const &name); + void start(Capability binary); }; } diff --git a/base-linux/src/core/pd_session_component.cc b/base-linux/src/core/pd_session_component.cc index bf4c2edc2b..7eb619f3ad 100644 --- a/base-linux/src/core/pd_session_component.cc +++ b/base-linux/src/core/pd_session_component.cc @@ -12,6 +12,7 @@ */ /* Genode includes */ +#include #include #include @@ -78,8 +79,13 @@ static const char *get_env(const char *key) ** PD session interface ** **************************/ -Pd_session_component::Pd_session_component(Rpc_entrypoint *ds_ep, const char *) -: _pid(0), _ds_ep(ds_ep) { } +Pd_session_component::Pd_session_component(Rpc_entrypoint *ep, const char *args) +: + _pid(0), _ds_ep(ep) +{ + Arg_string::find_arg(args, "label").string(_label, sizeof(_label), + ""); +} Pd_session_component::~Pd_session_component() @@ -100,10 +106,11 @@ int Pd_session_component::assign_parent(Parent_capability parent) } -void Pd_session_component::start(Capability binary, Name const &name) +void Pd_session_component::start(Capability binary) { /* lookup binary dataspace */ - Dataspace_component *ds = reinterpret_cast(_ds_ep->obj_by_cap(binary)); + Dataspace_component *ds = + reinterpret_cast(_ds_ep->obj_by_cap(binary)); if (!ds) { PERR("could not lookup binary, aborted PD startup"); @@ -128,8 +135,9 @@ void Pd_session_component::start(Capability binary, Name const &name) &envbuf[3][0], &envbuf[4][0], 0 }; /* prefix name of Linux program (helps killing some zombies) */ - char pname_buf[9 + Linux_dataspace::FNAME_LEN]; - snprintf(pname_buf, sizeof(pname_buf), "[Genode] %s", name.string()); + char const *prefix = "[Genode] "; + char pname_buf[sizeof(_label) + sizeof(prefix)]; + snprintf(pname_buf, sizeof(pname_buf), "%s%s", prefix, _label); char *argv_buf[2]; argv_buf[0] = pname_buf; argv_buf[1] = 0; diff --git a/base-okl4/include/okl4_pd_session/connection.h b/base-okl4/include/okl4_pd_session/connection.h index d4b720135b..eb479e6004 100644 --- a/base-okl4/include/okl4_pd_session/connection.h +++ b/base-okl4/include/okl4_pd_session/connection.h @@ -21,18 +21,9 @@ namespace Genode { struct Pd_connection : Connection, Okl4_pd_session_client { - /** - * Constructor - * - * \param args additional session arguments - */ - Pd_connection(const char *args = 0) + Pd_connection() : - Connection( - session("ram_quota=4K%s%s", - args ? ", " : "", - args ? args : "")), - + Connection(session("ram_quota=4K")), Okl4_pd_session_client(cap()) { } }; diff --git a/base/include/pd_session/connection.h b/base/include/pd_session/connection.h index 5bc903eb5f..6edb1567ce 100644 --- a/base/include/pd_session/connection.h +++ b/base/include/pd_session/connection.h @@ -24,15 +24,11 @@ namespace Genode { /** * Constructor * - * \param args additional session arguments + * \param label session label */ - Pd_connection(const char *args = 0) + Pd_connection(const char *label = "") : - Connection( - session("ram_quota=4K%s%s", - args ? ", " : "", - args ? args : "")), - + Connection(session("ram_quota=4K, label=\"%s\"", label)), Pd_session_client(cap()) { } }; diff --git a/base/src/base/process/process.cc b/base/src/base/process/process.cc index 6f102a1a04..342e3b56d1 100644 --- a/base/src/base/process/process.cc +++ b/base/src/base/process/process.cc @@ -174,9 +174,10 @@ Process::Process(Dataspace_capability elf_ds_cap, Cpu_session_capability cpu_session_cap, Rm_session_capability rm_session_cap, Parent_capability parent_cap, - const char *name, + char const *name, char *const argv[]) : + _pd(name), _cpu_session_client(cpu_session_cap), _rm_session_client(rm_session_cap) {