From 0f052357ef8e0a36dd931b17ae749cf9885ed2b8 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Tue, 15 Sep 2015 18:16:31 +0200 Subject: [PATCH] init: propagate exit conditions of children This patch extends the configuration concept of init with an additional sub node for the node: ... If the 'propagate' attribute is set to "yes", the exit of the respective child will appear to init's parent as the exit of the entire init subsystem. Fixes #1686 --- repos/os/doc/init.txt | 21 +++++++++++++++++++++ repos/os/include/init/child.h | 17 +++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/repos/os/doc/init.txt b/repos/os/doc/init.txt index 00f9545bb5..987e5e936f 100644 --- a/repos/os/doc/init.txt +++ b/repos/os/doc/init.txt @@ -299,6 +299,27 @@ as LOG output. To enable the verbose mode, assign the value "yes" to the 'verbose' attribute of the '' node. +Propagation of exit events +========================== + +A component can notify its parent about its graceful exit via the exit RPC +function of the parent interface. By default, init responds to such a +notification from one of its children by merely printing a log message but +ignores it otherwise. However, there are scenarios where the exit of a +particular child should result in the exit of the entire init component. To +propagate the exit of a child to the parent of init, start nodes can host the +optional sub node '' with the attribute 'propagate' set to "yes". + +! +! +! +! ... +! +! + +The exit value specified by the exiting child is forwarded to init's parent. + + Executing children in chroot environments on Linux ================================================== diff --git a/repos/os/include/init/child.h b/repos/os/include/init/child.h index 4d7f076ff3..30b95c4349 100644 --- a/repos/os/include/init/child.h +++ b/repos/os/include/init/child.h @@ -802,6 +802,23 @@ class Init::Child : Genode::Child_policy _child.notify_resource_avail(); } + void exit(int exit_value) override + { + try { + if (_start_node.sub_node("exit").attribute("propagate").has_value("yes")) { + Genode::env()->parent()->exit(exit_value); + return; + } + } catch (...) { } + + /* + * Print a message as the exit is not handled otherwise. There are + * a number of automated tests that rely on this message. It is + * printed by the default implementation of 'Child_policy::exit'. + */ + Child_policy::exit(exit_value); + } + Genode::Native_pd_args const *pd_args() const { return &_pd_args; } };