diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2014-07-23 14:20:12 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2014-08-05 12:42:18 +0800 |
commit | 71da0c6cb80e3708213a08c06e71f099534bcd2a (patch) | |
tree | e8327fd499bebdfb54a38a8f544f8079936bf806 | |
parent | 6897abaa97a02e0ab8ac07209a5e4966bfe101c5 (diff) | |
download | petitboot-71da0c6cb80e3708213a08c06e71f099534bcd2a.zip petitboot-71da0c6cb80e3708213a08c06e71f099534bcd2a.tar.gz |
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>
-rw-r--r-- | discover/pb-discover.c | 3 | ||||
-rw-r--r-- | discover/platform-powerpc.c | 6 | ||||
-rw-r--r-- | discover/platform.c | 27 | ||||
-rw-r--r-- | lib/types/types.h | 5 | ||||
-rw-r--r-- | utils/Makefile.am | 2 | ||||
-rw-r--r-- | utils/pb-config.c | 2 | ||||
-rw-r--r-- | utils/pb-console | 4 | ||||
-rwxr-xr-x | utils/pb-sysinfo | 10 |
8 files changed, 45 insertions, 14 deletions
diff --git a/discover/pb-discover.c b/discover/pb-discover.c index 81c582d..fd37068 100644 --- a/discover/pb-discover.c +++ b/discover/pb-discover.c @@ -185,6 +185,9 @@ int main(int argc, char *argv[]) if (config_get()->lang) setlocale(LC_ALL, config_get()->lang); + if (config_get()->debug) + pb_log_set_debug(true); + system_info_init(server); handler = device_handler_init(server, waitset, opts.dry_run == opt_yes); diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c index 2ce69e7..98dc045 100644 --- a/discover/platform-powerpc.c +++ b/discover/platform-powerpc.c @@ -36,6 +36,7 @@ static const char *known_params[] = { "petitboot,network", "petitboot,timeout", "petitboot,bootdev", + "petitboot,debug?", NULL, }; @@ -424,6 +425,11 @@ static void populate_config(struct platform_powerpc *platform, populate_network_config(platform, config); populate_bootdev_config(platform, config); + + if (!config->debug) { + val = get_param(platform, "petitboot,debug?"); + config->debug = val && !strcmp(val, "true"); + } } static char *iface_config_str(void *ctx, struct interface_config *config) 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) diff --git a/lib/types/types.h b/lib/types/types.h index 5536e2a..25bf556 100644 --- a/lib/types/types.h +++ b/lib/types/types.h @@ -121,12 +121,15 @@ struct boot_priority { struct config { bool autoboot_enabled; unsigned int autoboot_timeout_sec; - bool safe_mode; struct network_config network; struct boot_priority *boot_priorities; unsigned int n_boot_priorities; char *boot_device; char *lang; + + /* not user-settable */ + bool safe_mode; + bool debug; }; #endif /* _TYPES_H */ diff --git a/utils/Makefile.am b/utils/Makefile.am index fde6e55..c373943 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -13,7 +13,7 @@ # dist_sbin_SCRIPTS += utils/pb-udhcpc -dist_pkglibexec_SCRIPTS = utils/pb-console utils/pb-sysinfo +dist_pkglibexec_SCRIPTS = utils/pb-console sbin_PROGRAMS += utils/pb-event utils/pb-config utils_pb_config_LDADD = $(top_builddir)/lib/libpbcore.la \ diff --git a/utils/pb-config.c b/utils/pb-config.c index d05538b..3bd670c 100644 --- a/utils/pb-config.c +++ b/utils/pb-config.c @@ -68,6 +68,8 @@ static void print_config(void *ctx, struct config *config, const char *var) config->autoboot_timeout_sec); print_one_config(ctx, var, "safe-mode", "%s", config->safe_mode ? "enabled" : "disabled"); + print_one_config(ctx, var, "debug", "%s", + config->debug ? "enabled" : "disabled"); } int main(int argc, char **argv) diff --git a/utils/pb-console b/utils/pb-console index 1c2bf62..64bf77f 100644 --- a/utils/pb-console +++ b/utils/pb-console @@ -9,6 +9,7 @@ shell=sh getty=/sbin/getty use_getty=0 detach=0 +pb_config=pb-config usage() { cat >&2 <<EOF @@ -104,8 +105,7 @@ case "$(tty)" in esac verbose_opt= -sysinfo_bin=$(dirname $0)/pb-sysinfo -if [ -x $sysinfo_bin ] && $sysinfo_bin --debug-enabled +if $pb_config debug | grep -q enabled then verbose_opt=--verbose fi diff --git a/utils/pb-sysinfo b/utils/pb-sysinfo deleted file mode 100755 index 7d6635c..0000000 --- a/utils/pb-sysinfo +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -case "$1" in -'--debug-enabled') - exec >/dev/null 2>&1 - nvram --print-config=petitboot,debug? | grep -q true && exit 0 - grep -Fq petitboot.debug /proc/cmdline && exit 0 - exit 1 - ;; -esac |