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:
Emery Hemingway 2018-02-15 12:01:30 +01:00 committed by Christian Helmuth
parent 5261462d7a
commit e1f7dd0553
4 changed files with 29 additions and 94 deletions

View File

@ -1,45 +1,10 @@
MIRROR_FROM_REP_DIR := src/app/fetchurl
#
# 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/* $@
content: $(MIRROR_FROM_REP_DIR) LICENSE
$(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:
cp $(GENODE_DIR)/LICENSE $@

View File

@ -5,10 +5,11 @@
#
set build_components {
core init
app/fetchurl
core init
drivers/nic
drivers/timer
lib/vfs/lxip
}
source ${genode_dir}/repos/base/run/platform_drv.inc
@ -19,7 +20,7 @@ build $build_components
create_boot_directory
append config {
<config verbose="yes">
<config>
<parent-provides>
<service name="CPU"/>
<service name="IO_MEM"/>
@ -49,14 +50,18 @@ append config {
<provides> <service name="Nic"/> </provides>
</start>
<start name="fetchurl" caps="500">
<resource name="RAM" quantum="8M"/>
<resource name="RAM" quantum="32M"/>
<config>
<vfs>
<dir name="etc">
<inline name="resolv.conf">nameserver 213.73.91.35</inline>
</dir>
<dir name="dev">
<log/> <null/> <inline name="rtc">2000-01-01 00:00</inline>
</dir>
<dir name="socket"> <lxip dhcp="yes"/> </dir>
</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"/>
</config>
</start>
@ -74,11 +79,12 @@ set boot_modules {
libcrypto.lib.so
libssh.lib.so
libssl.lib.so
lwip.lib.so
lxip.lib.so
nic_drv
timer
zlib.lib.so
pthread.lib.so
timer
vfs_lxip.lib.so
zlib.lib.so
}
# platform-specific modules

View File

@ -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
* under the terms of the GNU Affero General Public License version 3.
@ -27,16 +27,6 @@
#include <errno.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,
size_t size,
@ -48,47 +38,20 @@ static size_t write_callback(char *ptr,
}
int progress_callback(void *clientp,
double dltotal,
double dlnow,
double ultotal,
double ulnow)
static int fetchurl(Genode::Xml_node config_node)
{
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::Path<256> path;
CURLcode res = CURLE_OK;
Libc::with_libc([&]() { curl_global_init(CURL_GLOBAL_DEFAULT); });
Genode::Xml_node config_node = config.xml();
bool verbose = config_node.attribute_value("verbose", false);
config_node.for_each_sub_node("fetch", [&] (Genode::Xml_node node) {
if (res != CURLE_OK) return;
try {
node.attribute("url").value(&url);
node.attribute("path").value(path.base(), path.capacity());
@ -141,8 +104,8 @@ void Libc::Component::construct(Libc::Env &env)
default:
Genode::error("creation of ", out_path, " failed (errno=", errno, ")");
}
env.parent().exit(errno);
throw Genode::Exception();
res = CURLE_FAILED_INIT;
return;
}
CURL *curl = curl_easy_init();
@ -152,8 +115,6 @@ void Libc::Component::construct(Libc::Env &env)
return;
}
Stats stats(timer, url.string());
curl_easy_setopt(curl, CURLOPT_URL, url.string());
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_WRITEDATA, &fd);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &stats);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 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");
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 */

View File

@ -1,5 +1,3 @@
TARGET = fetchurl
LIBS += curl lwip libc_lwip libc_lwip_nic_dhcp libc ld pthread
LIBS += curl libc ld pthread
SRC_CC = component.cc
CC_CXX_WARN_STRICT =