summaryrefslogtreecommitdiffstats
path: root/discover/platform.c
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2014-07-23 14:20:12 +0800
committerJeremy Kerr <jk@ozlabs.org>2014-08-05 12:42:18 +0800
commit71da0c6cb80e3708213a08c06e71f099534bcd2a (patch)
treee8327fd499bebdfb54a38a8f544f8079936bf806 /discover/platform.c
parent6897abaa97a02e0ab8ac07209a5e4966bfe101c5 (diff)
downloadtalos-petitboot-71da0c6cb80e3708213a08c06e71f099534bcd2a.tar.gz
talos-petitboot-71da0c6cb80e3708213a08c06e71f099534bcd2a.zip
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 <jk@ozlabs.org>
Diffstat (limited to 'discover/platform.c')
-rw-r--r--discover/platform.c27
1 files changed, 27 insertions, 0 deletions
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 <fcntl.h>
#include <string.h>
#include <log/log.h>
+#include <file/file.h>
#include <types/types.h>
#include <talloc/talloc.h>
@@ -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)
OpenPOWER on IntegriCloud