]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemd-bsod: Add "--continuous" option
authorOMOJOLA JOSHUA <omojolajoshua@gmail.com>
Sun, 6 Aug 2023 16:09:27 +0000 (17:09 +0100)
committerOMOJOLA JOSHUA <omojolajoshua@gmail.com>
Thu, 17 Aug 2023 12:13:54 +0000 (13:13 +0100)
man/systemd-bsod.xml
src/journal/bsod.c
units/meson.build
units/systemd-bsod.service.in [new file with mode: 0644]

index 7a64f4f004a1ed174aa5285b11dbc76715fe4738..86efb29db0809da215309831bc69becf6dca75af 100644 (file)
     <variablelist>
       <xi:include href="standard-options.xml" xpointer="help" />
       <xi:include href="standard-options.xml" xpointer="version" />
+
+     <varlistentry>
+        <term><option>-c</option></term>
+        <term><option>--continuous</option></term>
+
+        <listitem><para> Used to make systemd-bsod wait continuously for changes in the
+         journal's status if doesn't find any emergency messages on initial attempt.</para></listitem>
+     </varlistentry>
     </variablelist>
+
   </refsect1>
 
   <refsect1>
index 7d106eb48abb1f7faa8a2c373f4bd1737e0180a8..a421714f2155f147b9fd780f793521f3db0f6635 100644 (file)
@@ -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;
 
index 5161ec502996309ab7098b1603978bd808eacb3d..221bfa706b6f393b2df3c7299b190e578d41b51e 100644 (file)
@@ -60,6 +60,11 @@ units = [
           'conditions' : ['ENABLE_INITRD'],
           'symlinks' : ['initrd.target.wants/'],
         },
+        {
+          'file' : 'systemd-bsod.service.in',
+          'conditions' : ['HAVE_QRENCODE','ENABLE_INITRD'],
+          'symlinks' : ['initrd.target.wants/'],
+        },
         {
           'file' : 'initrd-cleanup.service',
           'conditions' : ['ENABLE_INITRD'],
diff --git a/units/systemd-bsod.service.in b/units/systemd-bsod.service.in
new file mode 100644 (file)
index 0000000..306d4a6
--- /dev/null
@@ -0,0 +1,21 @@
+#  SPDX-License-Identifier: LGPL-2.1-or-later
+#
+#  This file is part of systemd.
+#
+#  systemd is free software; you can redistribute it and/or modify it
+#  under the terms of the GNU Lesser General Public License as published by
+#  the Free Software Foundation; either version 2.1 of the License, or
+#  (at your option) any later version.
+
+[Unit]
+Description=Displays emergency message full screen.
+Documentation=man:systemd-bsod(8)
+ConditionVirtualization=no
+DefaultDependencies=no
+Conflicts=shutdown.target
+Before=shutdown.target
+After=systemd-battery-check.service
+
+[Service]
+RemainAfterExit=yes
+ExecStart={{LIBEXECDIR}}/systemd-bsod --continuous