remove native 'snprintf' calls, improve test coverage
- Replace all native 'snprintf' calls with 'Genode::String'. - Fix ram quotas and libc configs in effected run scripts. - Verify bit-perfect output of lz_rom test with rom_verify. Fix #72
This commit is contained in:
committed by
Norman Feske
parent
78046dfd66
commit
a44aa90660
@@ -215,11 +215,10 @@ void Rom_hash::Main::handle_session_request(Xml_node request)
|
||||
server_id_space.apply<Session>(server_id, [&] (Session &session) {
|
||||
Genode::size_t ram_quota = request.attribute_value("ram_quota", 0UL);
|
||||
|
||||
char buf[64];
|
||||
Genode::snprintf(buf, sizeof(buf), "ram_quota=%ld", ram_quota);
|
||||
String<64> args("ram_quota=", ram_quota);
|
||||
|
||||
// XXX handle Root::Invalid_args
|
||||
env.upgrade(session.client_id.id(), buf);
|
||||
env.upgrade(session.client_id.id(), args.string());
|
||||
env.parent().session_response(server_id, Parent::SESSION_OK);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -243,11 +243,10 @@ void Chroot::Main::handle_session_request(Xml_node request)
|
||||
|
||||
size_t ram_quota = request.attribute_value("ram_quota", 0UL);
|
||||
|
||||
char buf[64];
|
||||
snprintf(buf, sizeof(buf), "ram_quota=%ld", ram_quota);
|
||||
String<64> args("ram_quota=", ram_quota);
|
||||
|
||||
// XXX handle Root::Invalid_args
|
||||
env.upgrade(session.client_id.id(), buf);
|
||||
env.upgrade(session.client_id.id(), args.string());
|
||||
env.parent().session_response(server_id, Parent::SESSION_OK);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include <base/session_label.h>
|
||||
#include <base/heap.h>
|
||||
#include <base/log.h>
|
||||
#include <base/snprintf.h>
|
||||
#include <util/list.h>
|
||||
|
||||
namespace Log_tee {
|
||||
@@ -44,13 +43,12 @@ class Log_tee::Session_component : public Rpc_object<Log_session>
|
||||
{ }
|
||||
} _log;
|
||||
|
||||
char _prefix[Session_label::capacity()+3];
|
||||
Genode::String<Session_label::capacity()+3> _prefix;
|
||||
|
||||
public:
|
||||
|
||||
Session_component(Env &env, Session_label const &label, char const *args)
|
||||
: _log(env, args)
|
||||
{ snprintf(_prefix, sizeof(_prefix), "[%s] ", label.string()); }
|
||||
: _log(env, args), _prefix("[", label.string(), "] ") { }
|
||||
|
||||
size_t write(Log_session::String const &msg) override
|
||||
{
|
||||
@@ -58,7 +56,7 @@ class Log_tee::Session_component : public Rpc_object<Log_session>
|
||||
size_t n = _log.write(msg);
|
||||
|
||||
/* write to our own log session */
|
||||
log(Cstring(_prefix), msg.string());
|
||||
log(_prefix, msg.string());
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -36,13 +36,15 @@ using namespace Genode;
|
||||
namespace Lz_rom {
|
||||
using namespace Genode;
|
||||
|
||||
typedef Session_state::Args Args;
|
||||
typedef String<Session_label::capacity()> Lz_path;
|
||||
|
||||
struct Session;
|
||||
struct Main;
|
||||
|
||||
typedef Session_state::Args Args;
|
||||
|
||||
struct File_error { };
|
||||
struct Decompression_error { };
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +59,7 @@ struct Lz_rom::Session :
|
||||
Session(Id_space<Parent::Server> &server_space,
|
||||
Parent::Server::Id server_id,
|
||||
Libc::Env &env, Genode::Allocator &alloc,
|
||||
Session_label const &label,
|
||||
Lz_path const &path,
|
||||
LZ_Decoder *decoder);
|
||||
|
||||
Attached_ram_dataspace ram_ds;
|
||||
@@ -79,7 +81,7 @@ struct Lz_rom::Session :
|
||||
Lz_rom::Session::Session(Id_space<Parent::Server> &server_space,
|
||||
Parent::Server::Id server_id,
|
||||
Libc::Env &env, Genode::Allocator &alloc,
|
||||
Session_label const &label,
|
||||
Lz_path const &path,
|
||||
LZ_Decoder *decoder)
|
||||
:
|
||||
server_id(*this, server_space, server_id),
|
||||
@@ -92,7 +94,7 @@ Lz_rom::Session::Session(Id_space<Parent::Server> &server_space,
|
||||
|
||||
/* Get file size */
|
||||
Vfs::Directory_service::Stat stat;
|
||||
if (env.vfs().stat(label.string(), stat) != Stat_result::STAT_OK)
|
||||
if (env.vfs().stat(path.string(), stat) != Stat_result::STAT_OK)
|
||||
throw File_error();
|
||||
if (!stat.size)
|
||||
throw File_error();
|
||||
@@ -100,7 +102,7 @@ Lz_rom::Session::Session(Id_space<Parent::Server> &server_space,
|
||||
/* Open file */
|
||||
Vfs_handle *fh;
|
||||
Open_result res = env.vfs().open(
|
||||
label.string(), Vfs::Directory_service::OPEN_MODE_RDONLY, &fh, alloc);
|
||||
path.string(), Vfs::Directory_service::OPEN_MODE_RDONLY, &fh, alloc);
|
||||
if (res != Open_result::OPEN_OK)
|
||||
throw File_error();
|
||||
Vfs_handle::Guard handle_guard(fh);
|
||||
@@ -265,18 +267,16 @@ void Lz_rom::Main::handle_session_request(Xml_node request)
|
||||
Args const args = request.sub_node("args").decoded_content<Args>();
|
||||
Session_label const request_label =
|
||||
label_from_args(args.string()).last_element();
|
||||
char new_label[request_label.capacity()];
|
||||
snprintf(new_label, sizeof(new_label), "/%s.lz", request_label.string());
|
||||
Session_label const filename(new_label);
|
||||
Lz_path const lz_path("/", request_label.string(), ".lz");
|
||||
|
||||
try {
|
||||
Session *session = new (session_alloc)
|
||||
Session(server_id_space, server_id, env, vfs_alloc, filename, decoder);
|
||||
Session(server_id_space, server_id, env, vfs_alloc, lz_path, decoder);
|
||||
env.parent().deliver_session_cap(
|
||||
server_id, env.ep().manage(*session));
|
||||
return;
|
||||
} catch (File_error) {
|
||||
log("failed to open or read file '", filename, "'");
|
||||
log("failed to open or read file '", lz_path, "'");
|
||||
} catch (Decompression_error) {
|
||||
char const *msg = "";
|
||||
|
||||
@@ -305,7 +305,7 @@ void Lz_rom::Main::handle_session_request(Xml_node request)
|
||||
case LZ_library_error:
|
||||
msg = "a bug was detected in the library"; break;
|
||||
}
|
||||
error("failed to decompress '", filename, "', ", msg);
|
||||
error("failed to decompress '", lz_path, "', ", msg);
|
||||
} catch (...) { }
|
||||
env.parent().session_response(server_id, Parent::INVALID_ARGS);
|
||||
}
|
||||
|
||||
@@ -193,11 +193,10 @@ void Rom_fallback::Main::handle_session_request(Xml_node request)
|
||||
|
||||
size_t ram_quota = request.attribute_value("ram_quota", 0UL);
|
||||
|
||||
char buf[64];
|
||||
snprintf(buf, sizeof(buf), "ram_quota=%ld", ram_quota);
|
||||
String<64> args("ram_quota=", ram_quota);
|
||||
|
||||
// XXX handle Root::Invalid_args
|
||||
env.upgrade(session.client_id.id(), buf);
|
||||
env.upgrade(session.client_id.id(), args.string());
|
||||
env.parent().session_response(server_id, Parent::SESSION_OK);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user