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.
This commit is contained in:
Norman Feske 2012-10-11 20:57:10 +02:00
parent 97162332c9
commit db2b1a37ae
8 changed files with 32 additions and 34 deletions

View File

@ -35,8 +35,8 @@ namespace Genode {
* Linux-specific extension **
*****************************/
void start(Capability<Dataspace> binary, Name const &name) {
call<Rpc_start>(binary, name); }
void start(Capability<Dataspace> binary) {
call<Rpc_start>(binary); }
};
}

View File

@ -21,16 +21,14 @@ namespace Genode {
struct Linux_pd_session : Pd_session
{
typedef Rpc_in_buffer<64> Name;
void start(Capability<Dataspace> binary, Name const &name);
void start(Capability<Dataspace> binary);
/*********************
** RPC declaration **
*********************/
GENODE_RPC(Rpc_start, void, start, Capability<Dataspace>, Name const &);
GENODE_RPC(Rpc_start, void, start, Capability<Dataspace>);
GENODE_RPC_INTERFACE_INHERIT(Pd_session, Rpc_start);
};
}

View File

@ -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<Linux_pd_session>(_pd.cap()));
lx_pd.assign_parent(parent_cap);
lx_pd.start(elf_data_ds_cap, name);
lx_pd.start(elf_data_ds_cap);
}

View File

@ -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<Dataspace> binary, Name const &name);
void start(Capability<Dataspace> binary);
};
}

View File

@ -12,6 +12,7 @@
*/
/* Genode includes */
#include <util/arg_string.h>
#include <base/printf.h>
#include <base/snprintf.h>
@ -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),
"<unlabeled>");
}
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<Dataspace> binary, Name const &name)
void Pd_session_component::start(Capability<Dataspace> binary)
{
/* lookup binary dataspace */
Dataspace_component *ds = reinterpret_cast<Dataspace_component *>(_ds_ep->obj_by_cap(binary));
Dataspace_component *ds =
reinterpret_cast<Dataspace_component *>(_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<Dataspace> 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;

View File

@ -21,18 +21,9 @@ namespace Genode {
struct Pd_connection : Connection<Pd_session>, Okl4_pd_session_client
{
/**
* Constructor
*
* \param args additional session arguments
*/
Pd_connection(const char *args = 0)
Pd_connection()
:
Connection<Pd_session>(
session("ram_quota=4K%s%s",
args ? ", " : "",
args ? args : "")),
Connection<Pd_session>(session("ram_quota=4K")),
Okl4_pd_session_client(cap())
{ }
};

View File

@ -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<Pd_session>(
session("ram_quota=4K%s%s",
args ? ", " : "",
args ? args : "")),
Connection<Pd_session>(session("ram_quota=4K, label=\"%s\"", label)),
Pd_session_client(cap())
{ }
};

View File

@ -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)
{