mirror of
https://github.com/systemd/systemd.git
synced 2025-08-24 09:49:49 +03:00
qrcode-util: add debug message to show why a qrcode wasn't printed
(cherry picked from commit f0764b98e5
)
This commit is contained in:
committed by
Luca Boccassi
parent
6a4ff7a5c1
commit
b3fd2104bc
@ -178,8 +178,10 @@ int print_qrcode_full(FILE *out, const char *header, const char *string, unsigne
|
|||||||
|
|
||||||
/* If this is not a UTF-8 system or ANSI colors aren't supported/disabled don't print any QR
|
/* If this is not a UTF-8 system or ANSI colors aren't supported/disabled don't print any QR
|
||||||
* codes */
|
* codes */
|
||||||
if (!is_locale_utf8() || !colors_enabled())
|
if (!is_locale_utf8())
|
||||||
return -EOPNOTSUPP;
|
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Not an UTF-8 system, cannot print qrcode");
|
||||||
|
if (!colors_enabled())
|
||||||
|
return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Colors are disabled, cannot print qrcode");
|
||||||
|
|
||||||
r = dlopen_qrencode();
|
r = dlopen_qrencode();
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@ -187,21 +189,21 @@ int print_qrcode_full(FILE *out, const char *header, const char *string, unsigne
|
|||||||
|
|
||||||
qr = sym_QRcode_encodeString(string, 0, QR_ECLEVEL_L, QR_MODE_8, 1);
|
qr = sym_QRcode_encodeString(string, 0, QR_ECLEVEL_L, QR_MODE_8, 1);
|
||||||
if (!qr)
|
if (!qr)
|
||||||
return -ENOMEM;
|
return log_oom_debug();
|
||||||
|
|
||||||
if (row != UINT_MAX && column != UINT_MAX) {
|
if (row != UINT_MAX && column != UINT_MAX) {
|
||||||
int fd;
|
|
||||||
unsigned qr_code_width, qr_code_height;
|
unsigned qr_code_width, qr_code_height;
|
||||||
fd = fileno(out);
|
|
||||||
|
int fd = fileno(out);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return log_debug_errno(errno, "Failed to get file descriptor from the file stream: %m");
|
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)
|
if (column + qr_code_width > tty_width)
|
||||||
column = tty_width - qr_code_width;
|
column = tty_width - qr_code_width;
|
||||||
|
|
||||||
/* Terminal characters are twice as high as they are wide so it's qr_code_height / 2,
|
/* 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)
|
if (row + qr_code_height > tty_height)
|
||||||
row = tty_height - (qr_code_height / 2 ) - 1;
|
row = tty_height - (qr_code_height / 2 ) - 1;
|
||||||
|
|
||||||
@ -217,7 +219,6 @@ int print_qrcode_full(FILE *out, const char *header, const char *string, unsigne
|
|||||||
fprintf(out, "\n%s:\n\n", header);
|
fprintf(out, "\n%s:\n\n", header);
|
||||||
|
|
||||||
write_qrcode(out, qr, row, column);
|
write_qrcode(out, qr, row, column);
|
||||||
|
|
||||||
fputc('\n', out);
|
fputc('\n', out);
|
||||||
|
|
||||||
sym_QRcode_free(qr);
|
sym_QRcode_free(qr);
|
||||||
|
Reference in New Issue
Block a user