From 71da0c6cb80e3708213a08c06e71f099534bcd2a Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Wed, 23 Jul 2014 14:20:12 +0800 Subject: discover: Add debug flag to config This change adds a debug flag to the config, and groups it under not-user-modifiable parts of struct config. This means we no longer need the pb-sysinfo helper, as the last remaining function (--debug-enabled) can be implemented with pb-config. Signed-off-by: Jeremy Kerr --- discover/platform.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'discover/platform.c') diff --git a/discover/platform.c b/discover/platform.c index 65e9ed4..418b9ea 100644 --- a/discover/platform.c +++ b/discover/platform.c @@ -1,7 +1,11 @@ +#define _GNU_SOURCE + +#include #include #include +#include #include #include @@ -11,6 +15,8 @@ void *platform_ctx; static struct platform *platform; static struct config *config; +static const char *kernel_cmdline_debug = "petitboot.debug"; + static const char *device_type_name(enum device_type type) { switch (type) { @@ -85,6 +91,25 @@ static void dump_config(struct config *config) pb_log(" language: %s\n", config->lang ?: ""); } +static bool config_debug_on_cmdline(void) +{ + char buf[600]; + int rc, fd; + + fd = open("/proc/cmdline", O_RDONLY); + if (fd < 0) + return false; + + rc = read(fd, buf, sizeof(buf)); + close(fd); + + if (rc <= 0) + return false; + + return memmem(buf, rc, kernel_cmdline_debug, + strlen(kernel_cmdline_debug)) != NULL; +} + void config_set_defaults(struct config *config) { config->autoboot_enabled = true; @@ -105,6 +130,8 @@ void config_set_defaults(struct config *config) config->boot_priorities[0].priority = 2; config->boot_priorities[1].type = DEVICE_TYPE_DISK; config->boot_priorities[1].priority = 1; + + config->debug = config_debug_on_cmdline(); } int platform_init(void *ctx) -- cgit v1.2.1