vconsole-setup: handle gracefully if setfont/loadkeys are not available

Let's not complain too loudly if these external binaries aren't there.
This commit is contained in:
Lennart Poettering
2026-03-19 08:51:18 +01:00
parent 3d153bfeb6
commit 3327a411be
+40 -14
View File
@@ -271,6 +271,14 @@ static int keyboard_load_and_wait(const char *vc, Context *c, bool utf8) {
if (streq(keymap, "@kernel"))
return 0;
if (access(KBD_LOADKEYS, X_OK) < 0) {
if (errno != ENOENT)
return log_error_errno(errno, "Failed to check if '" KBD_LOADKEYS "' is available: %m");
log_notice("'" KBD_LOADKEYS "' is not available, skipping keyboard mapping setup.");
return 0; /* Report that we skipped this */
}
args[i++] = KBD_LOADKEYS;
args[i++] = "-q";
args[i++] = "-C";
@@ -298,7 +306,13 @@ static int keyboard_load_and_wait(const char *vc, Context *c, bool utf8) {
_exit(EXIT_FAILURE);
}
return pidref_wait_for_terminate_and_check(KBD_LOADKEYS, &pidref, WAIT_LOG);
r = pidref_wait_for_terminate_and_check(KBD_LOADKEYS, &pidref, WAIT_LOG);
if (r < 0)
return r;
if (r != EXIT_SUCCESS)
return -EPROTO;
return 1; /* Report that we did something */
}
static int font_load_and_wait(const char *vc, Context *c) {
@@ -318,6 +332,14 @@ static int font_load_and_wait(const char *vc, Context *c) {
if (!font && !font_map && !font_unimap)
return 0;
if (access(KBD_SETFONT, X_OK) < 0) {
if (errno != ENOENT)
return log_error_errno(errno, "Failed to check if '" KBD_SETFONT "' is available: %m");
log_notice("'" KBD_SETFONT "' is not available, skipping console font setup.");
return 0; /* Report that we skipped this */
}
args[i++] = KBD_SETFONT;
args[i++] = "-C";
args[i++] = vc;
@@ -353,12 +375,16 @@ static int font_load_and_wait(const char *vc, Context *c) {
* things, but in particular lack of a graphical console. Let's be generous and not treat this as an
* error. */
r = pidref_wait_for_terminate_and_check(KBD_SETFONT, &pidref, WAIT_LOG_ABNORMAL);
if (r == EX_OSERR)
if (r < 0)
return r; /* WAIT_LOG_ABNORMAL means we already have logged about these kinds of errors */
if (r == EX_OSERR) {
log_notice(KBD_SETFONT " failed with a \"system error\" (EX_OSERR), ignoring.");
else if (r >= 0 && r != EXIT_SUCCESS)
log_error(KBD_SETFONT " failed with exit status %i.", r);
return 0; /* Report that we skipped this */
}
if (r != EXIT_SUCCESS)
return log_error_errno(SYNTHETIC_ERRNO(EPROTO), KBD_SETFONT " failed with exit status %i.", r);
return r;
return 1; /* Report that we did something */
}
/*
@@ -590,9 +616,8 @@ static int run(int argc, char **argv) {
_cleanup_(context_done) Context c = {};
_cleanup_free_ char *vc = NULL;
_cleanup_close_ int fd = -EBADF, lock_fd = -EBADF;
bool utf8, keyboard_ok;
bool utf8;
unsigned idx = 0;
int r;
log_setup();
@@ -631,18 +656,19 @@ static int run(int argc, char **argv) {
(void) toggle_utf8_vc(vc, fd, utf8);
r = font_load_and_wait(vc, &c);
keyboard_ok = keyboard_load_and_wait(vc, &c, utf8) == 0;
int setfont_status = font_load_and_wait(vc, &c);
int loadkeys_status = keyboard_load_and_wait(vc, &c, utf8);
if (idx > 0) {
if (r == 0)
setup_remaining_vcs(fd, idx, utf8);
if (setfont_status == 0)
log_notice("Configuration of first virtual console was skipped, ignoring remaining ones.");
else if (setfont_status < 0)
log_warning("Configuration of first virtual console failed, ignoring remaining ones.");
else
log_full(r == EX_OSERR ? LOG_NOTICE : LOG_WARNING,
"Configuration of first virtual console failed, ignoring remaining ones.");
setup_remaining_vcs(fd, idx, utf8);
}
return IN_SET(r, 0, EX_OSERR) && keyboard_ok ? EXIT_SUCCESS : EXIT_FAILURE;
return (setfont_status >= 0 && loadkeys_status >= 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run);