Skip to content

Commit

Permalink
src/mark: log mark
Browse files Browse the repository at this point in the history
  • Loading branch information
ejoerns committed Aug 17, 2023
1 parent 59a34fd commit f85d0f3
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/mark.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "bootchooser.h"
#include "event-log.h"
#include "context.h"
#include "install.h"
#include "mark.h"
Expand Down Expand Up @@ -75,6 +76,61 @@ static RaucSlot* get_slot_by_identifier(const gchar *identifier, GError **error)
return slot;
}

#define MESSAGE_ID_MARKED_ACTIVE "8b5e7435-e105-4d86-8582-78e7544fe6da"
#define MESSAGE_ID_MARKED_GOOD "3304e15a-7a9a-4478-85eb-208ba7ae3a05"
#define MESSAGE_ID_MARKED_BAD "ccb0e584-a470-43d7-a531-6994bce77ae5"

void r_event_log_mark_active(RaucSlot *slot, const gchar *message, ...)
__attribute__((__format__(__printf__, 2, 3)));

void r_event_log_mark_active(RaucSlot *slot, const gchar *message, ...)
{
va_list list;
g_autofree gchar *formatted = NULL;
GLogField fields[] = {
{"MESSAGE", NULL, -1 },
{"MESSAGE_ID", MESSAGE_ID_MARKED_ACTIVE, -1 },
{"GLIB_DOMAIN", R_EVENT_LOG_DOMAIN, -1},
{"RAUC_EVENT_TYPE", "mark", -1},
{"RAUC_SLOT", NULL, -1},
{"BUNDLE_HASH", NULL, -1},
{"SLOT_BOOTNAME", NULL, -1},
};

g_return_if_fail(message);

va_start(list, message);
formatted = g_strdup_vprintf(message, list);
va_end(list);

fields[0].value = formatted;
fields[4].value = slot->name ?: "";
fields[5].value = slot->status->bundle_hash ?: "";
fields[6].value = slot->bootname ?: "";

g_log_structured_array(G_LOG_LEVEL_MESSAGE, fields, G_N_ELEMENTS(fields));
}

static void r_event_log_mark_good(RaucSlot *slot)
{
g_log_structured(R_EVENT_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE,
"RAUC_EVENT_TYPE", "mark",
"MESSAGE_ID", MESSAGE_ID_MARKED_GOOD,
"RAUC_SLOT", slot->name,
"MESSAGE", "Marked slot %s good", slot->name
);
}

static void r_event_log_mark_bad(RaucSlot *slot)
{
g_log_structured(R_EVENT_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE,
"RAUC_EVENT_TYPE", "mark",
"MESSAGE_ID", MESSAGE_ID_MARKED_BAD,
"RAUC_SLOT", slot->name,
"MESSAGE", "Marked slot %s bad", slot->name
);
}

gboolean r_mark_active(RaucSlot *slot, GError **error)
{
RaucSlotStatus *slot_state;
Expand All @@ -94,6 +150,8 @@ gboolean r_mark_active(RaucSlot *slot, GError **error)
return FALSE;
}

r_event_log_mark_active(slot, "Marked slot %s as active.", slot->name);

g_free(slot_state->activated_timestamp);
now = g_date_time_new_now_utc();
slot_state->activated_timestamp = g_date_time_format(now, "%Y-%m-%dT%H:%M:%SZ");
Expand Down Expand Up @@ -121,6 +179,9 @@ gboolean r_mark_good(RaucSlot *slot, GError **error)
return FALSE;
}

g_message("Marked slot %s as good.", slot->name);
r_event_log_mark_good(slot);

return TRUE;
}

Expand All @@ -138,6 +199,9 @@ gboolean r_mark_bad(RaucSlot *slot, GError **error)
return FALSE;
}

g_message("Marked slot %s as bad.", slot->name);
r_event_log_mark_bad(slot);

return TRUE;
}

Expand Down

0 comments on commit f85d0f3

Please sign in to comment.