Skip to content

Commit

Permalink
Merge pull request #1314 from ejoerns/fix-external-boot-detection
Browse files Browse the repository at this point in the history
src/main: fix and add support for boot detection with rauc.external
  • Loading branch information
jluebbe committed Jan 12, 2024
2 parents 9c2e8fa + 2f8b794 commit 5b10a9f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2004,6 +2004,7 @@ static gboolean status_start(int argc, char **argv)
}

#define MESSAGE_ID_BOOTED "e60e0addd3454cb8b796eae0d497af96"
#define MESSAGE_ID_BOOTED_EXTERNAL "dd237efdad1945d9b1e471bc2b994532"

static void r_event_log_booted(const RaucSlot *booted_slot)
{
Expand All @@ -2030,6 +2031,23 @@ static void r_event_log_booted(const RaucSlot *booted_slot)
g_log_structured_array(G_LOG_LEVEL_INFO, fields, G_N_ELEMENTS(fields));
}

static void r_event_log_booted_external(void)
{
g_autofree gchar *message = NULL;
GLogField fields[] = {
{"MESSAGE", NULL, -1 },
{"MESSAGE_ID", MESSAGE_ID_BOOTED_EXTERNAL, -1 },
{"GLIB_DOMAIN", R_EVENT_LOG_DOMAIN, -1},
{"RAUC_EVENT_TYPE", "boot", -1},
{"BOOT_ID", NULL, -1},
};

message = g_strdup_printf("Booted from external source");
fields[0].value = message;
fields[4].value = r_context()->boot_id;
g_log_structured_array(G_LOG_LEVEL_INFO, fields, G_N_ELEMENTS(fields));
}

G_GNUC_UNUSED
static void create_run_links(void)
{
Expand Down Expand Up @@ -2078,12 +2096,17 @@ static gboolean service_start(int argc, char **argv)
g_message("Restarted RAUC service");
r_event_log_message(R_EVENT_LOG_TYPE_SERVICE, "Service restarted");
} else {
RaucSlot *booted_slot = r_slot_find_by_device(r_context()->config->slots, r_context()->bootslot);
if (!booted_slot)
booted_slot = r_slot_find_by_bootname(r_context()->config->slots, r_context()->bootslot);
r_slot_status_load(booted_slot);
if (g_strcmp0(r_context()->bootslot, "_external_") == 0) {
r_event_log_booted_external();
} else {
RaucSlot *booted_slot = r_slot_find_by_device(r_context()->config->slots, r_context()->bootslot);
if (!booted_slot)
booted_slot = r_slot_find_by_bootname(r_context()->config->slots, r_context()->bootslot);

r_event_log_booted(booted_slot);
r_slot_status_load(booted_slot);

r_event_log_booted(booted_slot);
}

/* update boot ID */
g_free(r_context()->system_status->boot_id);
Expand Down
14 changes: 14 additions & 0 deletions test/rauc.t
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,20 @@ test_expect_success ROOT,SERVICE "rauc install --progress" "
test -s ${SHARNESS_TEST_DIRECTORY}/images/rootfs-1
"

test_expect_success ROOT,SERVICE "rauc install (rauc.external)" "
cp -L ${SHARNESS_TEST_DIRECTORY}/good-verity-bundle.raucb ${TEST_TMPDIR}/ &&
test_when_finished rm -f ${TEST_TMPDIR}/good-verity-bundle.raucb &&
start_rauc_dbus_service_with_system \
--conf=${SHARNESS_TEST_DIRECTORY}/minimal-test.conf \
--mount=${SHARNESS_TEST_DIRECTORY}/mnt \
--override-boot-slot=_external_ &&
test_when_finished stop_rauc_dbus_service_with_system &&
test ! -s ${SHARNESS_TEST_DIRECTORY}/images/rootfs-1 &&
rauc \
install ${TEST_TMPDIR}/good-verity-bundle.raucb &&
test -s ${SHARNESS_TEST_DIRECTORY}/images/rootfs-1
"

test_expect_success ROOT,!SERVICE "rauc install (no service)" "
cp -L ${SHARNESS_TEST_DIRECTORY}/good-bundle.raucb ${TEST_TMPDIR}/ &&
test_when_finished rm -f ${TEST_TMPDIR}/good-bundle.raucb &&
Expand Down

0 comments on commit 5b10a9f

Please sign in to comment.