From 4839149aa3152c5900da8bc84cde250abaadd7dd Mon Sep 17 00:00:00 2001 From: Ikey Doherty Date: Mon, 9 Jan 2017 03:16:53 +0000 Subject: [PATCH] timeout: Change configuration to /etc/kernel/timeout Recent changes have made CBM read files from /etc/kernel, such as the cmdline. Keeping in line with this simpler approach, i.e. "echo >" and upgrade, we use a simpler filename. To enhance ease of use, we'll also create the /etc/kernel directory if it doesn't already exist, so that there are less steps involved for the user. Signed-off-by: Ikey Doherty --- src/bootman/timeout.c | 23 +++++++++++++++-------- tests/check-core.c | 6 +++--- tests/harness.c | 8 ++++++-- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/bootman/timeout.c b/src/bootman/timeout.c index 3eb27ae..4e87898 100644 --- a/src/bootman/timeout.c +++ b/src/bootman/timeout.c @@ -17,26 +17,33 @@ #include "bootman.h" #include "bootman_private.h" +#include "config.h" #include "log.h" #include "nica/files.h" -/** - * In future we'll replace with an INI file for all of CBM config - */ -#define BOOT_TIMEOUT_CONFIG SYSCONFDIR "/boot_timeout.conf" - bool boot_manager_set_timeout_value(BootManager *self, int timeout) { autofree(FILE) *fp = NULL; autofree(char) *path = NULL; + autofree(char) *dir = NULL; if (!self || !self->sysconfig) { return false; } - if (asprintf(&path, "%s%s", self->sysconfig->prefix, BOOT_TIMEOUT_CONFIG) < 0) { + if (asprintf(&dir, "%s%s", self->sysconfig->prefix, KERNEL_CONF_DIRECTORY) < 0) { DECLARE_OOM(); - return -1; + return false; + } + + if (!nc_mkdir_p(dir, 00755)) { + LOG_ERROR("Failed to create directory %s: %s", dir, strerror(errno)); + return false; + } + + if (asprintf(&path, "%s%s/timeout", self->sysconfig->prefix, KERNEL_CONF_DIRECTORY) < 0) { + DECLARE_OOM(); + return false; } if (timeout <= 0) { @@ -74,7 +81,7 @@ int boot_manager_get_timeout_value(BootManager *self) return false; } - if (asprintf(&path, "%s%s", self->sysconfig->prefix, BOOT_TIMEOUT_CONFIG) < 0) { + if (asprintf(&path, "%s%s/timeout", self->sysconfig->prefix, KERNEL_CONF_DIRECTORY) < 0) { DECLARE_OOM(); return -1; } diff --git a/tests/check-core.c b/tests/check-core.c index 75273ee..bebaab4 100644 --- a/tests/check-core.c +++ b/tests/check-core.c @@ -515,9 +515,9 @@ START_TEST(bootman_timeout_test) fail_if(!boot_manager_set_timeout_value(m, 7), "Failed to set timeout value."); fail_if(boot_manager_get_timeout_value(m) != 7, "Failed to get correct timeout value."); fail_if(!boot_manager_set_timeout_value(m, 0), "Failed to disable timeout value."); - fail_if(nc_file_exists(TOP_BUILD_DIR "/tests/update_playground/" SYSCONFDIR - "/boot_timeout.conf"), - "boot_timeout.conf present."); + fail_if(nc_file_exists(TOP_BUILD_DIR "/tests/update_playground/" KERNEL_CONF_DIRECTORY + "/timeout"), + "kernel/timeout present."); fail_if(boot_manager_get_timeout_value(m) != -1, "Failed to get default timeout value."); } END_TEST diff --git a/tests/harness.c b/tests/harness.c index f206ea7..0a196d1 100644 --- a/tests/harness.c +++ b/tests/harness.c @@ -359,6 +359,11 @@ BootManager *prepare_playground(PlaygroundConfig *config) goto fail; } + /* Construct kernel config directory */ + if (!nc_mkdir_p(PLAYGROUND_ROOT "/" KERNEL_CONF_DIRECTORY, 00755)) { + goto fail; + } + if (!boot_manager_set_prefix(m, PLAYGROUND_ROOT)) { goto fail; } @@ -467,8 +472,7 @@ bool confirm_kernel_uninstalled(BootManager *manager, PlaygroundKernel *kernel) bool create_timeout_conf(void) { autofree(char) *timeout_conf = NULL; - if (asprintf(&timeout_conf, "%s/%s/%s", PLAYGROUND_ROOT, SYSCONFDIR, "boot_timeout.conf") < - 0) { + if (asprintf(&timeout_conf, "%s/%s/timeout", PLAYGROUND_ROOT, KERNEL_CONF_DIRECTORY) < 0) { return false; } if (!file_set_text((const char *)timeout_conf, (char *)"5")) {