Skip to content

Commit

Permalink
Merge pull request #1225 from jluebbe/run-links
Browse files Browse the repository at this point in the history
create links to active slot devices in /run/rauc/slots/active
  • Loading branch information
jluebbe committed Aug 17, 2023
2 parents dda8474 + b76c13c commit aee0bfd
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
16 changes: 14 additions & 2 deletions docs/using.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ To actually install an update bundle on your target hardware, RAUC provides the
Alternatively you can trigger a bundle installation `using the D-Bus API`_.

Viewing the System Status
-------------------------
Accessing the System Status
---------------------------

For debugging purposes and for scripting it is helpful to gain an overview of
the current system as RAUC sees it.
Expand All @@ -104,6 +104,18 @@ or a JSON representation of the system status.
If more information is needed such as the slots' :ref:`status <slot-status>` add
the command line option ``--detailed``.

Symbolic Links in ``/run/rauc``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Especially for use by other programs and services, RAUC creates symbolic links
in ``/run/rauc`` during service startup.

For example, on a system with A/B rootfs slots and corresponding appfs slots,
``/run/rauc/slots/active/appfs`` would point to the appfs slot that corresponds
to the booted rootfs.
This could be used to mount the correct appfs without replicating the status
determination already implemented in RAUC.

React to a Successfully Booted System/Failed Boot
-------------------------------------------------

Expand Down
1 change: 1 addition & 0 deletions qemu-test-init
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mount -t sysfs none /sys
mount -t debugfs debugfs /sys/kernel/debug/ || true
mount -t tracefs tracefs /sys/kernel/tracing/ || true
mount -t tmpfs none /mnt
mount -t tmpfs none /run
mount -t tmpfs none /tmp

BUILD_DIR="build/"
Expand Down
31 changes: 30 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ static gchar* r_status_formatter_shell(RaucStatusPrint *status)
formatter_shell_append(text, "RAUC_BOOT_PRIMARY", status->primary ? status->primary->name : NULL);

slotnames = g_ptr_array_new();
slotnumbers = g_ptr_array_new();
slotnumbers = g_ptr_array_new_with_free_func(g_free);
g_hash_table_iter_init(&iter, status->slots);
while (g_hash_table_iter_next(&iter, (gpointer*) &name, NULL)) {
g_ptr_array_add(slotnames, name);
Expand Down Expand Up @@ -2000,6 +2000,33 @@ static gboolean status_start(int argc, char **argv)
return TRUE;
}

G_GNUC_UNUSED
static void create_run_links(void)
{
g_autoptr(GError) ierror = NULL;
GHashTableIter iter;
RaucSlot *slot;

if (g_mkdir_with_parents("/run/rauc/slots/active", 0755) != 0) {
g_warning("Failed to create /run/rauc/slots/active");
return;
}

g_hash_table_iter_init(&iter, r_context()->config->slots);
while (g_hash_table_iter_next(&iter, NULL, (gpointer*) &slot)) {
g_autofree gchar* path = NULL;

if (!(slot->state & ST_ACTIVE))
continue;

path = g_build_filename("/run/rauc/slots/active", slot->sclass, NULL);

if (!r_update_symlink(slot->device, path, &ierror)) {
g_warning("Failed to create symlink for active slot: %s", ierror->message);
}
}
}

G_GNUC_UNUSED
static gboolean service_start(int argc, char **argv)
{
Expand All @@ -2013,6 +2040,8 @@ static gboolean service_start(int argc, char **argv)
return TRUE;
}

create_run_links();

if (r_context()->system_status) {
/* Boot ID-based system reboot vs service restart detection */
if (g_strcmp0(r_context()->system_status->boot_id, r_context()->boot_id) == 0) {
Expand Down
4 changes: 4 additions & 0 deletions test/rauc.t
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,10 @@ test_expect_success ROOT,SERVICE "rauc install" "
--override-boot-slot=system0 &&
test_when_finished stop_rauc_dbus_service_with_system &&
test ! -s ${SHARNESS_TEST_DIRECTORY}/images/rootfs-1 &&
test -d /run/rauc/slots/active &&
test -L /run/rauc/slots/active/rootfs &&
readlink /run/rauc/slots/active/rootfs &&
test \"\$(readlink /run/rauc/slots/active/rootfs)\" = \"${SHARNESS_TEST_DIRECTORY}/images/rootfs-0\" &&
rauc \
install ${TEST_TMPDIR}/good-bundle.raucb &&
test -s ${SHARNESS_TEST_DIRECTORY}/images/rootfs-1
Expand Down

0 comments on commit aee0bfd

Please sign in to comment.