os: removal of deprecated os/config.h (fix #2431)

This commit is contained in:
Stefan Kalkowski 2017-05-29 14:52:24 +02:00 committed by Christian Helmuth
parent dd214a8b15
commit 632ef28463
56 changed files with 354 additions and 660 deletions

View File

@ -1,3 +1,3 @@
TARGET = test-platform TARGET = test-platform
SRC_CC = main.cc ipc.cc SRC_CC = main.cc ipc.cc
LIBS = base-nova config LIBS = base-nova

View File

@ -4,7 +4,7 @@
# These static libraries are filtered out when linking dynamically linked # These static libraries are filtered out when linking dynamically linked
# binaries. # binaries.
# #
BASE_LIBS += cxx timed_semaphore alarm config BASE_LIBS += cxx timed_semaphore alarm
# #
# Name of Genode's dynamic linker # Name of Genode's dynamic linker

View File

@ -1,3 +1,3 @@
TARGET = test-audio_in TARGET = test-audio_in
SRC_CC = main.cc SRC_CC = main.cc
LIBS = base config LIBS = base

View File

@ -1,7 +1,7 @@
LIB_DIR = $(REP_DIR)/src/lib/usb LIB_DIR = $(REP_DIR)/src/lib/usb
LIB_INC_DIR = $(LIB_DIR)/include LIB_INC_DIR = $(LIB_DIR)/include
LIBS += usb_include lx_kit_setjmp config LIBS += usb_include lx_kit_setjmp
SRC_CC += main.cc lx_emul.cc storage.cc \ SRC_CC += main.cc lx_emul.cc storage.cc \
input_component.cc evdev.cc nic.cc raw.cc input_component.cc evdev.cc nic.cc raw.cc
SRC_C += dummies.c scsi.c raw_driver.c SRC_C += dummies.c scsi.c raw_driver.c

View File

@ -28,6 +28,7 @@ class Driver : public Block::Driver
{ {
private: private:
Genode::Heap &_heap;
Block::Session::Operations _ops; Block::Session::Operations _ops;
Genode::size_t _blk_sz; Genode::size_t _blk_sz;
Block::sector_t _blk_cnt; Block::sector_t _blk_cnt;
@ -37,13 +38,13 @@ class Driver : public Block::Driver
public: public:
Driver(Genode::Entrypoint &ep, Genode::Ram_session &ram) Driver(Genode::Env &env, Genode::Heap &heap)
: :
Block::Driver(ram), Block::Driver(env.ram()), _heap(heap),
_blk_sz(0), _blk_cnt(0), _cgd_device(0) _blk_sz(0), _blk_cnt(0), _cgd_device(0)
{ {
try { try {
_cgd_device = Cgd::init(Genode::env()->heap(), ep); _cgd_device = Cgd::init(_heap, env);
} catch (...) { } catch (...) {
Genode::error("could not initialize cgd device."); Genode::error("could not initialize cgd device.");
throw Genode::Service_denied(); throw Genode::Service_denied();
@ -62,7 +63,7 @@ class Driver : public Block::Driver
~Driver() ~Driver()
{ {
Cgd::deinit(Genode::env()->heap(), _cgd_device); Cgd::deinit(_heap, _cgd_device);
} }
bool _range_valid(Block::sector_t num, Genode::size_t count) bool _range_valid(Block::sector_t num, Genode::size_t count)

View File

@ -12,7 +12,7 @@
*/ */
/* Genode includes */ /* Genode includes */
#include <os/config.h> #include <base/attached_rom_dataspace.h>
/* repo includes */ /* repo includes */
#include <rump_cgd/cgd.h> #include <rump_cgd/cgd.h>
@ -164,9 +164,9 @@ namespace Cgd {
VALID_ENCODED_KEY_LEN = 48, /* length of 256Bit key */ VALID_ENCODED_KEY_LEN = 48, /* length of 256Bit key */
}; };
Genode::Config &_cfg; Genode::Attached_rom_dataspace _cfg;
Action _action; Action _action;
Params *_params; Params *_params;
/** /**
* Get action from config attribute * Get action from config attribute
@ -177,8 +177,8 @@ namespace Cgd {
{ {
char action_val[ACTION_VALUE_LEN]; char action_val[ACTION_VALUE_LEN];
if (_cfg.xml_node().has_attribute("action")) if (_cfg.xml().has_attribute("action"))
_cfg.xml_node().attribute("action").value(action_val, sizeof (action_val)); _cfg.xml().attribute("action").value(action_val, sizeof (action_val));
else else
return ACTION_INVALID; return ACTION_INVALID;
@ -224,8 +224,8 @@ namespace Cgd {
*/ */
void _parse_config() void _parse_config()
{ {
if (_cfg.xml_node().has_sub_node("params")) { if (_cfg.xml().has_sub_node("params")) {
Genode::Xml_node pnode = _cfg.xml_node().sub_node("params"); Genode::Xml_node pnode = _cfg.xml().sub_node("params");
char method_val[4]; char method_val[4];
pnode.sub_node("method").value(method_val, sizeof (method_val)); pnode.sub_node("method").value(method_val, sizeof (method_val));
@ -270,9 +270,9 @@ namespace Cgd {
public: public:
Config() Config(Genode::Env &env)
: :
_cfg(*Genode::config()), _cfg(env, "config"),
_action(_get_action()), _action(_get_action()),
_params(0) _params(0)
{ {
@ -444,7 +444,7 @@ Cgd::Device *Cgd::Device::configure(Genode::Allocator *alloc, Cgd::Params const
/** /**
* Initialize a new Cgd::Device * Initialize a new Cgd::Device
*/ */
Cgd::Device *Cgd::init(Genode::Allocator *alloc, Genode::Entrypoint &ep) Cgd::Device *Cgd::init(Genode::Allocator &alloc, Genode::Env &env)
{ {
/* start rumpkernel */ /* start rumpkernel */
rump_init(); rump_init();
@ -456,7 +456,7 @@ Cgd::Device *Cgd::init(Genode::Allocator *alloc, Genode::Entrypoint &ep)
throw Genode::Exception(); throw Genode::Exception();
} }
Cgd::Config cfg; Cgd::Config cfg(env);
Cgd::Config::Action action = cfg.action(); Cgd::Config::Action action = cfg.action();
@ -469,7 +469,7 @@ Cgd::Device *Cgd::init(Genode::Allocator *alloc, Genode::Entrypoint &ep)
if (!p) if (!p)
throw Genode::Exception(); throw Genode::Exception();
cgd_dev = Cgd::Device::configure(alloc, p, GENODE_DEVICE); cgd_dev = Cgd::Device::configure(&alloc, p, GENODE_DEVICE);
break; break;
} }
@ -495,7 +495,7 @@ Cgd::Device *Cgd::init(Genode::Allocator *alloc, Genode::Entrypoint &ep)
/** /**
* Deinitialize a Cgd::Device * Deinitialize a Cgd::Device
*/ */
void Cgd::deinit(Genode::Allocator *alloc, Cgd::Device *dev) void Cgd::deinit(Genode::Allocator &alloc, Cgd::Device *dev)
{ {
destroy(alloc, dev); destroy(alloc, dev);

View File

@ -51,8 +51,8 @@ namespace Cgd {
}; };
Device *init(Genode::Allocator *alloc, Genode::Entrypoint &ep); Device *init(Genode::Allocator &alloc, Genode::Env &env);
void deinit(Genode::Allocator *alloc, Device *dev); void deinit(Genode::Allocator &alloc, Device *dev);
} }
#endif /* _CGD_H_ */ #endif /* _CGD_H_ */

View File

@ -27,20 +27,19 @@ struct Main
struct Factory : Block::Driver_factory struct Factory : Block::Driver_factory
{ {
Genode::Entrypoint &ep; Genode::Env &env;
Genode::Ram_session &ram; Genode::Heap &heap;
Genode::Heap &heap;
Factory(Genode::Entrypoint &ep, Genode::Ram_session &ram, Genode::Heap &heap) Factory(Genode::Env &env, Genode::Heap &heap)
: ep(ep), ram(ram), heap(heap) { } : env(env), heap(heap) { }
Block::Driver *create() { Block::Driver *create() {
return new (&heap) Driver(ep, ram); } return new (&heap) Driver(env, heap); }
void destroy(Block::Driver *driver) { void destroy(Block::Driver *driver) {
Genode::destroy(&heap, driver); } Genode::destroy(&heap, driver); }
} factory { env.ep(), env.ram(), heap }; } factory { env, heap };
Block::Root root { env.ep(), heap, env.rm(), factory }; Block::Root root { env.ep(), heap, env.rm(), factory };

View File

@ -1,5 +1,5 @@
TARGET = liquid_fb TARGET = liquid_fb
LIBS = scout_widgets config LIBS = scout_widgets
SRC_CC = main.cc services.cc SRC_CC = main.cc services.cc
INC_DIR += $(REP_DIR)/src/app/scout \ INC_DIR += $(REP_DIR)/src/app/scout \
$(REP_DIR)/src/server/framebuffer/sdl $(REP_DIR)/src/server/framebuffer/sdl

View File

@ -1,4 +1,4 @@
TARGET = cpu_load_display TARGET = cpu_load_display
SRC_CC = main.cc SRC_CC = main.cc
LIBS = base config LIBS = base
INC_DIR += $(PRG_DIR) INC_DIR += $(PRG_DIR)

View File

@ -92,26 +92,33 @@ static inline void load_stylesheet()
} }
int main(int argc, char *argv[]) void Libc::Component::construct(Libc::Env &env)
{ {
Report_thread *report_thread; Libc::with_libc([&] {
try { report_thread = new Report_thread(); } initialize_qpa_plugin(env);
catch (...) {
int argc = 1;
char const *argv[] = { "mixer_gui_qt", 0 };
Report_thread *report_thread;
try { report_thread = new Report_thread(); }
catch (...) {
Genode::error("Could not create Report_thread"); Genode::error("Could not create Report_thread");
return -1; return -1;
}
QApplication app(argc, argv);
load_stylesheet();
QMember<Main_window> main_window(env);
main_window->show();
report_thread->connect_window(main_window);
report_thread->start();
app.connect(&app, SIGNAL(lastWindowClosed()), SLOT(quit()));
exit(app.exec());
} }
QApplication app(argc, argv);
load_stylesheet();
QMember<Main_window> main_window;
main_window->show();
report_thread->connect_window(main_window);
report_thread->start();
app.connect(&app, SIGNAL(lastWindowClosed()), SLOT(quit()));
return app.exec();
} }

View File

@ -15,7 +15,6 @@
#include <base/log.h> #include <base/log.h>
#include <mixer/channel.h> #include <mixer/channel.h>
#include <base/attached_rom_dataspace.h> #include <base/attached_rom_dataspace.h>
#include <os/config.h>
#include <os/reporter.h> #include <os/reporter.h>
#include <rom_session/connection.h> #include <rom_session/connection.h>
@ -434,7 +433,7 @@ void Main_window::report_changed(void *l, void const *p)
} }
Main_window::Main_window() Main_window::Main_window(Libc::Env &env)
: :
_default_out_volume(0), _default_out_volume(0),
_default_volume(0), _default_volume(0),
@ -445,13 +444,14 @@ Main_window::Main_window()
using namespace Genode; using namespace Genode;
Attached_rom_dataspace config(env, "config");
try { try {
Xml_node config_node = config()->xml_node(); Xml_node config_node = config.xml();
_verbose = config_node.attribute("verbose").has_value("yes"); _verbose = config_node.attribute("verbose").has_value("yes");
} catch (...) { _verbose = false; } } catch (...) { _verbose = false; }
try { try {
Xml_node node = config()->xml_node().sub_node("default"); Xml_node node = config.xml().sub_node("default");
_default_out_volume = node.attribute_value<long>("out_volume", 0); _default_out_volume = node.attribute_value<long>("out_volume", 0);
_default_volume = node.attribute_value<long>("volume", 0); _default_volume = node.attribute_value<long>("volume", 0);
_default_muted = node.attribute_value<long>("muted", 1); _default_muted = node.attribute_value<long>("muted", 1);

View File

@ -8,4 +8,4 @@ include $(QT5_REP_DIR)/src/app/qt5/tmpl/target_final.inc
main_window.o: main_window.moc main_window.o: main_window.moc
LIBS += config qoost qt5_component LIBS += qoost qt5_gui qt5_widgets qt5_core libc

View File

@ -31,8 +31,14 @@ namespace Decorator {
class Decorator::Config class Decorator::Config
{ {
private:
Genode::Xml_node _config;
public: public:
Config(Genode::Xml_node node) : _config(node) {}
/** /**
* Return the base color of the window with the specified title * Return the base color of the window with the specified title
*/ */
@ -41,7 +47,7 @@ class Decorator::Config
Color result(0, 0, 0); Color result(0, 0, 0);
try { try {
Genode::Session_policy policy(title); Genode::Session_policy policy(title, _config);
result = policy.attribute_value("color", result); result = policy.attribute_value("color", result);
} catch (Genode::Session_policy::No_policy_defined) { } } catch (Genode::Session_policy::No_policy_defined) { }

View File

@ -101,7 +101,7 @@ struct Decorator::Main : Window_factory_base
Attached_rom_dataspace _config { _env, "config" }; Attached_rom_dataspace _config { _env, "config" };
Config _decorator_config; Config _decorator_config { _config.xml() };
void _handle_config(); void _handle_config();

View File

@ -1,4 +1,4 @@
SRC_CC = init.cc plugin.cc SRC_CC = plugin.cc
vpath %.cc $(REP_DIR)/src/lib/libc_lwip_nic_dhcp vpath %.cc $(REP_DIR)/src/lib/libc_lwip_nic_dhcp

View File

@ -39,7 +39,6 @@ set config {
<start name="test-python"> <start name="test-python">
<resource name="RAM" quantum="3M"/> <resource name="RAM" quantum="3M"/>
<config> <config>
<script name="hello.py"/>
<vfs> <vfs>
<dir name="dev"> <log/> </dir> <dir name="dev"> <log/> </dir>
<inline name="hello.py"> <inline name="hello.py">
@ -57,6 +56,7 @@ print " \r\n\r";
</inline> </inline>
</vfs> </vfs>
<libc stdout="/dev/log" stderr="/dev/log"/> <libc stdout="/dev/log" stderr="/dev/log"/>
<arg value="hello.py"/>
</config> </config>
</start> </start>
</config> </config>

View File

@ -1,129 +0,0 @@
/*
* \brief lwip nic interface initialisation using DHCP
* \author Christian Prochaska
* \date 2010-04-29
*
*/
/*
* Copyright (C) 2010-2017 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#include <base/log.h>
#include <parent/parent.h>
#include <os/config.h>
#include <nic/packet_allocator.h>
#include <util/string.h>
#include <lwip/genode.h>
extern "C" {
#include <lwip/sockets.h>
#include <lwip/api.h>
}
extern void create_lwip_plugin();
extern void create_etc_resolv_conf_plugin();
void __attribute__((constructor)) init_nic_dhcp(void)
{
enum { BUF_SIZE = Nic::Packet_allocator::DEFAULT_PACKET_SIZE * 128 };
Genode::log(__func__);
bool provide_etc_resolv_conf = true;
char ip_addr_str[16] = {0};
char netmask_str[16] = {0};
char gateway_str[16] = {0};
genode_int32_t ip_addr = 0;
genode_int32_t netmask = 0;
genode_int32_t gateway = 0;
Genode::Number_of_bytes tx_buf_size(BUF_SIZE);
Genode::Number_of_bytes rx_buf_size(BUF_SIZE);
try {
Genode::Xml_node libc_node = Genode::config()->xml_node().sub_node("libc");
provide_etc_resolv_conf = libc_node.attribute_value("resolv", provide_etc_resolv_conf);
try {
libc_node.attribute("ip_addr").value(ip_addr_str, sizeof(ip_addr_str));
} catch(...) { }
try {
libc_node.attribute("netmask").value(netmask_str, sizeof(netmask_str));
} catch(...) { }
try {
libc_node.attribute("gateway").value(gateway_str, sizeof(gateway_str));
} catch(...) { }
try {
libc_node.attribute("tx_buf_size").value(&tx_buf_size);
} catch(...) { }
try {
libc_node.attribute("rx_buf_size").value(&rx_buf_size);
} catch(...) { }
/* either none or all 3 interface attributes must exist */
if ((strlen(ip_addr_str) != 0) ||
(strlen(netmask_str) != 0) ||
(strlen(gateway_str) != 0)) {
if (strlen(ip_addr_str) == 0) {
Genode::error("missing \"ip_addr\" attribute. Ignoring network interface config.");
throw Genode::Xml_node::Nonexistent_attribute();
} else if (strlen(netmask_str) == 0) {
Genode::error("missing \"netmask\" attribute. Ignoring network interface config.");
throw Genode::Xml_node::Nonexistent_attribute();
} else if (strlen(gateway_str) == 0) {
Genode::error("missing \"gateway\" attribute. Ignoring network interface config.");
throw Genode::Xml_node::Nonexistent_attribute();
}
} else
throw -1;
Genode::log("static network interface: "
"ip_addr=", Genode::Cstring(ip_addr_str), " "
"netmask=", Genode::Cstring(netmask_str), " "
"gateway=", Genode::Cstring(gateway_str));
genode_uint32_t ip, nm, gw;
ip = inet_addr(ip_addr_str);
nm = inet_addr(netmask_str);
gw = inet_addr(gateway_str);
if (ip == INADDR_NONE || nm == INADDR_NONE || gw == INADDR_NONE) {
Genode::error("invalid network interface config");
throw -1;
} else {
ip_addr = ip;
netmask = nm;
gateway = gw;
}
}
catch (...) {
Genode::log("Using DHCP for interface configuration.");
}
/* make sure the libc_lwip plugin has been created */
create_lwip_plugin();
try {
lwip_nic_init(ip_addr, netmask, gateway,
(Genode::size_t)tx_buf_size, (Genode::size_t)rx_buf_size);
}
catch (Genode::Service_denied) { /* ignore for now */ }
if (provide_etc_resolv_conf)
create_etc_resolv_conf_plugin();
}

View File

@ -33,9 +33,34 @@
#include <string.h> #include <string.h>
/* Genode includes */ /* Genode includes */
#include <base/attached_rom_dataspace.h>
#include <base/env.h> #include <base/env.h>
#include <base/heap.h>
#include <util/misc_math.h> #include <util/misc_math.h>
#include <base/log.h>
#include <parent/parent.h>
#include <nic/packet_allocator.h>
#include <util/string.h>
#include <lwip/genode.h>
#undef AF_INET6
#undef MSG_PEEK
#undef MSG_WAITALL
#undef MSG_OOB
#undef MSG_DONTWAIT
namespace Lwip {
extern "C" {
#include <lwip/sockets.h>
#include <lwip/api.h>
}
}
extern void create_lwip_plugin();
namespace { namespace {
@ -92,6 +117,8 @@ namespace {
{ {
private: private:
Genode::Constructible<Genode::Heap> _heap;
/** /**
* File name this plugin feels responsible for * File name this plugin feels responsible for
*/ */
@ -134,14 +161,14 @@ namespace {
Libc::File_descriptor *open(const char *pathname, int flags) Libc::File_descriptor *open(const char *pathname, int flags)
{ {
Plugin_context *context = new (Genode::env()->heap()) Plugin_context; Plugin_context *context = new (*_heap) Plugin_context;
context->status_flags(flags); context->status_flags(flags);
return Libc::file_descriptor_allocator()->alloc(this, context); return Libc::file_descriptor_allocator()->alloc(this, context);
} }
int close(Libc::File_descriptor *fd) int close(Libc::File_descriptor *fd)
{ {
Genode::destroy(Genode::env()->heap(), context(fd)); Genode::destroy(*_heap, context(fd));
Libc::file_descriptor_allocator()->free(fd); Libc::file_descriptor_allocator()->free(fd);
return 0; return 0;
} }
@ -223,12 +250,104 @@ namespace {
default: Genode::error("fcntl(): command ", cmd, " not supported", cmd); return -1; default: Genode::error("fcntl(): command ", cmd, " not supported", cmd); return -1;
} }
} }
};
void init(Libc::Env &env) override
{
_heap.construct(env.ram(), env.rm());
enum { BUF_SIZE = Nic::Packet_allocator::DEFAULT_PACKET_SIZE * 128 };
Genode::log(__func__);
char ip_addr_str[16] = {0};
char netmask_str[16] = {0};
char gateway_str[16] = {0};
genode_int32_t ip_addr = 0;
genode_int32_t netmask = 0;
genode_int32_t gateway = 0;
Genode::Number_of_bytes tx_buf_size(BUF_SIZE);
Genode::Number_of_bytes rx_buf_size(BUF_SIZE);
try {
Genode::Attached_rom_dataspace config(env, "config");
Genode::Xml_node libc_node = config.xml().sub_node("libc");
try {
libc_node.attribute("ip_addr").value(ip_addr_str, sizeof(ip_addr_str));
} catch(...) { }
try {
libc_node.attribute("netmask").value(netmask_str, sizeof(netmask_str));
} catch(...) { }
try {
libc_node.attribute("gateway").value(gateway_str, sizeof(gateway_str));
} catch(...) { }
try {
libc_node.attribute("tx_buf_size").value(&tx_buf_size);
} catch(...) { }
try {
libc_node.attribute("rx_buf_size").value(&rx_buf_size);
} catch(...) { }
/* either none or all 3 interface attributes must exist */
if ((strlen(ip_addr_str) != 0) ||
(strlen(netmask_str) != 0) ||
(strlen(gateway_str) != 0)) {
if (strlen(ip_addr_str) == 0) {
Genode::error("missing \"ip_addr\" attribute. Ignoring network interface config.");
throw Genode::Xml_node::Nonexistent_attribute();
} else if (strlen(netmask_str) == 0) {
Genode::error("missing \"netmask\" attribute. Ignoring network interface config.");
throw Genode::Xml_node::Nonexistent_attribute();
} else if (strlen(gateway_str) == 0) {
Genode::error("missing \"gateway\" attribute. Ignoring network interface config.");
throw Genode::Xml_node::Nonexistent_attribute();
}
} else
throw -1;
Genode::log("static network interface: "
"ip_addr=", Genode::Cstring(ip_addr_str), " "
"netmask=", Genode::Cstring(netmask_str), " "
"gateway=", Genode::Cstring(gateway_str));
genode_uint32_t ip, nm, gw;
ip = inet_addr(ip_addr_str);
nm = inet_addr(netmask_str);
gw = inet_addr(gateway_str);
if (ip == INADDR_NONE || nm == INADDR_NONE || gw == INADDR_NONE) {
Genode::error("invalid network interface config");
throw -1;
} else {
ip_addr = ip;
netmask = nm;
gateway = gw;
}
}
catch (...) {
Genode::log("Using DHCP for interface configuration.");
}
/* make sure the libc_lwip plugin has been created */
create_lwip_plugin();
try {
lwip_nic_init(ip_addr, netmask, gateway,
(Genode::size_t)tx_buf_size, (Genode::size_t)rx_buf_size);
}
catch (Genode::Service_denied) { /* ignore for now */ }
}
};
} /* unnamed namespace */ } /* unnamed namespace */
void create_etc_resolv_conf_plugin() void __attribute__((constructor)) init_libc_lwip_dhcp(void)
{ {
static Plugin plugin; static Plugin plugin;
} }

View File

@ -15,10 +15,10 @@
*/ */
#include <base/allocator_avl.h> #include <base/allocator_avl.h>
#include <base/attached_rom_dataspace.h>
#include <base/log.h> #include <base/log.h>
#include <base/thread.h> #include <base/thread.h>
#include <audio_out_session/connection.h> #include <audio_out_session/connection.h>
#include <os/config.h>
enum { enum {
@ -75,13 +75,17 @@ static Signal_receiver *signal_receiver()
} }
static void read_config() static void read_config(Genode::Signal_context_capability sigh =
Genode::Signal_context_capability())
{ {
/* read volume from config file */ /* read volume from config file */
try { try {
unsigned int config_volume; unsigned int config_volume;
Genode::config()->xml_node().sub_node("sdl_audio_volume") Genode::Attached_rom_dataspace config("config");
if (sigh.valid()) config.sigh(sigh);
else config.update();
config.xml().sub_node("sdl_audio_volume")
.attribute("value").value(&config_volume); .attribute("value").value(&config_volume);
volume = (float)config_volume / 100; volume = (float)config_volume / 100;
@ -163,8 +167,7 @@ static SDL_AudioDevice *GENODEAUD_CreateDevice(int devindex)
} }
} }
Genode::config()->sigh(signal_receiver()->manage(&config_signal_context)); read_config(signal_receiver()->manage(&config_signal_context));
read_config();
return _this; return _this;
} }
@ -221,7 +224,6 @@ static void GENODEAUD_PlayAudio(_THIS)
if (signal_receiver()->pending()) { if (signal_receiver()->pending()) {
signal_receiver()->wait_for_signal(); signal_receiver()->wait_for_signal();
Genode::config()->reload();
read_config(); read_config();
} }

View File

@ -829,11 +829,11 @@ namespace File_system {
{ {
private: private:
Genode::Env &_env; Genode::Env &_env;
Genode::Allocator &_md_alloc; Genode::Allocator &_md_alloc;
Genode::Allocator &_heap; Genode::Allocator &_heap;
Genode::Attached_rom_dataspace _config { _env, "config" };
Directory &_root_dir; Directory &_root_dir;
protected: protected:
@ -852,7 +852,7 @@ namespace File_system {
Session_label const label = label_from_args(args); Session_label const label = label_from_args(args);
try { try {
Session_policy policy(label); Session_policy policy(label, _config.xml());
/* /*
* Determine directory that is used as root directory of * Determine directory that is used as root directory of

View File

@ -6,7 +6,7 @@ SRC_C = $(notdir $(EXFAT_DIR)/fuse/main.c)
SRC_CC = fuse_fs_main.cc \ SRC_CC = fuse_fs_main.cc \
init.cc init.cc
LIBS = config libc libfuse libexfat LIBS = libc libfuse libexfat
INC_DIR += $(PRG_DIR)/.. INC_DIR += $(PRG_DIR)/..
CC_OPT += -Wno-unused-function CC_OPT += -Wno-unused-function

View File

@ -9,7 +9,7 @@ SRC_C = $(filter-out $(FILTER_OUT), $(notdir $(wildcard $(FUSE_EXT2_DIR)/*.c)))
SRC_CC = fuse_fs_main.cc \ SRC_CC = fuse_fs_main.cc \
init.cc init.cc
LIBS = config libc libfuse libext2fs LIBS = libc libfuse libext2fs
CC_OPT += -DHAVE_CONFIG_H -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 CC_OPT += -DHAVE_CONFIG_H -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64

View File

@ -16,7 +16,6 @@
#include <file_system/node_handle_registry.h> #include <file_system/node_handle_registry.h>
#include <file_system_session/rpc_object.h> #include <file_system_session/rpc_object.h>
#include <base/attached_rom_dataspace.h> #include <base/attached_rom_dataspace.h>
#include <os/config.h>
#include <os/session_policy.h> #include <os/session_policy.h>
#include <root/component.h> #include <root/component.h>
#include <util/xml_node.h> #include <util/xml_node.h>
@ -41,7 +40,7 @@ class File_system::Session_component : public Session_rpc_object
{ {
private: private:
Genode::Entrypoint &_ep; Genode::Env &_env;
Allocator &_md_alloc; Allocator &_md_alloc;
Directory &_root; Directory &_root;
Node_handle_registry _handle_registry; Node_handle_registry _handle_registry;
@ -155,19 +154,18 @@ class File_system::Session_component : public Session_rpc_object
/** /**
* Constructor * Constructor
*/ */
Session_component(size_t tx_buf_size, Session_component(size_t tx_buf_size,
Genode::Entrypoint &ep, Genode::Env &env,
Genode::Region_map &rm, char const *root_dir,
char const *root_dir, bool writeable,
bool writeable, Allocator &md_alloc)
Allocator &md_alloc)
: :
Session_rpc_object(env()->ram_session()->alloc(tx_buf_size), rm, ep.rpc_ep()), Session_rpc_object(env.ram().alloc(tx_buf_size), env.rm(), env.ep().rpc_ep()),
_ep(ep), _env(env),
_md_alloc(md_alloc), _md_alloc(md_alloc),
_root(*new (&_md_alloc) Directory(_md_alloc, root_dir, false)), _root(*new (&_md_alloc) Directory(_md_alloc, root_dir, false)),
_writeable(writeable), _writeable(writeable),
_process_packet_handler(_ep, *this, &Session_component::_process_packets) _process_packet_handler(_env.ep(), *this, &Session_component::_process_packets)
{ {
_tx.sigh_packet_avail(_process_packet_handler); _tx.sigh_packet_avail(_process_packet_handler);
_tx.sigh_ready_to_ack(_process_packet_handler); _tx.sigh_ready_to_ack(_process_packet_handler);
@ -181,7 +179,7 @@ class File_system::Session_component : public Session_rpc_object
Fuse::sync_fs(); Fuse::sync_fs();
Dataspace_capability ds = tx_sink()->dataspace(); Dataspace_capability ds = tx_sink()->dataspace();
env()->ram_session()->free(static_cap_cast<Ram_dataspace>(ds)); _env.ram().free(static_cap_cast<Ram_dataspace>(ds));
destroy(&_md_alloc, &_root); destroy(&_md_alloc, &_root);
} }
@ -402,8 +400,8 @@ class File_system::Root : public Root_component<Session_component>
{ {
private: private:
Genode::Entrypoint &_ep; Genode::Env &_env;
Genode::Region_map &_rm; Genode::Attached_rom_dataspace _config { _env, "config" };
protected: protected:
@ -423,7 +421,7 @@ class File_system::Root : public Root_component<Session_component>
Session_label const label = label_from_args(args); Session_label const label = label_from_args(args);
try { try {
Session_policy policy(label); Session_policy policy(label, _config.xml());
/* /*
* Determine directory that is used as root directory of * Determine directory that is used as root directory of
@ -485,7 +483,7 @@ class File_system::Root : public Root_component<Session_component>
throw Insufficient_ram_quota(); throw Insufficient_ram_quota();
} }
return new (md_alloc()) return new (md_alloc())
Session_component(tx_buf_size, _ep, _rm, root_dir, writeable, *md_alloc()); Session_component(tx_buf_size, _env, root_dir, writeable, *md_alloc());
} }
public: public:
@ -493,39 +491,29 @@ class File_system::Root : public Root_component<Session_component>
/** /**
* Constructor * Constructor
* *
* \param ep entrypoint * \param env environment
* \param sig_rec signal receiver used for handling the
* data-flow signals of packet streams
* \param md_alloc meta-data allocator * \param md_alloc meta-data allocator
*/ */
Root(Genode::Entrypoint &ep, Allocator &md_alloc, Genode::Region_map &rm) Root(Genode::Env & env, Allocator &md_alloc)
: : Root_component<Session_component>(env.ep(), md_alloc),
Root_component<Session_component>(&ep.rpc_ep(), &md_alloc), _env(env) { }
_ep(ep), _rm(rm)
{ }
}; };
struct File_system::Main struct File_system::Main
{ {
Genode::Entrypoint &ep; Genode::Env & env;
Genode::Region_map &rm; Sliced_heap sliced_heap { env.ram(), env.rm() };
Root fs_root { env, sliced_heap };
/* Main(Genode::Env & env) : env(env)
* Initialize root interface
*/
Sliced_heap sliced_heap = { env()->ram_session(), env()->rm_session() };
Root fs_root = { ep, sliced_heap, rm };
Main(Genode::Entrypoint &ep, Genode::Region_map &rm) : ep(ep), rm(rm)
{ {
if (!Fuse::init_fs()) { if (!Fuse::init_fs()) {
Genode::error("FUSE fs initialization failed"); Genode::error("FUSE fs initialization failed");
return; return;
} }
env()->parent()->announce(ep.manage(fs_root)); env.parent().announce(env.ep().manage(fs_root));
} }
~Main() ~Main()
@ -543,6 +531,6 @@ struct File_system::Main
void Libc::Component::construct(Libc::Env &env) void Libc::Component::construct(Libc::Env &env)
{ {
static File_system::Main inst(env.ep(), env.rm()); static File_system::Main inst(env);
} }

View File

@ -6,7 +6,7 @@ SRC_C := ntfs-3g.c ntfs-3g_common.c
SRC_CC := fuse_fs_main.cc \ SRC_CC := fuse_fs_main.cc \
init.cc init.cc
LIBS := config libc libfuse libntfs-3g LIBS := libc libfuse libntfs-3g
CC_OPT := -DHAVE_TIMESPEC -DHAVE_CONFIG_H -DRECORD_LOCKING_NOT_IMPLEMENTED CC_OPT := -DHAVE_TIMESPEC -DHAVE_CONFIG_H -DRECORD_LOCKING_NOT_IMPLEMENTED

View File

@ -13,15 +13,12 @@
*/ */
/* Genode includes */ /* Genode includes */
#include <base/attached_rom_dataspace.h>
#include <base/log.h> #include <base/log.h>
#include <base/thread.h>
#include <util/string.h>
#include <timer_session/connection.h>
#include <nic/packet_allocator.h>
#include <os/config.h>
#include <base/sleep.h>
#include <libc/component.h> #include <libc/component.h>
#include <nic/packet_allocator.h>
#include <timer_session/connection.h>
#include <util/string.h>
extern "C" { extern "C" {
#include <lwip/sockets.h> #include <lwip/sockets.h>
@ -32,90 +29,46 @@ extern "C" {
#include <lwip/genode.h> #include <lwip/genode.h>
static const char *http_get_request =
"GET / HTTP/1.0\r\nHost: localhost:80\r\n\r\n"; /* simple HTTP request header */
using namespace Genode;
template <Genode::size_t N>
static Genode::String<N> read_string_attribute(Genode::Xml_node node, char const *attr,
Genode::String<N> default_value)
{
try {
char buf[N];
node.attribute(attr).value(buf, sizeof(buf));
return Genode::String<N>(Genode::Cstring(buf));
}
catch (...) {
return default_value; }
}
bool static_ip_config(uint32_t & ip, uint32_t & nm, uint32_t & gw)
{
enum { ADDR_STR_SZ = 16 };
Xml_node libc_node = config()->xml_node().sub_node("libc");
String<ADDR_STR_SZ> ip_str =
read_string_attribute<ADDR_STR_SZ>(libc_node, "ip_addr", String<ADDR_STR_SZ>());
String<ADDR_STR_SZ> nm_str =
read_string_attribute<ADDR_STR_SZ>(libc_node, "netmask", String<ADDR_STR_SZ>());
String<ADDR_STR_SZ> gw_str =
read_string_attribute<ADDR_STR_SZ>(libc_node, "gateway", String<ADDR_STR_SZ>());
ip = inet_addr(ip_str.string());
nm = inet_addr(nm_str.string());
gw = inet_addr(gw_str.string());
if (ip == INADDR_NONE || nm == INADDR_NONE || gw == INADDR_NONE) { return false; }
log("static ip config: ip=", ip_str, " nm=", nm_str, " gw=", gw_str);
return true;
}
/** /**
* The client thread simply loops endless, * The client simply loops endless,
* and sends as much 'http get' requests as possible, * and sends as much 'http get' requests as possible,
* printing out the response. * printing out the response.
*/ */
void Libc::Component::construct(Libc::Env &env) void Libc::Component::construct(Libc::Env &env)
{ {
using namespace Genode;
using Address = Genode::String<16>;
enum { BUF_SIZE = Nic::Packet_allocator::DEFAULT_PACKET_SIZE * 128 }; enum { BUF_SIZE = Nic::Packet_allocator::DEFAULT_PACKET_SIZE * 128 };
static Timer::Connection _timer(env); static Timer::Connection _timer(env);
_timer.msleep(2000); _timer.msleep(2000);
lwip_tcpip_init(); lwip_tcpip_init();
uint32_t ip = 0; uint32_t ip = 0, nm = 0, gw = 0;
uint32_t nm = 0; Address serv_addr, ip_addr, netmask, gateway;
uint32_t gw = 0;
bool static_ip = static_ip_config(ip, nm, gw);
enum { ADDR_STR_SZ = 16 }; Attached_rom_dataspace config(env, "config");
char serv_addr[ADDR_STR_SZ] = { 0 }; Xml_node config_node = config.xml();
Xml_node config_node = config()->xml_node(); Xml_node libc_node = env.libc_config();
try { config_node.attribute("server_ip").value(serv_addr, ADDR_STR_SZ); } try {
catch(...) { libc_node.attribute("ip_addr").value(&ip_addr);
error("Missing \"server_ip\" attribute."); libc_node.attribute("netmask").value(&netmask);
throw Xml_node::Nonexistent_attribute(); libc_node.attribute("gateway").value(&gateway);
} ip = inet_addr(ip_addr.string());
nm = inet_addr(netmask.string());
gw = inet_addr(gateway.string());
} catch (...) {}
config_node.attribute("server_ip").value(&serv_addr);
if (static_ip) { if (lwip_nic_init(ip, nm, gw, BUF_SIZE, BUF_SIZE)) {
if (lwip_nic_init(ip, nm, gw, BUF_SIZE, BUF_SIZE)) { error("We got no IP address!");
error("We got no IP address!"); exit(1);
exit(1);
}
} else {
if( lwip_nic_init(0, 0, 0, BUF_SIZE, BUF_SIZE))
{
error("got no IP address!");
exit(1);
}
} }
for(int j = 0; j != 5; ++j) { for(int j = 0; j != 5; ++j) {
_timer.msleep(2000); _timer.msleep(2000);
log("Create new socket ..."); log("Create new socket ...");
int s = lwip_socket(AF_INET, SOCK_STREAM, 0 ); int s = lwip_socket(AF_INET, SOCK_STREAM, 0 );
if (s < 0) { if (s < 0) {
@ -135,7 +88,7 @@ void Libc::Component::construct(Libc::Env &env)
struct sockaddr_in addr; struct sockaddr_in addr;
addr.sin_port = htons(port); addr.sin_port = htons(port);
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr(serv_addr); addr.sin_addr.s_addr = inet_addr(serv_addr.string());
if((lwip_connect(s, (struct sockaddr *)&addr, sizeof(addr))) < 0) { if((lwip_connect(s, (struct sockaddr *)&addr, sizeof(addr))) < 0) {
error("Could not connect!"); error("Could not connect!");
@ -144,6 +97,11 @@ void Libc::Component::construct(Libc::Env &env)
} }
log("Send request..."); log("Send request...");
/* simple HTTP request header */
static const char *http_get_request =
"GET / HTTP/1.0\r\nHost: localhost:80\r\n\r\n";
unsigned long bytes = lwip_send(s, (char*)http_get_request, unsigned long bytes = lwip_send(s, (char*)http_get_request,
Genode::strlen(http_get_request), 0); Genode::strlen(http_get_request), 0);
if ( bytes < 0 ) { if ( bytes < 0 ) {

View File

@ -18,12 +18,11 @@
*/ */
/* Genode includes */ /* Genode includes */
#include <base/attached_rom_dataspace.h>
#include <base/log.h> #include <base/log.h>
#include <base/thread.h> #include <libc/component.h>
#include <util/string.h>
#include <nic/packet_allocator.h> #include <nic/packet_allocator.h>
#include <os/config.h> #include <util/string.h>
#include <base/snprintf.h>
/* LwIP includes */ /* LwIP includes */
extern "C" { extern "C" {
@ -33,15 +32,7 @@ extern "C" {
#include <lwip/genode.h> #include <lwip/genode.h>
using Response = Genode::String<1024>;
const static char http_html_hdr[] =
"HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n"; /* HTTP response header */
enum { HTTP_INDEX_HTML_SZ = 1024 };
static char http_index_html[HTTP_INDEX_HTML_SZ]; /* HTML page */
using namespace Genode;
/** /**
@ -49,7 +40,7 @@ using namespace Genode;
* *
* \param conn socket connected to the client * \param conn socket connected to the client
*/ */
void http_server_serve(int conn) void http_server_serve(int conn, Response & response)
{ {
char buf[1024]; char buf[1024];
ssize_t buflen; ssize_t buflen;
@ -57,7 +48,7 @@ void http_server_serve(int conn)
/* Read the data from the port, blocking if nothing yet there. /* Read the data from the port, blocking if nothing yet there.
We assume the request (the part we care about) is in one packet */ We assume the request (the part we care about) is in one packet */
buflen = lwip_recv(conn, buf, 1024, 0); buflen = lwip_recv(conn, buf, 1024, 0);
log("Packet received!"); Genode::log("Packet received!");
/* Ignore all receive errors */ /* Ignore all receive errors */
if (buflen > 0) { if (buflen > 0) {
@ -71,63 +62,46 @@ void http_server_serve(int conn)
buf[3] == ' ' && buf[3] == ' ' &&
buf[4] == '/' ) { buf[4] == '/' ) {
log("Will send response"); Genode::log("Will send response");
/* Send http header */
lwip_send(conn, http_html_hdr, Genode::strlen(http_html_hdr), 0);
/* Send our HTML page */ /* Send our HTML page */
lwip_send(conn, http_index_html, Genode::strlen(http_index_html), 0); lwip_send(conn, response.string(), response.length(), 0);
} }
} }
} }
struct Initialization_failed {};
template <Genode::size_t N> #define ASSERT(cond, err) \
static Genode::String<N> read_string_attribute(Genode::Xml_node node, char const *attr, if (!cond) { \
Genode::String<N> default_value) Genode::error(err); \
{ throw Initialization_failed(); \
try {
char buf[N];
node.attribute(attr).value(buf, sizeof(buf));
return Genode::String<N>(Genode::Cstring(buf));
} }
catch (...) {
return default_value; }
}
void Libc::Component::construct(Libc::Env & env)
int main()
{ {
using namespace Genode; using namespace Genode;
using Address = Genode::String<16>;
enum { BUF_SIZE = Nic::Packet_allocator::DEFAULT_PACKET_SIZE * 128 }; enum { BUF_SIZE = Nic::Packet_allocator::DEFAULT_PACKET_SIZE * 128 };
int s;
lwip_tcpip_init(); lwip_tcpip_init();
enum { ADDR_STR_SZ = 16 };
uint32_t ip = 0; uint32_t ip = 0;
uint32_t nm = 0; uint32_t nm = 0;
uint32_t gw = 0; uint32_t gw = 0;
unsigned port = 0; unsigned port = 0;
Xml_node config_node = config()->xml_node(); Address ip_addr_str;
Xml_node libc_node = config_node.sub_node("libc"); Address netmask_str;
String<ADDR_STR_SZ> ip_addr_str = Address gateway_str;
read_string_attribute<ADDR_STR_SZ>(libc_node, "ip_addr", String<ADDR_STR_SZ>());
String<ADDR_STR_SZ> netmask_str =
read_string_attribute<ADDR_STR_SZ>(libc_node, "netmask", String<ADDR_STR_SZ>());
String<ADDR_STR_SZ> gateway_str =
read_string_attribute<ADDR_STR_SZ>(libc_node, "gateway", String<ADDR_STR_SZ>());
try { config_node.attribute("port").value(&port); } Attached_rom_dataspace config(env, "config");
catch(...) { Xml_node libc_node = env.libc_config();
error("Missing \"port\" attribute."); libc_node.attribute("ip_addr").value(&ip_addr_str);
throw Xml_node::Nonexistent_attribute(); libc_node.attribute("netmask").value(&netmask_str);
} libc_node.attribute("gateway").value(&gateway_str);
config.xml().attribute("port").value(&port);
log("static network interface: ip=", ip_addr_str, " nm=", netmask_str, " gw=", gateway_str); log("static network interface: ip=", ip_addr_str, " nm=", netmask_str, " gw=", gateway_str);
@ -135,48 +109,41 @@ int main()
nm = inet_addr(netmask_str.string()); nm = inet_addr(netmask_str.string());
gw = inet_addr(gateway_str.string()); gw = inet_addr(gateway_str.string());
if (ip == INADDR_NONE || nm == INADDR_NONE || gw == INADDR_NONE) { ASSERT((ip != INADDR_NONE && nm != INADDR_NONE && gw != INADDR_NONE),
error("Invalid network interface config."); "Invalid network interface config.");
throw -1;
}
/* Initialize network stack */ /* Initialize network stack */
if (lwip_nic_init(ip, nm, gw, BUF_SIZE, BUF_SIZE)) { ASSERT(!lwip_nic_init(ip, nm, gw, BUF_SIZE, BUF_SIZE),
error("got no IP address!"); "got no IP address!");
return -1;
}
log("Create new socket ..."); log("Create new socket ...");
if((s = lwip_socket(AF_INET, SOCK_STREAM, 0)) < 0) {
error("no socket available!");
return -1;
}
Genode::snprintf( int s;
http_index_html, HTTP_INDEX_HTML_SZ, ASSERT(((s = lwip_socket(AF_INET, SOCK_STREAM, 0)) >= 0),
"no socket available!");
static Response response(
"HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n"
"<html><head></head><body>" "<html><head></head><body>"
"<h1>HTTP server at %s:%u</h1>" "<h1>HTTP server at %s:%u</h1>"
"<p>This is a small test page.</body></html>", "<p>This is a small test page.</body></html>",
ip_addr_str.string(), port); ip_addr_str.string(), port);
log("Now, I will bind ..."); log("Now, I will bind ...");
struct sockaddr_in in_addr; struct sockaddr_in in_addr;
in_addr.sin_family = AF_INET; in_addr.sin_family = AF_INET;
in_addr.sin_port = htons(port); in_addr.sin_port = htons(port);
in_addr.sin_addr.s_addr = INADDR_ANY; in_addr.sin_addr.s_addr = INADDR_ANY;
if(lwip_bind(s, (struct sockaddr*)&in_addr, sizeof(in_addr))) { ASSERT(!lwip_bind(s, (struct sockaddr*)&in_addr, sizeof(in_addr)),
error("bind failed!"); "bind failed!");
return -1;
}
log("Now, I will listen ..."); log("Now, I will listen ...");
if(lwip_listen(s, 5)) { ASSERT(!lwip_listen(s, 5),
error("listen failed!"); "listen failed!");
return -1;
}
log("Start the server loop ..."); log("Start the server loop ...");
while(true) { while (true) {
struct sockaddr addr; struct sockaddr addr;
socklen_t len = sizeof(addr); socklen_t len = sizeof(addr);
int client = lwip_accept(s, &addr, &len); int client = lwip_accept(s, &addr, &len);
@ -184,8 +151,7 @@ int main()
warning("invalid socket from accept!"); warning("invalid socket from accept!");
continue; continue;
} }
http_server_serve(client); http_server_serve(client, response);
lwip_close(client); lwip_close(client);
} }
return 0;
} }

View File

@ -1,5 +1,5 @@
TARGET = test-lwip_httpsrv_static TARGET = test-lwip_httpsrv_static
LIBS = lwip posix config LIBS = lwip posix
SRC_CC = main.cc SRC_CC = main.cc
INC_DIR += $(REP_DIR)/src/lib/lwip/include INC_DIR += $(REP_DIR)/src/lib/lwip/include

View File

@ -16,7 +16,6 @@
/* Genode includes */ /* Genode includes */
#include <base/log.h> #include <base/log.h>
#include <os/config.h>
/* libc includes */ /* libc includes */
#include <fcntl.h> #include <fcntl.h>
@ -24,39 +23,18 @@
extern "C" int __sread(void *, char *, int); extern "C" int __sread(void *, char *, int);
static bool process_config(char **file)
{
using namespace Genode;
static char file_name[64];
try { int main(int argc, char const ** args)
Xml_node config_node = config()->xml_node();
Xml_node script_node = config_node.sub_node("script");
script_node.attribute("name").value(file_name, sizeof(file_name));
*file = file_name;
return true;
}
catch (Xml_node::Nonexistent_sub_node) {
Genode::error("no 'config/script' sub node in config found"); }
catch (Xml_node::Nonexistent_attribute) {
Genode::error("no 'name' attribute in 'script' node found"); }
return false;
}
int main()
{ {
using namespace Genode; using namespace Genode;
char *name; if (argc < 1) {
if (!process_config(&name)) { Genode::error("Need <scriptname>.py as argument!");
Genode::error("no script found"); return -1;
return 1;
} }
Genode::log("Found script: ", Genode::Cstring(name)); char * name = const_cast<char*>(args[0]);
FILE* fp = fopen(name, "r"); FILE * fp = fopen(name, "r");
//fp._flags = __SRD; //fp._flags = __SRD;
Py_SetProgramName(name); Py_SetProgramName(name);
//don't need the 'site' module //don't need the 'site' module

View File

@ -1,72 +0,0 @@
/*
* \brief Access to process configuration
* \author Norman Feske
* \date 2010-05-04
*/
/*
* Copyright (C) 2010-2017 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef INCLUDED_BY_OS_CONFIG_CC
#ifndef INCLUDED_FROM_OS_SESSION_POLICY_H
#warning os/config.h is deprecated, use 'Attached_rom_dataspace' instead
#endif
#endif
#ifndef _INCLUDE__OS__CONFIG_H_
#define _INCLUDE__OS__CONFIG_H_
#include <rom_session/connection.h>
#include <dataspace/client.h>
#include <util/xml_node.h>
#include <base/exception.h>
namespace Genode {
class Config;
/**
* Return singleton instance of config
*/
Reconstructible<Config> &config();
}
class Genode::Config
{
private:
Rom_connection _config_rom;
Dataspace_capability _config_ds;
Xml_node _config_xml;
public:
/**
* Constructor
*/
Config();
Xml_node xml_node();
/**
* Register signal handler for tracking config modifications
*/
void sigh(Signal_context_capability cap);
/**
* Reload configuration
*
* \throw Invalid if the new configuration has an invalid syntax
*
* This method is meant to be called as response to a signal
* received by the signal handler as registered via 'sigh()'.
*/
void reload();
};
#endif /* _INCLUDE__OS__CONFIG_H_ */

View File

@ -14,13 +14,10 @@
#ifndef _INCLUDE__OS__SESSION_POLICY_H_ #ifndef _INCLUDE__OS__SESSION_POLICY_H_
#define _INCLUDE__OS__SESSION_POLICY_H_ #define _INCLUDE__OS__SESSION_POLICY_H_
#include <util/arg_string.h>
#include <base/session_label.h> #include <base/session_label.h>
#include <session/session.h>
/* to be removed along with the \deprecated API */ #include <util/arg_string.h>
#define INCLUDED_FROM_OS_SESSION_POLICY_H #include <util/xml_node.h>
#include <os/config.h>
#undef INCLUDED_FROM_OS_SESSION_POLICY_H
namespace Genode { namespace Genode {
@ -229,20 +226,6 @@ class Genode::Session_policy : public Xml_node
: :
Xml_node(_query_policy(label, config)) Xml_node(_query_policy(label, config))
{ } { }
/**
* Constructor
*
* \param label label used as the selector of a policy
*
* \deprecated use constructor with explicit 'config' argument
*/
template <size_t N> explicit Session_policy(String<N> const &label) __attribute__((deprecated));
}; };
template <Genode::size_t N> Genode::Session_policy::Session_policy(String<N> const &label)
:
Xml_node(_query_policy(label, Genode::config()->xml_node()))
{ }
#endif /* _INCLUDE__OS__SESSION_POLICY_H_ */ #endif /* _INCLUDE__OS__SESSION_POLICY_H_ */

View File

@ -1,3 +0,0 @@
SRC_CC = config.cc
vpath config.cc $(REP_DIR)/src/lib/config

View File

@ -1,4 +1,4 @@
LIBS += base config LIBS += base
SRC_CC += serial_driver.cc block_driver.cc vm_base.cc spec/imx53/main.cc SRC_CC += serial_driver.cc block_driver.cc vm_base.cc spec/imx53/main.cc
INC_DIR += $(REP_DIR)/src/server/tz_vmm/spec/imx53 INC_DIR += $(REP_DIR)/src/server/tz_vmm/spec/imx53
INC_DIR += $(REP_DIR)/src/server/tz_vmm/include INC_DIR += $(REP_DIR)/src/server/tz_vmm/include

View File

@ -7,7 +7,7 @@
TARGET = fb_drv TARGET = fb_drv
REQUIRES = omap4 REQUIRES = omap4
SRC_CC = main.cc SRC_CC = main.cc
LIBS = base blit config LIBS = base blit
INC_DIR += $(PRG_DIR) INC_DIR += $(PRG_DIR)
vpath main.cc $(PRG_DIR) vpath main.cc $(PRG_DIR)

View File

@ -1,5 +1,5 @@
REQUIRES = cadence_gem REQUIRES = cadence_gem
TARGET = nic_drv TARGET = nic_drv
SRC_CC = main.cc SRC_CC = main.cc
LIBS = base config LIBS = base
INC_DIR += $(PRG_DIR) INC_DIR += $(PRG_DIR)

View File

@ -1,4 +1,4 @@
TARGET = linux_nic_drv TARGET = linux_nic_drv
REQUIRES = linux REQUIRES = linux
LIBS = lx_hybrid config LIBS = lx_hybrid
SRC_CC = main.cc SRC_CC = main.cc

View File

@ -1,6 +1,6 @@
TARGET = kdb_uart_drv TARGET = kdb_uart_drv
SRC_CC = main.cc SRC_CC = main.cc
LIBS += base config LIBS += base
INC_DIR += $(REP_DIR)/src/drivers/uart $(REP_DIR)/src/drivers/uart/kdb INC_DIR += $(REP_DIR)/src/drivers/uart $(REP_DIR)/src/drivers/uart/kdb
vpath main.cc $(REP_DIR)/src/drivers/uart vpath main.cc $(REP_DIR)/src/drivers/uart

View File

@ -1,107 +0,0 @@
/*
* \brief Access to process configuration
* \author Norman Feske
* \date 2010-05-04
*
* \deprecated
*/
/*
* Copyright (C) 2010-2017 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#define INCLUDED_BY_OS_CONFIG_CC
#include <os/config.h>
#undef INCLUDED_BY_OS_CONFIG_CC
using namespace Genode;
Xml_node _config_xml_node(Dataspace_capability config_ds)
{
if (!config_ds.valid())
throw Exception();
return Xml_node(env_deprecated()->rm_session()->attach(config_ds),
Genode::Dataspace_client(config_ds).size());
}
/**
* Fallback XML node used if the configuration is broken
*/
static Xml_node fallback_config_xml()
{
return Xml_node("<config/>");
}
void Config::reload()
{
if (!this)
return;
try {
/* re-acquire dataspace from ROM session */
if (_config_ds.valid())
env_deprecated()->rm_session()->detach(_config_xml.addr());
_config_ds = _config_rom.dataspace();
/* re-initialize XML node with new config data */
_config_xml = _config_xml_node(_config_ds);
} catch (Genode::Xml_node::Invalid_syntax) {
Genode::error("config ROM has invalid syntax");
_config_xml = fallback_config_xml();
}
}
Xml_node Config::xml_node()
{
if (!this)
return fallback_config_xml();
return _config_xml;
}
void Config::sigh(Signal_context_capability cap)
{
if (this)
_config_rom.sigh(cap);
}
Config::Config()
:
_config_rom(false, "config"),
_config_ds(_config_rom.dataspace()),
_config_xml(_config_xml_node(_config_ds))
{ }
Reconstructible<Config> &Genode::config()
{
static bool config_failed = false;
if (!config_failed) {
try {
static Reconstructible<Config> config_inst;
return config_inst;
} catch (Genode::Rom_connection::Rom_connection_failed) {
Genode::error("Could not obtain config file");
} catch (Genode::Xml_node::Invalid_syntax) {
Genode::error("Config file has invalid syntax");
} catch(...) {
Genode::error("Config dataspace is invalid");
}
}
/* do not try again to construct 'config_inst' */
config_failed = true;
class Config_construction_failed : Genode::Exception { };
throw Config_construction_failed();
}

View File

@ -1,6 +1,6 @@
TARGET = nic_dump TARGET = nic_dump
LIBS += base net config LIBS += base net
SRC_CC += component.cc main.cc uplink.cc interface.cc SRC_CC += component.cc main.cc uplink.cc interface.cc

View File

@ -1,6 +1,6 @@
TARGET = nic_router TARGET = nic_router
LIBS += base net config LIBS += base net
SRC_CC += arp_waiter.cc ip_rule.cc SRC_CC += arp_waiter.cc ip_rule.cc
SRC_CC += component.cc port_allocator.cc forward_rule.cc SRC_CC += component.cc port_allocator.cc forward_rule.cc

View File

@ -1,3 +1,3 @@
TARGET = part_blk TARGET = part_blk
LIBS = base config LIBS = base
SRC_CC = main.cc SRC_CC = main.cc

View File

@ -1,4 +1,4 @@
TARGET = trace_fs TARGET = trace_fs
SRC_CC = main.cc SRC_CC = main.cc
LIBS = base config LIBS = base
INC_DIR += $(PRG_DIR) INC_DIR += $(PRG_DIR)

View File

@ -1,3 +1,3 @@
TARGET = test-audio_out TARGET = test-audio_out
SRC_CC = main.cc SRC_CC = main.cc
LIBS = base config LIBS = base

View File

@ -1,3 +1,3 @@
TARGET = test-audio_out_click TARGET = test-audio_out_click
SRC_CC = main.cc SRC_CC = main.cc
LIBS = base config LIBS = base

View File

@ -1,3 +1,3 @@
TARGET = bomb TARGET = bomb
SRC_CC = main.cc SRC_CC = main.cc
LIBS = base config LIBS = base

View File

@ -1,3 +1,3 @@
TARGET = test-dynamic_config TARGET = test-dynamic_config
SRC_CC = main.cc SRC_CC = main.cc
LIBS = base config LIBS = base

View File

@ -1,6 +1,6 @@
TARGET = led_gpio_drv TARGET = led_gpio_drv
REQUIRES = gpio REQUIRES = gpio
SRC_CC = main.cc SRC_CC = main.cc
LIBS = base config LIBS = base
vpath main.cc $(PRG_DIR) vpath main.cc $(PRG_DIR)

View File

@ -2,6 +2,6 @@ TARGET = signal_gpio_drv
REQUIRES = gpio REQUIRES = gpio
SRC_CC = main.cc SRC_CC = main.cc
INC_DIR += $(PRG_DIR) INC_DIR += $(PRG_DIR)
LIBS = base config LIBS = base
vpath main.cc $(PRG_DIR) vpath main.cc $(PRG_DIR)

View File

@ -1,3 +1,3 @@
TARGET = test-resource_yield TARGET = test-resource_yield
SRC_CC = main.cc SRC_CC = main.cc
LIBS = base config LIBS = base

View File

@ -1,3 +1,3 @@
TARGET = test-rom_blk TARGET = test-rom_blk
SRC_CC = main.cc SRC_CC = main.cc
LIBS = base config LIBS = base

View File

@ -1,3 +1,3 @@
TARGET = test-trace TARGET = test-trace
SRC_CC = main.cc SRC_CC = main.cc
LIBS += base config LIBS += base

View File

@ -14,7 +14,7 @@
/* Genode includes */ /* Genode includes */
#include <base/env.h> #include <base/env.h>
#include <os/config.h> #include <base/attached_rom_dataspace.h>
/* GDB monitor includes */ /* GDB monitor includes */
#include "app_child.h" #include "app_child.h"
@ -443,8 +443,9 @@ extern "C" int fork()
static char filename[32] = ""; static char filename[32] = "";
Genode::Attached_rom_dataspace config { *genode_env, "config" };
try { try {
config()->xml_node().sub_node("target").attribute("name").value(filename, sizeof(filename)); config.xml().sub_node("target").attribute("name").value(filename, sizeof(filename));
} catch (Xml_node::Nonexistent_sub_node) { } catch (Xml_node::Nonexistent_sub_node) {
error("missing '<target>' sub node"); error("missing '<target>' sub node");
return -1; return -1;
@ -454,7 +455,7 @@ extern "C" int fork()
} }
/* extract target node from config file */ /* extract target node from config file */
Xml_node target_node = config()->xml_node().sub_node("target"); Xml_node target_node = config.xml().sub_node("target");
/* /*
* preserve the configured amount of memory for gdb_monitor and give the * preserve the configured amount of memory for gdb_monitor and give the
@ -462,7 +463,7 @@ extern "C" int fork()
*/ */
Number_of_bytes preserved_ram_quota = 0; Number_of_bytes preserved_ram_quota = 0;
try { try {
Xml_node preserve_node = config()->xml_node().sub_node("preserve"); Xml_node preserve_node = config.xml().sub_node("preserve");
if (preserve_node.attribute("name").has_value("RAM")) if (preserve_node.attribute("name").has_value("RAM"))
preserve_node.attribute("quantum").value(&preserved_ram_quota); preserve_node.attribute("quantum").value(&preserved_ram_quota);
else else

View File

@ -1,3 +1,3 @@
TARGET = vbox_pointer TARGET = vbox_pointer
SRC_CC = main.cc policy.cc SRC_CC = main.cc policy.cc
LIBS += base config LIBS += base

View File

@ -12,20 +12,17 @@
*/ */
/* Genode includes */ /* Genode includes */
#include <os/config.h> #include <base/attached_rom_dataspace.h>
#include <base/component.h>
#include <base/log.h>
using namespace Genode; void Component::construct(Genode::Env & env)
int main(void)
{ {
Genode::Attached_rom_dataspace config(env, "config");
try { try {
config()->xml_node().sub_node("test_config_subnode"); config.xml().sub_node("test_config_subnode");
} catch (Xml_node::Nonexistent_sub_node) { Genode::log("Test succeeded");
error("missing '<test_config_subnode>' sub node"); } catch (Genode::Xml_node::Nonexistent_sub_node) {
return -1; Genode::error("missing '<test_config_subnode>' sub node");
} }
log("Test succeeded");
return 0;
} }

View File

@ -1,3 +1,3 @@
TARGET = test-gdb_monitor_target_config TARGET = test-gdb_monitor_target_config
SRC_CC = main.cc SRC_CC = main.cc
LIBS = base config LIBS = base

View File

@ -1,3 +1,3 @@
TARGET = test-vbox_pointer TARGET = test-vbox_pointer
SRC_CC = main.cc SRC_CC = main.cc
LIBS = base config LIBS = base