diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2014-04-04 13:05:18 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2014-04-07 11:49:08 +0800 |
commit | ae3c354e844698bdb4ed35a6845aa9dca1e9205f (patch) | |
tree | b741aa698f1b48d4bf3a42ac696cb1a6d6920465 /discover | |
parent | 3fa256bb478f2b3e6316c561169190457b21e616 (diff) | |
download | talos-petitboot-ae3c354e844698bdb4ed35a6845aa9dca1e9205f.tar.gz talos-petitboot-ae3c354e844698bdb4ed35a6845aa9dca1e9205f.zip |
log: Allow runtime selection of 'debug' log level
Currently, we need to compile with -DDEBUG to implement debug-level
logging in the UIs and discover server.
Since we may not be able to easily replace a system's petitboot
binaries, this change introduces a -v|--verbose option to the discver
server and ncurses UI, which enables debug at runtime. We also move some
of the udev debug code out of an #ifdef DEBUG block.
Since petitboot is generally started on boot, we also add a little
infrastructure to pass -v to petitboot on certain system contitions:
either petitboot.debug on the kernel command line, or a petitboot,debug?
NVRAM property containing the value 'true'.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'discover')
-rw-r--r-- | discover/pb-discover.c | 13 | ||||
-rw-r--r-- | discover/udev.c | 23 |
2 files changed, 20 insertions, 16 deletions
diff --git a/discover/pb-discover.c b/discover/pb-discover.c index 713d99d..e895f47 100644 --- a/discover/pb-discover.c +++ b/discover/pb-discover.c @@ -29,7 +29,7 @@ static void print_usage(void) print_version(); printf( "Usage: pb-discover [-a, --no-autoboot] [-h, --help] [-l, --log log-file]\n" -" [-n, --dry-run] [-V, --version]\n"); +" [-n, --dry-run] [-v, --verbose] [-V, --version]\n"); } /** @@ -48,6 +48,7 @@ struct opts { const char *log_file; enum opt_value dry_run; enum opt_value show_version; + enum opt_value verbose; }; /** @@ -61,14 +62,16 @@ static int opts_parse(struct opts *opts, int argc, char *argv[]) {"help", no_argument, NULL, 'h'}, {"log", required_argument, NULL, 'l'}, {"dry-run", no_argument, NULL, 'n'}, + {"verbose", no_argument, NULL, 'v'}, {"version", no_argument, NULL, 'V'}, { NULL, 0, NULL, 0}, }; - static const char short_options[] = "ahl:nV"; + static const char short_options[] = "ahl:nvV"; static const struct opts default_values = { .no_autoboot = opt_no, .log_file = "/var/log/petitboot/pb-discover.log", .dry_run = opt_no, + .verbose = opt_no, }; *opts = default_values; @@ -93,6 +96,9 @@ static int opts_parse(struct opts *opts, int argc, char *argv[]) case 'n': opts->dry_run = opt_yes; break; + case 'v': + opts->verbose = opt_yes; + break; case 'V': opts->show_version = opt_yes; break; @@ -147,6 +153,9 @@ int main(int argc, char *argv[]) } pb_log_init(log); + if (opts.verbose) + pb_log_set_debug(true); + pb_log("--- pb-discover ---\n"); /* we look for closed sockets when we write, so ignore SIGPIPE */ diff --git a/discover/udev.c b/discover/udev.c index 7db36a7..9e1a5ce 100644 --- a/discover/udev.c +++ b/discover/udev.c @@ -263,23 +263,18 @@ static int udev_handle_dev_change(struct pb_udev *udev, struct udev_device *dev) static int udev_handle_dev_action(struct udev_device *dev, const char *action) { struct pb_udev *udev = udev_get_userdata(udev_device_get_udev(dev)); + struct udev_list_entry *list; + const char *name; -#ifdef DEBUG - { - struct udev_list_entry *list; - const char *name; - - list = udev_device_get_properties_list_entry(dev); - name = udev_device_get_sysname(dev); + list = udev_device_get_properties_list_entry(dev); + name = udev_device_get_sysname(dev); - pb_debug("%s: action %s, device %s\n", __func__, action, name); - pb_debug("%s properties:\n", __func__); + pb_debug("udev: action %s, device %s\n", action, name); + pb_debug("udev: properties:\n"); - for (; list; list = udev_list_entry_get_next(list)) - pb_log("\t%-20s: %s\n", udev_list_entry_get_name(list), - udev_list_entry_get_value(list)); - } while (0); -#endif + for (; list; list = udev_list_entry_get_next(list)) + pb_debug("\t%-20s: %s\n", udev_list_entry_get_name(list), + udev_list_entry_get_value(list)); if (!strcmp(action, "add")) return udev_handle_dev_add(udev, dev); |