core: add platform logging service

If the root child requests a LOG service with the label "platform" then
return a LOG session that logs messages directly to kernel. This is to
allow a remote test controller to recognize messages produced by an
privileged local test harness.
This commit is contained in:
Emery Hemingway 2020-01-21 10:07:07 +01:00
parent 7c4568fb5a
commit 5d4e72c874
2 changed files with 53 additions and 23 deletions

View File

@ -30,7 +30,11 @@ namespace Genode {
*/
Log_session_component *_create_session(const char *args) override
{
return new (md_alloc()) Log_session_component(label_from_args(args));
Session_label const label = label_from_args(args);
if (label == "init -> platform")
return new (md_alloc()) Platform_log_session_component();
return new (md_alloc()) Labeled_log_session_component(label);
}
public:

View File

@ -24,23 +24,10 @@ namespace Genode {
class Log_session_component : public Rpc_object<Log_session>
{
private:
protected:
Session_label const _label;
public:
/**
* Constructor
*/
Log_session_component(Session_label const &label) : _label(label) { }
/*****************
** Log session **
*****************/
size_t write(String const &string_buf) override
template <typename PROC>
size_t split_lines(String const &string_buf, PROC proc)
{
if (!(string_buf.valid_string())) {
error("corrupted string");
@ -50,25 +37,64 @@ namespace Genode {
char const *string = string_buf.string();
size_t len = strlen(string);
char buf[string_buf.MAX_SIZE];
unsigned from_i = 0;
for (unsigned i = 0; i < len; i++) {
if (string[i] == '\n') {
memcpy(buf, string + from_i, i - from_i);
buf[i - from_i] = 0;
log("[", _label, "] ", Cstring(buf));
proc(Cstring(string + from_i, i - from_i));
from_i = i + 1;
}
}
/* if last character of string was not a line break, add one */
if (from_i < len)
log("[", _label, "] ", Cstring(string + from_i));
proc(Cstring(string + from_i));
return len;
}
};
class Labeled_log_session_component final : public Log_session_component
{
private:
Session_label const _label;
public:
/**
* Constructor
*/
Labeled_log_session_component(Session_label const &label) : _label(label) { }
/*****************
** Log session **
*****************/
size_t write(String const &string_buf) override
{
return split_lines(string_buf, [&] (Cstring const &line) {
log("[", _label, "] ", line); });
}
};
class Platform_log_session_component final : public Log_session_component
{
public:
/*****************
** Log session **
*****************/
size_t write(String const &string_buf) override
{
return split_lines(string_buf, [&] (Cstring const &line) {
log(line);
});
}
};
}
#endif /* _CORE__INCLUDE__LOG_SESSION_COMPONENT_H_ */