mirror of
https://github.com/genodelabs/genode.git
synced 2025-05-24 03:04:22 +00:00
This patch introduces support for ROM sessions that update their provided data during the lifetime of the session. The 'Rom_session' interface had been extended with the new 'release()' and 'sigh()' functions, which are needed to support the new protocol. All ROM services have been updated to the new interface. Furthermore, the patch changes the child policy of init with regard to the handling of configuration files. The 'Init::Child' used to always provide the ROM dataspace with the child's config file via a locally implemented ROM service. However, for dynamic ROM sessions, we need to establish a session to the real supplier of the ROM data. This is achieved by using a new 'Child_policy_redirect_rom_file' policy to handle the 'configfile' rather than handling the 'configfile' case entirely within 'Child_config'. To see the new facility in action, the new 'os/run/dynamic_config.run' script provides a simple scenario. The config file of the test program is provided by a service, which generates and updates the config data at regular intervals. In addition, new support has been added to let slaves use dynamic reconfiguration. By using the new 'Child_policy_dynamic_rom_file', the configuration of a slave can be changed dynamically at runtime via the new 'configure()' function. The config is provided as plain null-terminated string (instead of a dataspace capability) because we need to buffer the config data anyway. So there is no benefit of using a dataspace. For buffering configuration data, a 'Ram_session' must be supplied. If no 'Ram_session' is specified at construction time of a 'Slave_policy', no config is supplied to the slave (which is still a common case). An example for dynamically reconfiguring a slave is provided by 'os/run/dynamic_config_slave.run'.
105 lines
2.4 KiB
C++
105 lines
2.4 KiB
C++
/*
|
|
* \brief Access to process configuration
|
|
* \author Norman Feske
|
|
* \date 2010-05-04
|
|
*/
|
|
|
|
/*
|
|
* Copyright (C) 2010-2012 Genode Labs GmbH
|
|
*
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
* under the terms of the GNU General Public License version 2.
|
|
*/
|
|
|
|
#ifndef _INCLUDE__OS__CONFIG_H_
|
|
#define _INCLUDE__OS__CONFIG_H_
|
|
|
|
#include <util/xml_node.h>
|
|
#include <dataspace/client.h>
|
|
#include <rom_session/connection.h>
|
|
#include <base/exception.h>
|
|
|
|
namespace Genode {
|
|
|
|
class Config
|
|
{
|
|
private:
|
|
|
|
Rom_connection _config_rom;
|
|
Dataspace_capability _config_ds;
|
|
Xml_node _config_xml;
|
|
|
|
public:
|
|
|
|
/**
|
|
* Exception class for configuration errors
|
|
*/
|
|
class Invalid : public Exception { };
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
Config() :
|
|
_config_rom("config"),
|
|
_config_ds(_config_rom.dataspace()),
|
|
_config_xml(env()->rm_session()->attach(_config_ds),
|
|
Genode::Dataspace_client(_config_ds).size())
|
|
{ }
|
|
|
|
Xml_node xml_node() { return _config_xml; }
|
|
|
|
/**
|
|
* Register signal handler for tracking config modifications
|
|
*/
|
|
void sigh(Signal_context_capability cap) { _config_rom.sigh(cap); }
|
|
|
|
/**
|
|
* Reload configuration
|
|
*
|
|
* \throw Invalid if the new configuration has an invalid syntax
|
|
*
|
|
* This function is meant to be called as response to a signal
|
|
* received by the signal handler as registered via 'sigh()'.
|
|
*/
|
|
void reload()
|
|
{
|
|
try {
|
|
/* re-acquire dataspace from ROM session */
|
|
env()->rm_session()->detach(_config_xml.addr());
|
|
_config_ds = _config_rom.dataspace();
|
|
|
|
/* re-initialize XML node with new config data */
|
|
_config_xml = Xml_node(env()->rm_session()->attach(_config_ds),
|
|
Genode::Dataspace_client(_config_ds).size());
|
|
|
|
} catch (Genode::Xml_node::Invalid_syntax) {
|
|
PERR("Config file has invalid syntax");
|
|
throw Invalid();
|
|
}
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Return singleton instance of config
|
|
*/
|
|
static Config *config()
|
|
{
|
|
static bool config_failed = false;
|
|
if (!config_failed) {
|
|
try {
|
|
static Config config_inst;
|
|
return &config_inst;
|
|
} catch (Genode::Rom_connection::Rom_connection_failed) {
|
|
PERR("Could not obtain config file");
|
|
} catch (Genode::Xml_node::Invalid_syntax) {
|
|
PERR("Config file has invalid syntax");
|
|
}
|
|
}
|
|
/* do not try again to construct 'config_inst' */
|
|
config_failed = true;
|
|
throw Config::Invalid();
|
|
}
|
|
}
|
|
|
|
#endif /* _INCLUDE__OS__CONFIG_H_ */
|