]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
97c4a07d | 2 | /*** |
96b2fb93 | 3 | Copyright © 2016 Michal Soltys <soltys@ziu.info> |
97c4a07d LP |
4 | ***/ |
5 | ||
97c4a07d | 6 | #include <errno.h> |
97c4a07d | 7 | #include <fcntl.h> |
97c4a07d | 8 | #include <limits.h> |
97c4a07d | 9 | #include <linux/kd.h> |
07630cea | 10 | #include <linux/tiocl.h> |
dd04aac9 | 11 | #include <linux/vt.h> |
07630cea LP |
12 | #include <stdbool.h> |
13 | #include <stdio.h> | |
14 | #include <stdlib.h> | |
15 | #include <sys/ioctl.h> | |
93c9a9d2 | 16 | #include <sysexits.h> |
042d7f50 | 17 | #include <termios.h> |
07630cea | 18 | #include <unistd.h> |
97c4a07d | 19 | |
b5efdb8a | 20 | #include "alloc-util.h" |
686d13b9 | 21 | #include "env-file.h" |
3ffd4af2 | 22 | #include "fd-util.h" |
a5c32cff | 23 | #include "fileio.h" |
c004493c | 24 | #include "io-util.h" |
8752c575 | 25 | #include "locale-util.h" |
07630cea | 26 | #include "log.h" |
01771226 | 27 | #include "proc-cmdline.h" |
0b452006 | 28 | #include "process-util.h" |
ce30c8dc | 29 | #include "signal-util.h" |
d054f0a4 | 30 | #include "stdio-util.h" |
07630cea | 31 | #include "string-util.h" |
3d623780 | 32 | #include "strv.h" |
07630cea LP |
33 | #include "terminal-util.h" |
34 | #include "util.h" | |
35 | #include "virt.h" | |
97c4a07d | 36 | |
1142bed2 | 37 | static int verify_vc_device(int fd) { |
b53f3386 LP |
38 | unsigned char data[] = { |
39 | TIOCL_GETFGCONSOLE, | |
40 | }; | |
41 | ||
1142bed2 | 42 | int r; |
97c4a07d | 43 | |
1142bed2 | 44 | r = ioctl(fd, TIOCLINUX, data); |
b53f3386 LP |
45 | if (r < 0) |
46 | return -errno; | |
47 | ||
48 | return r; | |
97c4a07d LP |
49 | } |
50 | ||
1142bed2 MS |
51 | static int verify_vc_allocation(unsigned idx) { |
52 | char vcname[sizeof("/dev/vcs") + DECIMAL_STR_MAX(unsigned) - 2]; | |
03044059 | 53 | |
1142bed2 | 54 | xsprintf(vcname, "/dev/vcs%u", idx); |
b53f3386 LP |
55 | |
56 | if (access(vcname, F_OK) < 0) | |
57 | return -errno; | |
58 | ||
59 | return 0; | |
03044059 MS |
60 | } |
61 | ||
1142bed2 | 62 | static int verify_vc_allocation_byfd(int fd) { |
03044059 MS |
63 | struct vt_stat vcs = {}; |
64 | ||
b53f3386 LP |
65 | if (ioctl(fd, VT_GETSTATE, &vcs) < 0) |
66 | return -errno; | |
67 | ||
68 | return verify_vc_allocation(vcs.v_active); | |
03044059 MS |
69 | } |
70 | ||
1142bed2 | 71 | static int verify_vc_kbmode(int fd) { |
b53f3386 | 72 | int curr_mode; |
03044059 | 73 | |
03044059 MS |
74 | /* |
75 | * Make sure we only adjust consoles in K_XLATE or K_UNICODE mode. | |
d23a0044 | 76 | * Otherwise we would (likely) interfere with X11's processing of the |
03044059 MS |
77 | * key events. |
78 | * | |
79 | * http://lists.freedesktop.org/archives/systemd-devel/2013-February/008573.html | |
80 | */ | |
b53f3386 LP |
81 | |
82 | if (ioctl(fd, KDGKBMODE, &curr_mode) < 0) | |
1142bed2 MS |
83 | return -errno; |
84 | ||
85 | return IN_SET(curr_mode, K_XLATE, K_UNICODE) ? 0 : -EBUSY; | |
03044059 MS |
86 | } |
87 | ||
aaa709bb | 88 | static int toggle_utf8(const char *name, int fd, bool utf8) { |
042d7f50 MS |
89 | int r; |
90 | struct termios tc = {}; | |
97c4a07d | 91 | |
aaa709bb ZJS |
92 | assert(name); |
93 | ||
042d7f50 | 94 | r = ioctl(fd, KDSKBMODE, utf8 ? K_UNICODE : K_XLATE); |
97c4a07d | 95 | if (r < 0) |
aaa709bb | 96 | return log_warning_errno(errno, "Failed to %s UTF-8 kbdmode on %s: %m", enable_disable(utf8), name); |
97c4a07d | 97 | |
042d7f50 MS |
98 | r = loop_write(fd, utf8 ? "\033%G" : "\033%@", 3, false); |
99 | if (r < 0) | |
aaa709bb | 100 | return log_warning_errno(r, "Failed to %s UTF-8 term processing on %s: %m", enable_disable(utf8), name); |
042d7f50 MS |
101 | |
102 | r = tcgetattr(fd, &tc); | |
103 | if (r >= 0) { | |
ab8ee0f2 | 104 | SET_FLAG(tc.c_iflag, IUTF8, utf8); |
042d7f50 | 105 | r = tcsetattr(fd, TCSANOW, &tc); |
a25d4d0e | 106 | } |
042d7f50 | 107 | if (r < 0) |
aaa709bb | 108 | return log_warning_errno(errno, "Failed to %s iutf8 flag on %s: %m", enable_disable(utf8), name); |
d305a67b | 109 | |
aaa709bb | 110 | log_debug("UTF-8 kbdmode %sd on %s", enable_disable(utf8), name); |
042d7f50 MS |
111 | return 0; |
112 | } | |
d305a67b | 113 | |
042d7f50 MS |
114 | static int toggle_utf8_sysfs(bool utf8) { |
115 | int r; | |
d305a67b | 116 | |
57512c89 | 117 | r = write_string_file("/sys/module/vt/parameters/default_utf8", one_zero(utf8), WRITE_STRING_FILE_DISABLE_BUFFER); |
d305a67b | 118 | if (r < 0) |
aaa709bb ZJS |
119 | return log_warning_errno(r, "Failed to %s sysfs UTF-8 flag: %m", enable_disable(utf8)); |
120 | ||
121 | log_debug("Sysfs UTF-8 flag %sd", enable_disable(utf8)); | |
122 | return 0; | |
d305a67b TG |
123 | } |
124 | ||
aecb6fcb | 125 | static int keyboard_load_and_wait(const char *vc, const char *map, const char *map_toggle, bool utf8) { |
5b396b06 | 126 | const char *args[8]; |
1142bed2 | 127 | unsigned i = 0; |
97c4a07d | 128 | pid_t pid; |
4c253ed1 | 129 | int r; |
97c4a07d | 130 | |
8931278c LDM |
131 | /* An empty map means kernel map */ |
132 | if (isempty(map)) | |
c9d2b3d0 | 133 | return 0; |
944d4c91 | 134 | |
9841e8e3 | 135 | args[i++] = KBD_LOADKEYS; |
97c4a07d LP |
136 | args[i++] = "-q"; |
137 | args[i++] = "-C"; | |
138 | args[i++] = vc; | |
139 | if (utf8) | |
140 | args[i++] = "-u"; | |
141 | args[i++] = map; | |
5b396b06 AB |
142 | if (map_toggle) |
143 | args[i++] = map_toggle; | |
97c4a07d LP |
144 | args[i++] = NULL; |
145 | ||
16dbd110 LP |
146 | if (DEBUG_LOGGING) { |
147 | _cleanup_free_ char *cmd; | |
148 | ||
149 | cmd = strv_join((char**) args, " "); | |
150 | log_debug("Executing \"%s\"...", strnull(cmd)); | |
151 | } | |
3d623780 | 152 | |
0672e2c6 | 153 | r = safe_fork("(loadkeys)", FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_RLIMIT_NOFILE_SAFE|FORK_LOG, &pid); |
4c253ed1 | 154 | if (r < 0) |
b6e1fff1 | 155 | return r; |
4c253ed1 | 156 | if (r == 0) { |
97c4a07d LP |
157 | execv(args[0], (char **) args); |
158 | _exit(EXIT_FAILURE); | |
159 | } | |
160 | ||
7d4904fe | 161 | return wait_for_terminate_and_check(KBD_LOADKEYS, pid, WAIT_LOG); |
97c4a07d LP |
162 | } |
163 | ||
aecb6fcb | 164 | static int font_load_and_wait(const char *vc, const char *font, const char *map, const char *unimap) { |
97c4a07d | 165 | const char *args[9]; |
1142bed2 | 166 | unsigned i = 0; |
97c4a07d | 167 | pid_t pid; |
4c253ed1 | 168 | int r; |
97c4a07d | 169 | |
c9d2b3d0 MS |
170 | /* Any part can be set independently */ |
171 | if (isempty(font) && isempty(map) && isempty(unimap)) | |
172 | return 0; | |
944d4c91 | 173 | |
9841e8e3 | 174 | args[i++] = KBD_SETFONT; |
97c4a07d LP |
175 | args[i++] = "-C"; |
176 | args[i++] = vc; | |
c9d2b3d0 | 177 | if (!isempty(map)) { |
97c4a07d LP |
178 | args[i++] = "-m"; |
179 | args[i++] = map; | |
180 | } | |
c9d2b3d0 | 181 | if (!isempty(unimap)) { |
97c4a07d LP |
182 | args[i++] = "-u"; |
183 | args[i++] = unimap; | |
184 | } | |
c9d2b3d0 MS |
185 | if (!isempty(font)) |
186 | args[i++] = font; | |
97c4a07d LP |
187 | args[i++] = NULL; |
188 | ||
16dbd110 LP |
189 | if (DEBUG_LOGGING) { |
190 | _cleanup_free_ char *cmd; | |
191 | ||
192 | cmd = strv_join((char**) args, " "); | |
193 | log_debug("Executing \"%s\"...", strnull(cmd)); | |
194 | } | |
3d623780 | 195 | |
0672e2c6 | 196 | r = safe_fork("(setfont)", FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_RLIMIT_NOFILE_SAFE|FORK_LOG, &pid); |
4c253ed1 | 197 | if (r < 0) |
b6e1fff1 | 198 | return r; |
4c253ed1 | 199 | if (r == 0) { |
97c4a07d LP |
200 | execv(args[0], (char **) args); |
201 | _exit(EXIT_FAILURE); | |
202 | } | |
203 | ||
7d4904fe | 204 | return wait_for_terminate_and_check(KBD_SETFONT, pid, WAIT_LOG); |
97c4a07d LP |
205 | } |
206 | ||
d3b37e84 | 207 | /* |
1142bed2 | 208 | * A newly allocated VT uses the font from the source VT. Here |
d3b37e84 KS |
209 | * we update all possibly already allocated VTs with the configured |
210 | * font. It also allows to restart systemd-vconsole-setup.service, | |
211 | * to apply a new font to all VTs. | |
eb22d84b MS |
212 | * |
213 | * We also setup per-console utf8 related stuff: kbdmode, term | |
214 | * processing, stty iutf8. | |
d3b37e84 | 215 | */ |
1142bed2 | 216 | static void setup_remaining_vcs(int src_fd, unsigned src_idx, bool utf8) { |
eb22d84b | 217 | struct console_font_op cfo = { |
5297577f MS |
218 | .op = KD_FONT_OP_GET, |
219 | .width = UINT_MAX, .height = UINT_MAX, | |
220 | .charcount = UINT_MAX, | |
eb22d84b | 221 | }; |
eb22d84b | 222 | struct unimapinit adv = {}; |
ff452e76 | 223 | struct unimapdesc unimapd; |
6a08e1b0 | 224 | _cleanup_free_ struct unipair* unipairs = NULL; |
eb22d84b | 225 | _cleanup_free_ void *fontbuf = NULL; |
1142bed2 MS |
226 | unsigned i; |
227 | int r; | |
dd04aac9 | 228 | |
6a08e1b0 | 229 | unipairs = new(struct unipair, USHRT_MAX); |
e2c9192a LP |
230 | if (!unipairs) { |
231 | log_oom(); | |
6a08e1b0 KR |
232 | return; |
233 | } | |
234 | ||
5297577f | 235 | /* get metadata of the current font (width, height, count) */ |
1142bed2 | 236 | r = ioctl(src_fd, KDFONTOP, &cfo); |
eb22d84b | 237 | if (r < 0) |
5297577f | 238 | log_warning_errno(errno, "KD_FONT_OP_GET failed while trying to get the font metadata: %m"); |
eb22d84b | 239 | else { |
a5eebcff | 240 | /* verify parameter sanity first */ |
5297577f MS |
241 | if (cfo.width > 32 || cfo.height > 32 || cfo.charcount > 512) |
242 | log_warning("Invalid font metadata - width: %u (max 32), height: %u (max 32), count: %u (max 512)", | |
a5eebcff | 243 | cfo.width, cfo.height, cfo.charcount); |
5297577f MS |
244 | else { |
245 | /* | |
246 | * Console fonts supported by the kernel are limited in size to 32 x 32 and maximum 512 | |
247 | * characters. Thus with 1 bit per pixel it requires up to 65536 bytes. The height always | |
248 | * requries 32 per glyph, regardless of the actual height - see the comment above #define | |
249 | * max_font_size 65536 in drivers/tty/vt/vt.c for more details. | |
250 | */ | |
8419d457 | 251 | fontbuf = malloc_multiply((cfo.width + 7) / 8 * 32, cfo.charcount); |
5297577f MS |
252 | if (!fontbuf) { |
253 | log_oom(); | |
254 | return; | |
255 | } | |
1142bed2 | 256 | /* get fonts from the source console */ |
5297577f | 257 | cfo.data = fontbuf; |
1142bed2 | 258 | r = ioctl(src_fd, KDFONTOP, &cfo); |
5297577f MS |
259 | if (r < 0) |
260 | log_warning_errno(errno, "KD_FONT_OP_GET failed while trying to read the font data: %m"); | |
261 | else { | |
262 | unimapd.entries = unipairs; | |
263 | unimapd.entry_ct = USHRT_MAX; | |
1142bed2 | 264 | r = ioctl(src_fd, GIO_UNIMAP, &unimapd); |
5297577f MS |
265 | if (r < 0) |
266 | log_warning_errno(errno, "GIO_UNIMAP failed while trying to read unicode mappings: %m"); | |
267 | else | |
268 | cfo.op = KD_FONT_OP_SET; | |
269 | } | |
270 | } | |
eb22d84b MS |
271 | } |
272 | ||
a5eebcff | 273 | if (cfo.op != KD_FONT_OP_SET) |
5297577f | 274 | log_warning("Fonts will not be copied to remaining consoles"); |
eb22d84b | 275 | |
9fa71843 | 276 | for (i = 1; i <= 63; i++) { |
1142bed2 | 277 | char ttyname[sizeof("/dev/tty63")]; |
eb22d84b | 278 | _cleanup_close_ int fd_d = -1; |
dd04aac9 | 279 | |
1142bed2 | 280 | if (i == src_idx || verify_vc_allocation(i) < 0) |
dd04aac9 KS |
281 | continue; |
282 | ||
eb22d84b | 283 | /* try to open terminal */ |
1142bed2 MS |
284 | xsprintf(ttyname, "/dev/tty%u", i); |
285 | fd_d = open_terminal(ttyname, O_RDWR|O_CLOEXEC|O_NOCTTY); | |
eb22d84b | 286 | if (fd_d < 0) { |
1142bed2 | 287 | log_warning_errno(fd_d, "Unable to open tty%u, fonts will not be copied: %m", i); |
dd04aac9 | 288 | continue; |
eb22d84b | 289 | } |
dd04aac9 | 290 | |
1142bed2 | 291 | if (verify_vc_kbmode(fd_d) < 0) |
dd04aac9 KS |
292 | continue; |
293 | ||
aaa709bb | 294 | toggle_utf8(ttyname, fd_d, utf8); |
eb22d84b MS |
295 | |
296 | if (cfo.op != KD_FONT_OP_SET) | |
297 | continue; | |
298 | ||
299 | r = ioctl(fd_d, KDFONTOP, &cfo); | |
300 | if (r < 0) { | |
d610d201 FB |
301 | int last_errno, mode; |
302 | ||
303 | /* The fonts couldn't have been copied. It might be due to the | |
304 | * terminal being in graphical mode. In this case the kernel | |
305 | * returns -EINVAL which is too generic for distinguishing this | |
306 | * specific case. So we need to retrieve the terminal mode and if | |
307 | * the graphical mode is in used, let's assume that something else | |
308 | * is using the terminal and the failure was expected as we | |
309 | * shouldn't have tried to copy the fonts. */ | |
310 | ||
311 | last_errno = errno; | |
312 | if (ioctl(fd_d, KDGETMODE, &mode) >= 0 && mode != KD_TEXT) | |
313 | log_debug("KD_FONT_OP_SET skipped: tty%u is not in text mode", i); | |
314 | else | |
315 | log_warning_errno(last_errno, "KD_FONT_OP_SET failed, fonts will not be copied to tty%u: %m", i); | |
316 | ||
eb22d84b MS |
317 | continue; |
318 | } | |
ff452e76 | 319 | |
1142bed2 | 320 | /* |
d610d201 FB |
321 | * copy unicode translation table unimapd is a ushort count and a pointer |
322 | * to an array of struct unipair { ushort, ushort } | |
1142bed2 | 323 | */ |
eb22d84b | 324 | r = ioctl(fd_d, PIO_UNIMAPCLR, &adv); |
aaa709bb | 325 | if (r < 0) { |
1142bed2 | 326 | log_warning_errno(errno, "PIO_UNIMAPCLR failed, unimaps might be incorrect for tty%u: %m", i); |
aaa709bb | 327 | continue; |
ff452e76 | 328 | } |
aaa709bb ZJS |
329 | |
330 | r = ioctl(fd_d, PIO_UNIMAP, &unimapd); | |
331 | if (r < 0) { | |
1142bed2 | 332 | log_warning_errno(errno, "PIO_UNIMAP failed, unimaps might be incorrect for tty%u: %m", i); |
aaa709bb ZJS |
333 | continue; |
334 | } | |
335 | ||
336 | log_debug("Font and unimap successfully copied to %s", ttyname); | |
dd04aac9 KS |
337 | } |
338 | } | |
339 | ||
1142bed2 MS |
340 | static int find_source_vc(char **ret_path, unsigned *ret_idx) { |
341 | _cleanup_free_ char *path = NULL; | |
c10d6bdb | 342 | int r, err = 0; |
1142bed2 | 343 | unsigned i; |
1142bed2 MS |
344 | |
345 | path = new(char, sizeof("/dev/tty63")); | |
234519ae | 346 | if (!path) |
1142bed2 MS |
347 | return log_oom(); |
348 | ||
349 | for (i = 1; i <= 63; i++) { | |
350 | _cleanup_close_ int fd = -1; | |
351 | ||
352 | r = verify_vc_allocation(i); | |
353 | if (r < 0) { | |
354 | if (!err) | |
355 | err = -r; | |
356 | continue; | |
357 | } | |
358 | ||
359 | sprintf(path, "/dev/tty%u", i); | |
360 | fd = open_terminal(path, O_RDWR|O_CLOEXEC|O_NOCTTY); | |
361 | if (fd < 0) { | |
362 | if (!err) | |
363 | err = -fd; | |
364 | continue; | |
365 | } | |
366 | r = verify_vc_kbmode(fd); | |
367 | if (r < 0) { | |
368 | if (!err) | |
369 | err = -r; | |
370 | continue; | |
371 | } | |
372 | ||
373 | /* all checks passed, return this one as a source console */ | |
374 | *ret_idx = i; | |
ae2a15bc | 375 | *ret_path = TAKE_PTR(path); |
c10d6bdb | 376 | return TAKE_FD(fd); |
1142bed2 MS |
377 | } |
378 | ||
379 | return log_error_errno(err, "No usable source console found: %m"); | |
380 | } | |
381 | ||
382 | static int verify_source_vc(char **ret_path, const char *src_vc) { | |
1142bed2 | 383 | _cleanup_close_ int fd = -1; |
c10d6bdb LP |
384 | char *path; |
385 | int r; | |
1142bed2 MS |
386 | |
387 | fd = open_terminal(src_vc, O_RDWR|O_CLOEXEC|O_NOCTTY); | |
388 | if (fd < 0) | |
389 | return log_error_errno(fd, "Failed to open %s: %m", src_vc); | |
390 | ||
391 | r = verify_vc_device(fd); | |
392 | if (r < 0) | |
393 | return log_error_errno(r, "Device %s is not a virtual console: %m", src_vc); | |
394 | ||
395 | r = verify_vc_allocation_byfd(fd); | |
396 | if (r < 0) | |
397 | return log_error_errno(r, "Virtual console %s is not allocated: %m", src_vc); | |
398 | ||
399 | r = verify_vc_kbmode(fd); | |
400 | if (r < 0) | |
401 | return log_error_errno(r, "Virtual console %s is not in K_XLATE or K_UNICODE: %m", src_vc); | |
402 | ||
403 | path = strdup(src_vc); | |
234519ae | 404 | if (!path) |
1142bed2 MS |
405 | return log_oom(); |
406 | ||
407 | *ret_path = path; | |
c10d6bdb | 408 | return TAKE_FD(fd); |
1142bed2 MS |
409 | } |
410 | ||
97c4a07d | 411 | int main(int argc, char **argv) { |
abee28c5 | 412 | _cleanup_free_ char |
1142bed2 | 413 | *vc = NULL, |
abee28c5 ZJS |
414 | *vc_keymap = NULL, *vc_keymap_toggle = NULL, |
415 | *vc_font = NULL, *vc_font_map = NULL, *vc_font_unimap = NULL; | |
416 | _cleanup_close_ int fd = -1; | |
1142bed2 MS |
417 | bool utf8, keyboard_ok; |
418 | unsigned idx = 0; | |
93c9a9d2 | 419 | int r; |
97c4a07d | 420 | |
6bf3c61c | 421 | log_setup_service(); |
97c4a07d | 422 | |
4c12626c LP |
423 | umask(0022); |
424 | ||
97c4a07d | 425 | if (argv[1]) |
1142bed2 MS |
426 | fd = verify_source_vc(&vc, argv[1]); |
427 | else | |
428 | fd = find_source_vc(&vc, &idx); | |
1142bed2 | 429 | if (fd < 0) |
abee28c5 | 430 | return EXIT_FAILURE; |
03044059 | 431 | |
653ab83b | 432 | utf8 = is_locale_utf8(); |
97c4a07d | 433 | |
aa8fbc74 | 434 | r = parse_env_file(NULL, "/etc/vconsole.conf", |
2034ec42 MS |
435 | "KEYMAP", &vc_keymap, |
436 | "KEYMAP_TOGGLE", &vc_keymap_toggle, | |
437 | "FONT", &vc_font, | |
438 | "FONT_MAP", &vc_font_map, | |
13df9c39 | 439 | "FONT_UNIMAP", &vc_font_unimap); |
2034ec42 | 440 | if (r < 0 && r != -ENOENT) |
da927ba9 | 441 | log_warning_errno(r, "Failed to read /etc/vconsole.conf: %m"); |
2034ec42 MS |
442 | |
443 | /* Let the kernel command line override /etc/vconsole.conf */ | |
01771226 LP |
444 | r = proc_cmdline_get_key_many( |
445 | PROC_CMDLINE_STRIP_RD_PREFIX, | |
446 | "vconsole.keymap", &vc_keymap, | |
447 | "vconsole.keymap_toggle", &vc_keymap_toggle, | |
448 | "vconsole.font", &vc_font, | |
449 | "vconsole.font_map", &vc_font_map, | |
450 | "vconsole.font_unimap", &vc_font_unimap, | |
451 | /* compatibility with obsolete multiple-dot scheme */ | |
452 | "vconsole.keymap.toggle", &vc_keymap_toggle, | |
453 | "vconsole.font.map", &vc_font_map, | |
454 | "vconsole.font.unimap", &vc_font_unimap); | |
455 | if (r < 0 && r != -ENOENT) | |
456 | log_warning_errno(r, "Failed to read /proc/cmdline: %m"); | |
1ebdf5b6 | 457 | |
31390963 LP |
458 | (void) toggle_utf8_sysfs(utf8); |
459 | (void) toggle_utf8(vc, fd, utf8); | |
93c9a9d2 ZJS |
460 | |
461 | r = font_load_and_wait(vc, vc_font, vc_font_map, vc_font_unimap); | |
c9d2b3d0 | 462 | keyboard_ok = keyboard_load_and_wait(vc, vc_keymap, vc_keymap_toggle, utf8) == 0; |
97c4a07d | 463 | |
1142bed2 | 464 | if (idx > 0) { |
93c9a9d2 | 465 | if (r == 0) |
1142bed2 | 466 | setup_remaining_vcs(fd, idx, utf8); |
93c9a9d2 ZJS |
467 | else if (r == EX_OSERR) |
468 | /* setfont returns EX_OSERR when ioctl(KDFONTOP/PIO_FONTX/PIO_FONTX) fails. | |
469 | * This might mean various things, but in particular lack of a graphical | |
470 | * console. Let's be generous and not treat this as an error. */ | |
471 | log_notice("Setting fonts failed with a \"system error\", ignoring."); | |
eb22d84b | 472 | else |
aaa709bb | 473 | log_warning("Setting source virtual console failed, ignoring remaining ones"); |
eb22d84b | 474 | } |
97c4a07d | 475 | |
93c9a9d2 | 476 | return IN_SET(r, 0, EX_OSERR) && keyboard_ok ? EXIT_SUCCESS : EXIT_FAILURE; |
97c4a07d | 477 | } |