diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2017-12-06 08:52:31 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2017-12-06 08:52:31 +0100 |
| commit | 787e8a80d54d8bd5320d76276dc5f4bafe5b86c0 (patch) | |
| tree | 443a61c139a8451cc5b834451c04207c0293b694 | |
| parent | 45c32bd7e50adde4119b7a25b580cf3f77d5b91f (diff) | |
services: console-font: Use 'tcsetattr' instead of invoking 'unicode_start'.
This is more robust, faster, and incidentally gets rid of remaining
"error in the finalization thread: Bad file descriptor" messages.
* gnu/services/base.scm (unicode-start): Rewrite to use 'tcgetattr' and
'tcsetattr'.
(console-font-shepherd-services)[start]: Add 'loop' to check whether
DEVICE is ready. Tolerate EX_OSERR return from 'setfont'.
[modules]: New field.
| -rw-r--r-- | gnu/services/base.scm | 56 |
1 files changed, 38 insertions, 18 deletions
diff --git a/gnu/services/base.scm b/gnu/services/base.scm index 11f55c588cf..291dd63256f 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm | |||
| @@ -621,21 +621,23 @@ to add @var{device} to the kernel's entropy pool. The service will fail if | |||
| 621 | 621 | ||
| 622 | (define (unicode-start tty) | 622 | (define (unicode-start tty) |
| 623 | "Return a gexp to start Unicode support on @var{tty}." | 623 | "Return a gexp to start Unicode support on @var{tty}." |
| 624 | 624 | (with-imported-modules '((guix build syscalls)) | |
| 625 | ;; We have to run 'unicode_start' in a pipe so that when it invokes the | 625 | #~(let* ((fd (open-fdes #$tty O_RDWR)) |
| 626 | ;; 'tty' command, that command returns TTY. | 626 | (termios (tcgetattr fd))) |
| 627 | #~(begin | 627 | (define (set-utf8-input termios) |
| 628 | (let ((pid (primitive-fork))) | 628 | (set-field termios (termios-input-flags) |
| 629 | (case pid | 629 | (logior (input-flags IUTF8) |
| 630 | ((0) | 630 | (termios-input-flags termios)))) |
| 631 | (close-fdes 0) | 631 | |
| 632 | (dup2 (open-fdes #$tty O_RDONLY) 0) | 632 | ;; See console_codes(4). |
| 633 | (close-fdes 1) | 633 | (display "\x1b%G" (fdes->outport fd)) |
| 634 | (dup2 (open-fdes #$tty O_WRONLY) 1) | 634 | |
| 635 | (execl #$(file-append kbd "/bin/unicode_start") | 635 | (tcsetattr fd (tcsetattr-action TCSAFLUSH) |
| 636 | "unicode_start")) | 636 | (set-utf8-input termios)) |
| 637 | (else | 637 | |
| 638 | (zero? (cdr (waitpid pid)))))))) | 638 | ;; TODO: ioctl(fd, KDSKBMODE, K_UNICODE); |
| 639 | (close-fdes fd) | ||
| 640 | #t))) | ||
| 639 | 641 | ||
| 640 | (define console-keymap-service-type | 642 | (define console-keymap-service-type |
| 641 | (shepherd-service-type | 643 | (shepherd-service-type |
| @@ -674,11 +676,29 @@ to add @var{device} to the kernel's entropy pool. The service will fail if | |||
| 674 | (requirement (list (symbol-append 'term- | 676 | (requirement (list (symbol-append 'term- |
| 675 | (string->symbol tty)))) | 677 | (string->symbol tty)))) |
| 676 | 678 | ||
| 679 | (modules '((guix build syscalls) ;for 'tcsetattr' | ||
| 680 | (srfi srfi-9 gnu))) ;for 'set-field' | ||
| 677 | (start #~(lambda _ | 681 | (start #~(lambda _ |
| 682 | ;; It could be that mingetty is not fully ready yet, | ||
| 683 | ;; which we check by calling 'ttyname'. | ||
| 684 | (let loop ((i 10)) | ||
| 685 | (unless (or (zero? i) | ||
| 686 | (call-with-input-file #$device | ||
| 687 | (lambda (port) | ||
| 688 | (false-if-exception (ttyname port))))) | ||
| 689 | (usleep 500) | ||
| 690 | (loop (- i 1)))) | ||
| 691 | |||
| 678 | (and #$(unicode-start device) | 692 | (and #$(unicode-start device) |
| 679 | (zero? | 693 | ;; 'setfont' returns EX_OSERR (71) when an |
| 680 | (system* #$(file-append kbd "/bin/setfont") | 694 | ;; KDFONTOP ioctl fails, for example. Like |
| 681 | "-C" #$device #$font))))) | 695 | ;; systemd's vconsole support, let's not treat |
| 696 | ;; this as an error. | ||
| 697 | (case (status:exit-val | ||
| 698 | (system* #$(file-append kbd "/bin/setfont") | ||
| 699 | "-C" #$device #$font)) | ||
| 700 | ((0 71) #t) | ||
| 701 | (else #f))))) | ||
| 682 | (stop #~(const #t)) | 702 | (stop #~(const #t)) |
| 683 | (respawn? #f))))) | 703 | (respawn? #f))))) |
| 684 | tty+font)) | 704 | tty+font)) |
