Skip to content

Commit

Permalink
install: control automatic activation of newly installed slot
Browse files Browse the repository at this point in the history
Add boolean key "activate-installed" to section [system] of RAUC's "system.conf"
and use its value to decide if a slot shall be activated with respect to the
bootloader after being updated.

Extend the test suite with tests for correctly parsing the key's values
"true"/"false", for detecting typos in the value and for setting the correct
default value "true" if the key does not exist in the [system] section of the
config file at all.

Signed-off-by: Ulrich Ölmann <u.oelmann@pengutronix.de>
  • Loading branch information
OnkelUlla committed Aug 18, 2017
1 parent 12345f3 commit 35a13bc
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 21 deletions.
7 changes: 7 additions & 0 deletions docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ Example configuration:
Only valid when ``bootloader`` is set to ``grub``.
Specifies the path under which the GRUB environment can be accessed.

``activate-installed``
This boolean value controls if a freshly installed slot is automatically
marked active with respect to the used bootloader. Its default value is
``true`` which means that this slot is going to be started the next time the
system boots. If the value of this parameter is ``false`` the slot has to be
activated manually in order to be booted.

**[keyring] section**

The ``keyring`` section refers to the trusted keyring used for signature
Expand Down
1 change: 1 addition & 0 deletions include/config_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ typedef struct {
/* path prefix where rauc may create mount directories */
gchar *mount_prefix;
gchar *grubenv_path;
gboolean activate_installed;
gchar *keyring_path;

gchar *autoinstall_path;
Expand Down
11 changes: 11 additions & 0 deletions src/config_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ gboolean load_config(const gchar *filename, RaucConfig **config, GError **error)
}
}

c->activate_installed = g_key_file_get_boolean(key_file, "system", "activate-installed", &ierror);
if (g_error_matches(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
c->activate_installed = TRUE;
g_clear_error(&ierror);
}
else if (ierror) {
g_propagate_error(error, ierror);
res = FALSE;
goto free;
}

/* parse [keyring] section */
c->keyring_path = resolve_path(filename,
g_key_file_get_string(key_file, "keyring", "path", NULL));
Expand Down
50 changes: 29 additions & 21 deletions src/install.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,20 +760,24 @@ static gboolean launch_and_wait_default_handler(RaucInstallArgs *args, gchar* bu
install_args_update(args, g_strdup_printf("Updating slot %s done", dest_slot->name));
}

/* Mark all parent destination slots bootable */
g_message("Marking slots as bootable...");
g_hash_table_iter_init(&iter, target_group);
while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&dest_slot)) {
if (dest_slot->parent || !dest_slot->bootname)
continue;
if (r_context()->config->activate_installed) {
/* Mark all parent destination slots bootable */
g_message("Marking slots as bootable...");
g_hash_table_iter_init(&iter, target_group);
while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&dest_slot)) {
if (dest_slot->parent || !dest_slot->bootname)
continue;

res = r_boot_set_primary(dest_slot);
res = r_boot_set_primary(dest_slot);

if (!res) {
g_set_error(error, R_INSTALL_ERROR, R_INSTALL_ERROR_MARK_BOOTABLE,
"Failed marking slot %s bootable", dest_slot->name);
goto out;
if (!res) {
g_set_error(error, R_INSTALL_ERROR, R_INSTALL_ERROR_MARK_BOOTABLE,
"Failed marking slot %s bootable", dest_slot->name);
goto out;
}
}
} else {
g_message("Leaving target slot non-bootable as requested by activate_installed == false.");
}

install_args_update(args, "All slots updated");
Expand Down Expand Up @@ -950,19 +954,23 @@ static gboolean launch_and_wait_network_handler(const gchar* base_url,
goto out;
}

/* Mark all parent destination slots bootable */
g_message("Marking slots as bootable...");
g_hash_table_iter_init(&iter, target_group);
while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&slot)) {
if (slot->parent || !slot->bootname)
continue;
if (r_context()->config->activate_installed) {
/* Mark all parent destination slots bootable */
g_message("Marking slots as bootable...");
g_hash_table_iter_init(&iter, target_group);
while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&slot)) {
if (slot->parent || !slot->bootname)
continue;

res = r_boot_set_primary(slot);
res = r_boot_set_primary(slot);

if (!res) {
g_warning("Failed marking slot %s bootable", slot->name);
goto out;
if (!res) {
g_warning("Failed marking slot %s bootable", slot->name);
goto out;
}
}
} else {
g_message("Leaving target slot non-bootable as requested by activate_installed == false.");
}

res = TRUE;
Expand Down
86 changes: 86 additions & 0 deletions test/config_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ parent=rootfs.1\n";
g_assert_cmpstr(config->system_compatible, ==, "FooCorp Super BarBazzer");
g_assert_cmpstr(config->system_bootloader, ==, "barebox");
g_assert_cmpstr(config->mount_prefix, ==, "/mnt/myrauc/");
g_assert_true(config->activate_installed);

g_assert_nonnull(config->slots);
slotlist = g_hash_table_get_keys(config->slots);
Expand Down Expand Up @@ -212,6 +213,82 @@ readonly=typo\n";
g_clear_error(&ierror);
}

static void config_file_typo_in_boolean_activate_installed_key(ConfigFileFixture *fixture,
gconstpointer user_data)
{
RaucConfig *config;
GError *ierror = NULL;
gchar* pathname;

const gchar *cfg_file = "\
[system]\n\
compatible=FooCorp Super BarBazzer\n\
bootloader=barebox\n\
mountprefix=/mnt/myrauc/\n\
activate-installed=typo\n";


pathname = write_tmp_file(fixture->tmpdir, "invalid_bootloader.conf", cfg_file, NULL);
g_assert_nonnull(pathname);

g_assert_false(load_config(pathname, &config, &ierror));
g_assert_error(ierror, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE);
g_assert_null(config);
g_clear_error(&ierror);
}

static void config_file_activate_installed_set_to_true(ConfigFileFixture *fixture,
gconstpointer user_data)
{
RaucConfig *config;
GError *ierror = NULL;
gchar* pathname;

const gchar *cfg_file = "\
[system]\n\
compatible=FooCorp Super BarBazzer\n\
bootloader=barebox\n\
mountprefix=/mnt/myrauc/\n\
activate-installed=true\n";


pathname = write_tmp_file(fixture->tmpdir, "invalid_bootloader.conf", cfg_file, NULL);
g_assert_nonnull(pathname);

g_assert_true(load_config(pathname, &config, &ierror));
g_assert_null(ierror);
g_assert_nonnull(config);
g_assert_true(config->activate_installed);

free_config(config);
}

static void config_file_activate_installed_set_to_false(ConfigFileFixture *fixture,
gconstpointer user_data)
{
RaucConfig *config;
GError *ierror = NULL;
gchar* pathname;

const gchar *cfg_file = "\
[system]\n\
compatible=FooCorp Super BarBazzer\n\
bootloader=barebox\n\
mountprefix=/mnt/myrauc/\n\
activate-installed=false\n";


pathname = write_tmp_file(fixture->tmpdir, "invalid_bootloader.conf", cfg_file, NULL);
g_assert_nonnull(pathname);

g_assert_true(load_config(pathname, &config, &ierror));
g_assert_null(ierror);
g_assert_nonnull(config);
g_assert_false(config->activate_installed);

free_config(config);
}


static void config_file_test3(void)
{
Expand Down Expand Up @@ -275,6 +352,15 @@ int main(int argc, char *argv[])
g_test_add("/config-file/typo-in-boolean-readonly-key", ConfigFileFixture, NULL,
config_file_fixture_set_up, config_file_typo_in_boolean_readonly_key,
config_file_fixture_tear_down);
g_test_add("/config-file/typo-in-boolean-activate-installed-key", ConfigFileFixture, NULL,
config_file_fixture_set_up, config_file_typo_in_boolean_activate_installed_key,
config_file_fixture_tear_down);
g_test_add("/config-file/activate-installed-key-set-to-true", ConfigFileFixture, NULL,
config_file_fixture_set_up, config_file_activate_installed_set_to_true,
config_file_fixture_tear_down);
g_test_add("/config-file/activate-installed-key-set-to-false", ConfigFileFixture, NULL,
config_file_fixture_set_up, config_file_activate_installed_set_to_false,
config_file_fixture_tear_down);
g_test_add_func("/config-file/test3", config_file_test3);
g_test_add_func("/config-file/test5", config_file_test5);
g_test_add_func("/config-file/test6", config_file_test6);
Expand Down

0 comments on commit 35a13bc

Please sign in to comment.