Skip to content

Commit

Permalink
src: support checking event log types
Browse files Browse the repository at this point in the history
Signed-off-by: Enrico Joerns <[email protected]>
  • Loading branch information
ejoerns committed Oct 7, 2023
1 parent 84ba868 commit 6c23ec1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
9 changes: 9 additions & 0 deletions include/event_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ typedef struct _REventLogger {
void (*writer)(REventLogger* logger, const GLogField *fields, gsize n_fields);
} REventLogger;

/**
* Tests type string for being a supported event log type.
*
* @param type Type string to test
*
* @return TRUE if supported, FALSE otherwise
*/
gboolean r_event_log_is_supported_type(const gchar *type);

/**
* Custom structured logging function.
*
Expand Down
9 changes: 8 additions & 1 deletion src/config_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,14 @@ static gboolean r_event_log_parse_config_sections(GKeyFile *key_file, RaucConfig
return FALSE;
}
for (gsize j = 0; j < entries; j++) {
/* FIXME: handle invalid values */
if (!r_event_log_is_supported_type(logger->events[j])) {
g_set_error(
error,
G_KEY_FILE_ERROR,
G_KEY_FILE_ERROR_INVALID_VALUE,
"Unsupported event log type '%s'", logger->events[j]);
return FALSE;
}
}
g_key_file_remove_key(key_file, *group, "events", NULL);

Expand Down
15 changes: 15 additions & 0 deletions src/event_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@
#include "context.h"
#include "event_log.h"

static const gchar *supported_event_types[] = {
"all",
R_EVENT_LOG_TYPE_BOOT,
R_EVENT_LOG_TYPE_MARK,
R_EVENT_LOG_TYPE_INSTALL,
R_EVENT_LOG_TYPE_SERVICE,
R_EVENT_LOG_TYPE_WRITE_SLOT,
NULL
};

gboolean r_event_log_is_supported_type(const gchar *type)
{
return g_strv_contains(supported_event_types, type);
}

void r_event_log_message(const gchar *type, const gchar *message, ...)
{
va_list list;
Expand Down

0 comments on commit 6c23ec1

Please sign in to comment.