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 <michael.i.doherty@intel.com>
This commit is contained in:
Ikey Doherty
2017-01-10 15:16:42 -08:00
committed by William Douglas
parent 149498296a
commit 4839149aa3
3 changed files with 24 additions and 13 deletions
+15 -8
View File
@@ -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;
}
+3 -3
View File
@@ -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
+6 -2
View File
@@ -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")) {