]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bsod: do not check for color support
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 28 Oct 2024 12:38:58 +0000 (13:38 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 13 Nov 2024 19:48:10 +0000 (19:48 +0000)
When invoked on a running system, bsod would not print the qrcode.
The check for "color support" on stdout is pointless, since we're not
printing to stdout but to a terminal fd that is opened separately.

(cherry picked from commit 5a64c86936477ecea5cc1fb8dbc79faf522cf370)

src/journal/bsod.c
src/shared/qrcode-util.c
src/shared/qrcode-util.h

index b2889f02eda230739fd54d8d7a51d037bdfd8b9b..ae0c1aa37495d6f806174c8b08c0c34c419b275e 100644 (file)
@@ -213,7 +213,9 @@ static int display_emergency_message_fullscreen(const char *message) {
                 goto cleanup;
         }
 
-        r = print_qrcode_full(stream, "Scan the QR code", message, qr_code_start_row, qr_code_start_column, w.ws_col, w.ws_row);
+        r = print_qrcode_full(stream, "Scan the QR code",
+                              message, qr_code_start_row, qr_code_start_column, w.ws_col, w.ws_row,
+                              /* check_tty= */ false);
         if (r < 0)
                 log_warning_errno(r, "QR code could not be printed, ignoring: %m");
 
index 9c24ca0cf0319121ed400906fafb773a7c7cd38c..45b7920b48e07ed69412945bbedd900e4c284623 100644 (file)
@@ -172,7 +172,16 @@ static void write_qrcode(FILE *output, QRcode *qr, unsigned int row, unsigned in
         fflush(output);
 }
 
-int print_qrcode_full(FILE *out, const char *header, const char *string, unsigned row, unsigned column, unsigned tty_width, unsigned tty_height) {
+int print_qrcode_full(
+                FILE *out,
+                const char *header,
+                const char *string,
+                unsigned row,
+                unsigned column,
+                unsigned tty_width,
+                unsigned tty_height,
+                bool check_tty) {
+
         QRcode* qr;
         int r;
 
@@ -180,7 +189,7 @@ int print_qrcode_full(FILE *out, const char *header, const char *string, unsigne
          * codes */
         if (!is_locale_utf8())
                 return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Not an UTF-8 system, cannot print qrcode");
-        if (!colors_enabled())
+        if (check_tty && !colors_enabled())
                 return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Colors are disabled, cannot print qrcode");
 
         r = dlopen_qrencode();
index ee58294436bf80a91e094a2047d5efdfa60de66f..89a15bb3f5e44868f2a6fb2ce81dd897b529470d 100644 (file)
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
-
 #pragma once
+
+#include <stdbool.h>
 #include <stdio.h>
 #include <errno.h>
 #include <limits.h>
@@ -8,15 +9,29 @@
 #if HAVE_QRENCODE
 int dlopen_qrencode(void);
 
-int print_qrcode_full(FILE *out, const char *header, const char *string, unsigned row, unsigned column, unsigned tty_width, unsigned tty_height);
-static inline int print_qrcode(FILE *out, const char *header, const char *string) {
-        return print_qrcode_full(out, header, string, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX);
-}
+int print_qrcode_full(
+                FILE *out,
+                const char *header,
+                const char *string,
+                unsigned row,
+                unsigned column,
+                unsigned tty_width,
+                unsigned tty_height,
+                bool check_tty);
 #else
-static inline int print_qrcode_full(FILE *out, const char *header, const char *string, unsigned row, unsigned column, unsigned tty_width, unsigned tty_height) {
+static inline int print_qrcode_full(
+                FILE *out,
+                const char *header,
+                const char *string,
+                unsigned row,
+                unsigned column,
+                unsigned tty_width,
+                unsigned tty_height,
+                bool check_tty) {
         return -EOPNOTSUPP;
 }
+#endif
+
 static inline int print_qrcode(FILE *out, const char *header, const char *string) {
-        return -EOPNOTSUPP;
+        return print_qrcode_full(out, header, string, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, true);
 }
-#endif