discover: Add debug flag to config
authorJeremy Kerr <jk@ozlabs.org>
Wed, 23 Jul 2014 06:20:12 +0000 (14:20 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Tue, 5 Aug 2014 04:42:18 +0000 (12:42 +0800)
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>
discover/pb-discover.c
discover/platform-powerpc.c
discover/platform.c
lib/types/types.h
utils/Makefile.am
utils/pb-config.c
utils/pb-console
utils/pb-sysinfo [deleted file]

index 81c582dcf201425a8fca7149a16832adba456a49..fd370685653f979419943ee03db5c3b64f311f5f 100644 (file)
@@ -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);
index 2ce69e76f892ace0f6b06bae728edb20d362f25f..98dc045b2c656cf85f0130b42d237dcbbf639d01 100644 (file)
@@ -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)
index 65e9ed4acb4af5662b9a1a3006715226b9c9954d..418b9ea1d68f0cdae48ded8a086680d061645199 100644 (file)
@@ -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)
index 5536e2a912e48c6df3025f6d6e288bb785257830..25bf556e8ee1c931625777a5dee2ba818dbbd057 100644 (file)
@@ -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 */
index fde6e55430215f85a37ac01a3a3ebb3adfbb1eaf..c3739434f2c24a4d5dc4481080ce80e7e789fdfc 100644 (file)
@@ -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 \
index d05538bed97298975916ea3c2833181543ff180a..3bd670c6d002e98de30813da46665d46de9aa2bb 100644 (file)
@@ -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)
index 1c2bf62784f62f0aff6faae911063cb385dc71d3..64bf77fd0c69e4e77973dc0187bb5a155df872e3 100644 (file)
@@ -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 (executable)
index 7d6635c..0000000
+++ /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