Fix display of qrcodes by bsod and other related cleanups (#34914)
This commit is contained in:
@@ -67,7 +67,7 @@ int enroll_recovery(
|
||||
"whenever authentication is requested.\n", stderr);
|
||||
fflush(stderr);
|
||||
|
||||
(void) print_qrcode(stderr, "You may optionally scan the recovery key off screen", password);
|
||||
(void) print_qrcode(stderr, "Optionally scan the recovery key for safekeeping", password);
|
||||
|
||||
if (asprintf(&keyslot_as_string, "%i", keyslot) < 0) {
|
||||
r = log_oom();
|
||||
|
||||
@@ -160,7 +160,7 @@ int identity_add_recovery_key(sd_json_variant **v) {
|
||||
"whenever authentication is requested.\n", stderr);
|
||||
fflush(stderr);
|
||||
|
||||
(void) print_qrcode(stderr, "You may optionally scan the recovery key off screen", password);
|
||||
(void) print_qrcode(stderr, "Optionally scan the recovery key for safekeeping", password);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+6
-4
@@ -143,7 +143,7 @@ static int display_emergency_message_fullscreen(const char *message) {
|
||||
unsigned qr_code_start_row = 1, qr_code_start_column = 1;
|
||||
char ttybuf[STRLEN("/dev/tty") + DECIMAL_STR_MAX(int) + 1];
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
_cleanup_fclose_ FILE *stream = NULL;
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
char read_character_buffer = '\0';
|
||||
struct winsize w = {
|
||||
.ws_col = 80,
|
||||
@@ -206,13 +206,15 @@ static int display_emergency_message_fullscreen(const char *message) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
r = fdopen_independent(fd, "r+", &stream);
|
||||
r = fdopen_independent(fd, "r+", &f);
|
||||
if (r < 0) {
|
||||
r = log_error_errno(errno, "Failed to open output file: %m");
|
||||
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(f, "Scan the error message",
|
||||
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");
|
||||
|
||||
@@ -226,7 +228,7 @@ static int display_emergency_message_fullscreen(const char *message) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
r = read_one_char(stream, &read_character_buffer, USEC_INFINITY, NULL);
|
||||
r = read_one_char(f, &read_character_buffer, USEC_INFINITY, NULL);
|
||||
if (r < 0 && r != -EINTR)
|
||||
log_error_errno(r, "Failed to read character: %m");
|
||||
|
||||
|
||||
@@ -199,9 +199,7 @@ int action_setup_keys(void) {
|
||||
if (!url)
|
||||
return log_oom();
|
||||
|
||||
(void) print_qrcode(stderr,
|
||||
"To transfer the verification key to your phone scan the QR code below",
|
||||
url);
|
||||
(void) print_qrcode(stderr, "Scan the verification key to transfer it to another device", url);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
+23
-12
@@ -173,36 +173,49 @@ 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) {
|
||||
QRcode* qr;
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(QRcode*, sym_QRcode_free, NULL);
|
||||
|
||||
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) {
|
||||
|
||||
int r;
|
||||
|
||||
/* If this is not a UTF-8 system or ANSI colors aren't supported/disabled don't print any QR
|
||||
* codes */
|
||||
if (!is_locale_utf8() || !colors_enabled())
|
||||
return -EOPNOTSUPP;
|
||||
if (!is_locale_utf8())
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Not an UTF-8 system, cannot print qrcode");
|
||||
if (check_tty && !colors_enabled())
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Colors are disabled, cannot print qrcode");
|
||||
|
||||
r = dlopen_qrencode();
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
qr = sym_QRcode_encodeString(string, 0, QR_ECLEVEL_L, QR_MODE_8, 1);
|
||||
_cleanup_(sym_QRcode_freep) QRcode *qr =
|
||||
sym_QRcode_encodeString(string, 0, QR_ECLEVEL_L, QR_MODE_8, 1);
|
||||
if (!qr)
|
||||
return -ENOMEM;
|
||||
return log_oom_debug();
|
||||
|
||||
if (row != UINT_MAX && column != UINT_MAX) {
|
||||
int fd;
|
||||
unsigned qr_code_width, qr_code_height;
|
||||
fd = fileno(out);
|
||||
|
||||
int fd = fileno(out);
|
||||
if (fd < 0)
|
||||
return log_debug_errno(errno, "Failed to get file descriptor from the file stream: %m");
|
||||
qr_code_width = qr_code_height = qr->width + 8;
|
||||
|
||||
qr_code_width = qr_code_height = qr->width + 8;
|
||||
if (column + qr_code_width > tty_width)
|
||||
column = tty_width - qr_code_width;
|
||||
|
||||
/* Terminal characters are twice as high as they are wide so it's qr_code_height / 2,
|
||||
* our QR code prints an extra new line, so we have -1 as well */
|
||||
* our QR code prints an extra new line, so we have -1 as well */
|
||||
if (row + qr_code_height > tty_height)
|
||||
row = tty_height - (qr_code_height / 2 ) - 1;
|
||||
|
||||
@@ -218,10 +231,8 @@ int print_qrcode_full(FILE *out, const char *header, const char *string, unsigne
|
||||
fprintf(out, "\n%s:\n\n", header);
|
||||
|
||||
write_qrcode(out, qr, row, column);
|
||||
|
||||
fputc('\n', out);
|
||||
|
||||
sym_QRcode_free(qr);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -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) {
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
static inline int print_qrcode(FILE *out, const char *header, const char *string) {
|
||||
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 print_qrcode_full(out, header, string, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, true);
|
||||
}
|
||||
|
||||
@@ -763,12 +763,13 @@ static int enumerate_sysv(const LookupPaths *lp, Hashmap *all_services) {
|
||||
return log_oom();
|
||||
|
||||
log_struct(LOG_WARNING,
|
||||
LOG_MESSAGE("SysV service '%s' lacks a native systemd unit file. "
|
||||
"%s Automatically generating a unit file for compatibility. Please update package to include a native systemd unit file, in order to make it safe, robust and future-proof. "
|
||||
LOG_MESSAGE("SysV service '%s' lacks a native systemd unit file, "
|
||||
"automatically generating a unit file for compatibility.\n"
|
||||
"Please update package to include a native systemd unit file.\n"
|
||||
"%s This compatibility logic is deprecated, expect removal soon. %s",
|
||||
fpath,
|
||||
special_glyph(SPECIAL_GLYPH_RECYCLING),
|
||||
special_glyph(SPECIAL_GLYPH_WARNING_SIGN), special_glyph(SPECIAL_GLYPH_WARNING_SIGN)),
|
||||
special_glyph(SPECIAL_GLYPH_WARNING_SIGN),
|
||||
special_glyph(SPECIAL_GLYPH_WARNING_SIGN)),
|
||||
"MESSAGE_ID=" SD_MESSAGE_SYSV_GENERATOR_DEPRECATED_STR,
|
||||
"SYSVSCRIPT=%s", fpath,
|
||||
"UNIT=%s", name);
|
||||
|
||||
@@ -25,6 +25,10 @@
|
||||
"in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat " \
|
||||
"non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
|
||||
|
||||
TEST(colors_enabled) {
|
||||
log_info("colors_enabled: %s", yes_no(colors_enabled()));
|
||||
}
|
||||
|
||||
TEST(default_term_for_tty) {
|
||||
puts(default_term_for_tty("/dev/tty23"));
|
||||
puts(default_term_for_tty("/dev/ttyS23"));
|
||||
|
||||
@@ -89,7 +89,7 @@ journalctl --sync
|
||||
SYSTEMD_COLORS=256 /usr/lib/systemd/systemd-bsod &
|
||||
PID=$!
|
||||
vcs_dump_and_check "Root emergency message"
|
||||
grep -aq "Scan the QR code" /tmp/console.dump
|
||||
grep -aq "Scan the error message" /tmp/console.dump
|
||||
# TODO: check if systemd-bsod exits on a key press (didn't figure this one out yet)
|
||||
kill $PID
|
||||
timeout 10 bash -c "while kill -0 $PID; do sleep .5; done"
|
||||
|
||||
Reference in New Issue
Block a user