diff options
Diffstat (limited to 'src/journal')
-rw-r--r-- | src/journal/bsod.c | 36 | ||||
-rw-r--r-- | src/journal/meson.build | 15 |
2 files changed, 35 insertions, 16 deletions
diff --git a/src/journal/bsod.c b/src/journal/bsod.c index 2ae06dee52..76907d2e5c 100644 --- a/src/journal/bsod.c +++ b/src/journal/bsod.c @@ -22,6 +22,8 @@ #include "sysctl-util.h" #include "terminal-util.h" +static bool arg_continuous = false; + static int help(void) { _cleanup_free_ char *link = NULL; int r; @@ -36,6 +38,8 @@ static int help(void) { "as a string and a QR code.\n\n%s" " -h --help Show this help\n" " --version Show package version\n" + " -c --continuous Make systemd-bsod wait continuously\n" + "for changes in the journal\n" "\nSee the %s for details.\n", program_invocation_short_name, ansi_highlight(), @@ -75,13 +79,24 @@ static int acquire_first_emergency_log_message(char **ret) { if (r < 0) return log_error_errno(r, "Failed to seek to start of jornal: %m"); - r = sd_journal_next(j); - if (r < 0) - return log_error_errno(r, "Failed to read next journal entry: %m"); - if (r == 0) { - log_debug("No emergency level entries in the journal"); - *ret = NULL; - return 0; + for(;;) { + r = sd_journal_next(j); + if (r < 0) + return log_error_errno(r, "Failed to read next journal entry: %m"); + if (r > 0) + break; + + if (!arg_continuous) { + log_debug("No emergency level entries in the journal"); + *ret = NULL; + return 0; + } + + r = sd_journal_wait(j, (uint64_t) -1); + if (r < 0) + return log_error_errno(r, "Failed to wait for changes: %m"); + + continue; } r = sd_journal_get_data(j, "MESSAGE", &d, &l); @@ -210,6 +225,7 @@ static int parse_argv(int argc, char * argv[]) { static const struct option options[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, ARG_VERSION }, + { "continuous", no_argument, NULL, 'c' }, {} }; @@ -218,7 +234,7 @@ static int parse_argv(int argc, char * argv[]) { assert(argc >= 0); assert(argv); - while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) + while ((c = getopt_long(argc, argv, "hc", options, NULL)) >= 0) switch (c) { @@ -228,6 +244,10 @@ static int parse_argv(int argc, char * argv[]) { case ARG_VERSION: return version(); + case 'c': + arg_continuous = true; + break; + case '?': return -EINVAL; diff --git a/src/journal/meson.build b/src/journal/meson.build index e89f9d1bc5..32d73cca82 100644 --- a/src/journal/meson.build +++ b/src/journal/meson.build @@ -72,6 +72,13 @@ executables += [ threads, ], }, + libexec_template + { + 'name' : 'systemd-bsod', + 'conditions' : ['HAVE_QRENCODE'], + 'sources' : files('bsod.c'), + 'link_with' : libshared, + 'dependencies' : libqrencode, + }, executable_template + { 'name' : 'systemd-cat', 'public' : true, @@ -95,14 +102,6 @@ executables += [ threads, ], }, - executable_template + { - 'name' : 'systemd-bsod', - 'conditions' : ['HAVE_QRENCODE'], - 'public' : true, - 'sources' : files('bsod.c'), - 'link_with' : libshared, - 'dependencies' : libqrencode, - }, journal_test_template + { 'sources' : files('test-journal-append.c'), 'type' : 'manual', |