From 18504b4801d0e60ee9eebbc8fcecc4e84902f128 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Tue, 3 Jan 2017 15:28:09 +0100 Subject: [PATCH] merge lib/config_args with lib/posix Merging the config_args library with the POSIX library supplies 'argc' and 'argv' arguments to components using a 'main' entry. Fix #2218 Ref #1987 --- repos/libports/src/app/avplay/target.mk | 2 +- repos/libports/src/lib/posix/construct.cc | 43 +++++++++++- .../lwip/pingpong/client/libc_lwip/target.mk | 2 +- .../test/lwip/pingpong/client/lwip/target.mk | 2 +- .../test/lwip/pingpong/server/lwip/target.mk | 2 +- repos/os/lib/mk/config_args.mk | 5 -- repos/os/run/config_args.run | 2 +- repos/os/src/lib/config_args/config_args.cc | 70 ------------------- repos/os/src/test/config_args/target.mk | 2 +- repos/ports/src/app/dosbox/target.mk | 2 +- repos/ports/src/app/lighttpd/target.inc | 2 +- repos/ports/src/app/netperf/target.inc | 2 - 12 files changed, 50 insertions(+), 86 deletions(-) delete mode 100644 repos/os/lib/mk/config_args.mk delete mode 100644 repos/os/src/lib/config_args/config_args.cc diff --git a/repos/libports/src/app/avplay/target.mk b/repos/libports/src/app/avplay/target.mk index b841a2cc67..62cf1f6875 100644 --- a/repos/libports/src/app/avplay/target.mk +++ b/repos/libports/src/app/avplay/target.mk @@ -3,7 +3,7 @@ include $(REP_DIR)/lib/import/import-av.inc TARGET = avplay SRC_C = avplay.c cmdutils.c libc_dummies.c LIBS += avfilter avformat avcodec avutil avresample swscale -LIBS += sdl posix config_args +LIBS += sdl posix CC_WARN += -Wno-parentheses -Wno-switch -Wno-uninitialized \ -Wno-format-zero-length -Wno-pointer-sign diff --git a/repos/libports/src/lib/posix/construct.cc b/repos/libports/src/lib/posix/construct.cc index 8005e39e67..80cd99f719 100644 --- a/repos/libports/src/lib/posix/construct.cc +++ b/repos/libports/src/lib/posix/construct.cc @@ -15,7 +15,8 @@ #include /* libc includes */ -#include /* for 'exit' */ +#include /* 'malloc' */ +#include /* 'exit' */ extern char **genode_argv; extern int genode_argc; @@ -28,5 +29,45 @@ extern "C" int main(int argc, char ** argv, char **envp); void Libc::Component::construct(Libc::Env &env) { + using Genode::Xml_node; + using Genode::Xml_attribute; + + env.config([&] (Xml_node const &node) { + int argc = 0; + static char **argv; + + /* count the number of arguments */ + node.for_each_sub_node("arg", [&] (Xml_node const &arg_node) { + /* check if the 'value' attribute exists */ + if (arg_node.has_attribute("value")) + ++argc; + }); + + if (argc == 0) + return; + + argv = (char**)malloc((argc + 1) * sizeof(char*)); + + /* read the arguments */ + int i = 0; + node.for_each_sub_node("arg", [&] (Xml_node const &arg_node) { + try { + Xml_attribute attr = arg_node.attribute("value"); + Genode::size_t const arg_len = attr.value_size()+1; + argv[i] = (char*)malloc(arg_len); + attr.value(argv[i], arg_len); + ++i; + } catch (Xml_node::Nonexistent_sub_node) { } + }); + + argv[i] = nullptr; + + /* register command-line arguments at Genode's startup code */ + genode_argc = argc; + genode_argv = argv; + }); + + /* TODO: environment variables, see #2236 */ + exit(main(genode_argc, genode_argv, genode_envp)); } diff --git a/repos/libports/src/test/lwip/pingpong/client/libc_lwip/target.mk b/repos/libports/src/test/lwip/pingpong/client/libc_lwip/target.mk index bd5879f83f..6e75a869b6 100644 --- a/repos/libports/src/test/lwip/pingpong/client/libc_lwip/target.mk +++ b/repos/libports/src/test/lwip/pingpong/client/libc_lwip/target.mk @@ -1,5 +1,5 @@ TARGET = test-ping_client_libc_lwip -LIBS = posix lwip libc_lwip_nic_dhcp config_args +LIBS = posix lwip libc_lwip_nic_dhcp SRC_CC = main.cc pingpong.cc vpath main.cc $(PRG_DIR)/.. diff --git a/repos/libports/src/test/lwip/pingpong/client/lwip/target.mk b/repos/libports/src/test/lwip/pingpong/client/lwip/target.mk index 095ab47a83..5ab89936d7 100644 --- a/repos/libports/src/test/lwip/pingpong/client/lwip/target.mk +++ b/repos/libports/src/test/lwip/pingpong/client/lwip/target.mk @@ -1,5 +1,5 @@ TARGET = test-ping_client_lwip -LIBS = posix lwip config_args +LIBS = posix lwip SRC_CC = main.cc pingpong.cc INC_DIR += $(REP_DIR)/src/lib/lwip/include diff --git a/repos/libports/src/test/lwip/pingpong/server/lwip/target.mk b/repos/libports/src/test/lwip/pingpong/server/lwip/target.mk index d74eef17ae..9b803fd114 100644 --- a/repos/libports/src/test/lwip/pingpong/server/lwip/target.mk +++ b/repos/libports/src/test/lwip/pingpong/server/lwip/target.mk @@ -1,5 +1,5 @@ TARGET = test-ping_server_lwip -LIBS = posix lwip config_args +LIBS = posix lwip SRC_CC = main.cc pingpong.cc CC_OPT += -DLWIP_NATIVE diff --git a/repos/os/lib/mk/config_args.mk b/repos/os/lib/mk/config_args.mk deleted file mode 100644 index 3f8f4d64b2..0000000000 --- a/repos/os/lib/mk/config_args.mk +++ /dev/null @@ -1,5 +0,0 @@ -SRC_CC = config_args.cc - -LIBS += config - -vpath %.cc $(REP_DIR)/src/lib/config_args diff --git a/repos/os/run/config_args.run b/repos/os/run/config_args.run index b42a73b8d2..37c0c73903 100644 --- a/repos/os/run/config_args.run +++ b/repos/os/run/config_args.run @@ -31,7 +31,7 @@ install_config { } -build_boot_image "core ld.lib.so init timer test-config_args" +build_boot_image "core ld.lib.so init timer test-config_args libc.lib.so libm.lib.so" append qemu_args "-nographic -m 64" diff --git a/repos/os/src/lib/config_args/config_args.cc b/repos/os/src/lib/config_args/config_args.cc deleted file mode 100644 index 3188fe22a7..0000000000 --- a/repos/os/src/lib/config_args/config_args.cc +++ /dev/null @@ -1,70 +0,0 @@ -/* - * \brief Read program arguments from the config file - * \date 2012-04-19 - * \author Christian Prochaska - */ - -/* - * Copyright (C) 2012-2013 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. - */ - -#include -#include - -using namespace Genode; - - -/* external symbols provided by Genode's startup code */ -extern char **genode_argv; -extern int genode_argc; - - -__attribute__((constructor)) -void init_config_args(void) -{ - int argc = 0; - static char **argv; - - /* count the number of arguments */ - try { - Xml_node arg_node = config()->xml_node().sub_node("arg"); - for (;;) { - /* check if the 'value' attribute exists */ - arg_node.attribute("value"); - argc++; - arg_node = arg_node.next("arg"); - } - } - catch (Xml_node::Nonexistent_sub_node) { } - catch (Xml_node::Nonexistent_attribute) - { - error(" node has no 'value' attribute, ignoring further nodes"); - } - - if (argc == 0) - return; - - argv = (char**)env()->heap()->alloc((argc + 1) * sizeof(char*)); - - /* read the arguments */ - Xml_node arg_node = config()->xml_node().sub_node("arg"); - try { - for (int i = 0; i < argc; i++) { - static char buf[512]; - arg_node.attribute("value").value(buf, sizeof(buf)); - size_t arg_size = strlen(buf) + 1; - argv[i] = (char*)env()->heap()->alloc(arg_size); - strncpy(argv[i], buf, arg_size); - arg_node = arg_node.next("arg"); - } - } catch (Xml_node::Nonexistent_sub_node) { } - - argv[argc] = 0; - - /* register command-line arguments at Genode's startup code */ - genode_argc = argc; - genode_argv = argv; -} diff --git a/repos/os/src/test/config_args/target.mk b/repos/os/src/test/config_args/target.mk index 4312f6981e..2825277487 100644 --- a/repos/os/src/test/config_args/target.mk +++ b/repos/os/src/test/config_args/target.mk @@ -1,3 +1,3 @@ TARGET = test-config_args SRC_CC = main.cc -LIBS = base config_args +LIBS = posix diff --git a/repos/ports/src/app/dosbox/target.mk b/repos/ports/src/app/dosbox/target.mk index ef09522296..266ed4b110 100644 --- a/repos/ports/src/app/dosbox/target.mk +++ b/repos/ports/src/app/dosbox/target.mk @@ -54,4 +54,4 @@ CC_WARN += -Wno-unused-variable -Wno-unused-function -Wno-switch -Wno-unused-val -Wno-parentheses LIBS += posix libpng sdl sdl_net stdcxx zlib -LIBS += libc_lwip_nic_dhcp config_args +LIBS += libc_lwip_nic_dhcp diff --git a/repos/ports/src/app/lighttpd/target.inc b/repos/ports/src/app/lighttpd/target.inc index bbc86052a0..312d648e6c 100644 --- a/repos/ports/src/app/lighttpd/target.inc +++ b/repos/ports/src/app/lighttpd/target.inc @@ -30,4 +30,4 @@ INC_DIR += $(PRG_DIR) INC_DIR += $(LIGHTTPD_DIR)/src LIBS += posix -LIBS += zlib config_args +LIBS += zlib diff --git a/repos/ports/src/app/netperf/target.inc b/repos/ports/src/app/netperf/target.inc index a37ce61264..45be49193c 100644 --- a/repos/ports/src/app/netperf/target.inc +++ b/repos/ports/src/app/netperf/target.inc @@ -2,8 +2,6 @@ NETPERF_DIR := $(call select_from_ports,netperf)/src/app/netperf LIBS += posix libc-resolv libc-net libc-nameser libc-isc -# plug-in to libc -LIBS += config_args SRC_C = netserver.c netlib.c netsh.c nettest_bsd.c dscp.c # omni test