mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-11 11:51:46 +00:00
Migrate fetchurl to socket_fs
Remove the dependency on the deprecated LwIP libary. Remove the progress logging callback. Should a progress indicator be desired, a progress report would be more appropriate. Fix #2684
This commit is contained in:
parent
5261462d7a
commit
e1f7dd0553
@ -1,45 +1,10 @@
|
|||||||
MIRROR_FROM_REP_DIR := src/app/fetchurl
|
MIRROR_FROM_REP_DIR := src/app/fetchurl
|
||||||
|
|
||||||
#
|
content: $(MIRROR_FROM_REP_DIR) LICENSE
|
||||||
# Copy of lwIP ingredients
|
|
||||||
#
|
|
||||||
MIRROR_FROM_REP_DIR += include/libc-plugin \
|
|
||||||
src/lib/libc_lwip \
|
|
||||||
src/lib/libc_lwip_nic_dhcp \
|
|
||||||
lib/mk/lwip.mk \
|
|
||||||
lib/mk/libc_lwip.mk \
|
|
||||||
lib/mk/libc_lwip_nic_dhcp.mk \
|
|
||||||
lib/import/import-lwip.mk
|
|
||||||
|
|
||||||
|
|
||||||
LWIP_PORT_DIR := $(call port_dir,$(REP_DIR)/ports/lwip)
|
|
||||||
|
|
||||||
content: $(MIRROR_FROM_REP_DIR) LICENSE include/lwip src/lib/lwip
|
|
||||||
|
|
||||||
include/lwip:
|
|
||||||
mkdir -p $@
|
|
||||||
cp -r $(LWIP_PORT_DIR)/include/lwip/* $@
|
|
||||||
cp -r $(REP_DIR)/include/lwip/* $@
|
|
||||||
|
|
||||||
src/lib/lwip:
|
|
||||||
mkdir -p $@
|
|
||||||
cp -r $(LWIP_PORT_DIR)/src/lib/lwip/* $@
|
|
||||||
cp -r $(REP_DIR)/src/lib/lwip/* $@
|
|
||||||
|
|
||||||
$(MIRROR_FROM_REP_DIR):
|
$(MIRROR_FROM_REP_DIR):
|
||||||
$(mirror_from_rep_dir)
|
$(mirror_from_rep_dir)
|
||||||
|
|
||||||
MIRROR_FROM_OS := lib/mk/timed_semaphore.mk \
|
|
||||||
include/os/timed_semaphore.h \
|
|
||||||
src/lib/timed_semaphore
|
|
||||||
|
|
||||||
content: $(MIRROR_FROM_OS)
|
|
||||||
|
|
||||||
$(MIRROR_FROM_OS):
|
|
||||||
mkdir -p $(dir $@)
|
|
||||||
cp -r $(GENODE_DIR)/repos/os/$@ $(dir $@)
|
|
||||||
|
|
||||||
LICENSE:
|
LICENSE:
|
||||||
cp $(GENODE_DIR)/LICENSE $@
|
cp $(GENODE_DIR)/LICENSE $@
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,10 +5,11 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
set build_components {
|
set build_components {
|
||||||
core init
|
|
||||||
app/fetchurl
|
app/fetchurl
|
||||||
|
core init
|
||||||
drivers/nic
|
drivers/nic
|
||||||
drivers/timer
|
drivers/timer
|
||||||
|
lib/vfs/lxip
|
||||||
}
|
}
|
||||||
|
|
||||||
source ${genode_dir}/repos/base/run/platform_drv.inc
|
source ${genode_dir}/repos/base/run/platform_drv.inc
|
||||||
@ -19,7 +20,7 @@ build $build_components
|
|||||||
create_boot_directory
|
create_boot_directory
|
||||||
|
|
||||||
append config {
|
append config {
|
||||||
<config verbose="yes">
|
<config>
|
||||||
<parent-provides>
|
<parent-provides>
|
||||||
<service name="CPU"/>
|
<service name="CPU"/>
|
||||||
<service name="IO_MEM"/>
|
<service name="IO_MEM"/>
|
||||||
@ -49,14 +50,18 @@ append config {
|
|||||||
<provides> <service name="Nic"/> </provides>
|
<provides> <service name="Nic"/> </provides>
|
||||||
</start>
|
</start>
|
||||||
<start name="fetchurl" caps="500">
|
<start name="fetchurl" caps="500">
|
||||||
<resource name="RAM" quantum="8M"/>
|
<resource name="RAM" quantum="32M"/>
|
||||||
<config>
|
<config>
|
||||||
<vfs>
|
<vfs>
|
||||||
|
<dir name="etc">
|
||||||
|
<inline name="resolv.conf">nameserver 213.73.91.35</inline>
|
||||||
|
</dir>
|
||||||
<dir name="dev">
|
<dir name="dev">
|
||||||
<log/> <null/> <inline name="rtc">2000-01-01 00:00</inline>
|
<log/> <null/> <inline name="rtc">2000-01-01 00:00</inline>
|
||||||
</dir>
|
</dir>
|
||||||
|
<dir name="socket"> <lxip dhcp="yes"/> </dir>
|
||||||
</vfs>
|
</vfs>
|
||||||
<libc stdout="/dev/log" stderr="/dev/log" rtc="/dev/rtc"/>
|
<libc stdout="/dev/log" stderr="/dev/log" rtc="/dev/rtc" socket="/socket"/>
|
||||||
<fetch url="http://genode.org/about/LICENSE" path="/dev/log"/>
|
<fetch url="http://genode.org/about/LICENSE" path="/dev/log"/>
|
||||||
</config>
|
</config>
|
||||||
</start>
|
</start>
|
||||||
@ -74,11 +79,12 @@ set boot_modules {
|
|||||||
libcrypto.lib.so
|
libcrypto.lib.so
|
||||||
libssh.lib.so
|
libssh.lib.so
|
||||||
libssl.lib.so
|
libssl.lib.so
|
||||||
lwip.lib.so
|
lxip.lib.so
|
||||||
nic_drv
|
nic_drv
|
||||||
timer
|
|
||||||
zlib.lib.so
|
|
||||||
pthread.lib.so
|
pthread.lib.so
|
||||||
|
timer
|
||||||
|
vfs_lxip.lib.so
|
||||||
|
zlib.lib.so
|
||||||
}
|
}
|
||||||
|
|
||||||
# platform-specific modules
|
# platform-specific modules
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2016 Genode Labs GmbH
|
* Copyright (C) 2016-2018 Genode Labs GmbH
|
||||||
*
|
*
|
||||||
* This file is part of the Genode OS framework, which is distributed
|
* This file is part of the Genode OS framework, which is distributed
|
||||||
* under the terms of the GNU Affero General Public License version 3.
|
* under the terms of the GNU Affero General Public License version 3.
|
||||||
@ -27,16 +27,6 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
struct Stats
|
|
||||||
{
|
|
||||||
Timer::Connection &timer;
|
|
||||||
unsigned long next = 0;
|
|
||||||
unsigned long remain = 0;
|
|
||||||
char const *url;
|
|
||||||
|
|
||||||
Stats(Timer::Connection &t, char const *u)
|
|
||||||
: timer(t), url(u) { }
|
|
||||||
};
|
|
||||||
|
|
||||||
static size_t write_callback(char *ptr,
|
static size_t write_callback(char *ptr,
|
||||||
size_t size,
|
size_t size,
|
||||||
@ -48,47 +38,20 @@ static size_t write_callback(char *ptr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int progress_callback(void *clientp,
|
static int fetchurl(Genode::Xml_node config_node)
|
||||||
double dltotal,
|
|
||||||
double dlnow,
|
|
||||||
double ultotal,
|
|
||||||
double ulnow)
|
|
||||||
{
|
{
|
||||||
Stats *stats = (Stats*)clientp;
|
|
||||||
|
|
||||||
unsigned long now = stats->timer.elapsed_ms();
|
|
||||||
unsigned long remain = dltotal-dlnow;
|
|
||||||
|
|
||||||
if ((now > stats->next) && (remain != stats->remain)) {
|
|
||||||
stats->next = now + 1000;
|
|
||||||
stats->remain = remain;
|
|
||||||
Genode::log(stats->url, ": ", remain, " bytes remain");
|
|
||||||
}
|
|
||||||
return CURLE_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Libc::Component::construct(Libc::Env &env)
|
|
||||||
{
|
|
||||||
Genode::Attached_rom_dataspace config(env, "config");
|
|
||||||
|
|
||||||
Timer::Connection timer(env);
|
|
||||||
|
|
||||||
/* wait for DHCP */
|
|
||||||
timer.msleep(4000);
|
|
||||||
|
|
||||||
Genode::String<256> url;
|
Genode::String<256> url;
|
||||||
Genode::Path<256> path;
|
Genode::Path<256> path;
|
||||||
CURLcode res = CURLE_OK;
|
CURLcode res = CURLE_OK;
|
||||||
|
|
||||||
Libc::with_libc([&]() { curl_global_init(CURL_GLOBAL_DEFAULT); });
|
Libc::with_libc([&]() { curl_global_init(CURL_GLOBAL_DEFAULT); });
|
||||||
|
|
||||||
Genode::Xml_node config_node = config.xml();
|
|
||||||
|
|
||||||
bool verbose = config_node.attribute_value("verbose", false);
|
bool verbose = config_node.attribute_value("verbose", false);
|
||||||
|
|
||||||
config_node.for_each_sub_node("fetch", [&] (Genode::Xml_node node) {
|
config_node.for_each_sub_node("fetch", [&] (Genode::Xml_node node) {
|
||||||
|
|
||||||
if (res != CURLE_OK) return;
|
if (res != CURLE_OK) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
node.attribute("url").value(&url);
|
node.attribute("url").value(&url);
|
||||||
node.attribute("path").value(path.base(), path.capacity());
|
node.attribute("path").value(path.base(), path.capacity());
|
||||||
@ -141,8 +104,8 @@ void Libc::Component::construct(Libc::Env &env)
|
|||||||
default:
|
default:
|
||||||
Genode::error("creation of ", out_path, " failed (errno=", errno, ")");
|
Genode::error("creation of ", out_path, " failed (errno=", errno, ")");
|
||||||
}
|
}
|
||||||
env.parent().exit(errno);
|
res = CURLE_FAILED_INIT;
|
||||||
throw Genode::Exception();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CURL *curl = curl_easy_init();
|
CURL *curl = curl_easy_init();
|
||||||
@ -152,8 +115,6 @@ void Libc::Component::construct(Libc::Env &env)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Stats stats(timer, url.string());
|
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, url.string());
|
curl_easy_setopt(curl, CURLOPT_URL, url.string());
|
||||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true);
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true);
|
||||||
|
|
||||||
@ -163,9 +124,7 @@ void Libc::Component::construct(Libc::Env &env)
|
|||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &fd);
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &fd);
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
|
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
|
||||||
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &stats);
|
|
||||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
|
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
||||||
@ -192,7 +151,14 @@ void Libc::Component::construct(Libc::Env &env)
|
|||||||
|
|
||||||
Genode::warning("SSL certificates not verified");
|
Genode::warning("SSL certificates not verified");
|
||||||
|
|
||||||
env.parent().exit(res ^ CURLE_OK);
|
return res ^ CURLE_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Libc::Component::construct(Libc::Env &env)
|
||||||
|
{
|
||||||
|
env.config([&env] (Genode::Xml_node config) {
|
||||||
|
env.parent().exit( fetchurl(config) );
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* dummies to prevent warnings printed by unimplemented libc functions */
|
/* dummies to prevent warnings printed by unimplemented libc functions */
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
TARGET = fetchurl
|
TARGET = fetchurl
|
||||||
LIBS += curl lwip libc_lwip libc_lwip_nic_dhcp libc ld pthread
|
LIBS += curl libc ld pthread
|
||||||
SRC_CC = component.cc
|
SRC_CC = component.cc
|
||||||
|
|
||||||
CC_CXX_WARN_STRICT =
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user