services: Add 'virtual-terminal'.

Fixes <https://bugs.gnu.org/30505>.
Suggested by Danny Milosavljevic <dannym@scratchpost.org>.

* gnu/services/base.scm (unicode-start): Remove.
(virtual-terminal-service-type): New variable.
(console-font-shepherd-services): Remove 'modules'; remove call to
'unicode-start'.  Add 'virtual-terminal' to 'requirement'.
(mingetty-shepherd-service, kmscon-service-type): Likewise.
(%base-services): Add 'virtual-terminal-service-type'.
* gnu/system/install.scm (%installation-services): Likewise.
This commit is contained in:
Ludovic Courtès 2018-03-15 11:37:18 +01:00
parent 88cd7bbd3d
commit bb3062ad62
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
2 changed files with 40 additions and 31 deletions

View file

@ -62,6 +62,7 @@ (define-module (gnu services base)
%default-console-font
console-font-service-type
console-font-service
virtual-terminal-service-type
udev-configuration
udev-configuration?
@ -665,22 +666,27 @@ (define (host-name-service name)
"Return a service that sets the host name to @var{name}."
(service host-name-service-type name))
(define (unicode-start tty)
"Return a gexp to start Unicode support on @var{tty}."
(with-imported-modules '((guix build syscalls))
#~(let* ((fd (open-fdes #$tty O_RDWR))
(termios (tcgetattr fd)))
(define (set-utf8-input termios)
(set-field termios (termios-input-flags)
(logior (input-flags IUTF8)
(termios-input-flags termios))))
(tcsetattr fd (tcsetattr-action TCSAFLUSH)
(set-utf8-input termios))
;; TODO: ioctl(fd, KDSKBMODE, K_UNICODE);
(close-fdes fd)
#t)))
(define virtual-terminal-service-type
;; Ensure that virtual terminals run in UTF-8 mode. This is the case by
;; default with recent Linux kernels, but this service allows us to ensure
;; this. This service must start before any 'term-' service so that newly
;; created terminals inherit this property. See
;; <https://bugs.gnu.org/30505> for a discussion.
(shepherd-service-type
'virtual-terminal
(lambda (utf8?)
(shepherd-service
(documentation "Set virtual terminals in UTF-8 module.")
(provision '(virtual-terminal))
(requirement '(root-file-system))
(start #~(lambda _
(call-with-output-file
"/sys/module/vt/parameters/default_utf8"
(lambda (port)
(display 1 port)))
#t))
(stop #~(const #f))))
#t)) ;default to UTF-8
(define console-keymap-service-type
(shepherd-service-type
@ -719,8 +725,6 @@ (define (console-font-shepherd-services tty+font)
(requirement (list (symbol-append 'term-
(string->symbol tty))))
(modules '((guix build syscalls) ;for 'tcsetattr'
(srfi srfi-9 gnu))) ;for 'set-field'
(start #~(lambda _
;; It could be that mingetty is not fully ready yet,
;; which we check by calling 'ttyname'.
@ -732,16 +736,18 @@ (define (console-font-shepherd-services tty+font)
(usleep 500)
(loop (- i 1))))
(and #$(unicode-start device)
;; 'setfont' returns EX_OSERR (71) when an
;; KDFONTOP ioctl fails, for example. Like
;; systemd's vconsole support, let's not treat
;; this as an error.
(case (status:exit-val
(system* #$(file-append kbd "/bin/setfont")
"-C" #$device #$font))
((0 71) #t)
(else #f)))))
;; Assume the VT is already in UTF-8 mode, thanks to
;; the 'virtual-terminal' service.
;;
;; 'setfont' returns EX_OSERR (71) when an
;; KDFONTOP ioctl fails, for example. Like
;; systemd's vconsole support, let's not treat
;; this as an error.
(case (status:exit-val
(system* #$(file-append kbd "/bin/setfont")
"-C" #$device #$font))
((0 71) #t)
(else #f))))
(stop #~(const #t))
(respawn? #f)))))
tty+font))
@ -1093,7 +1099,7 @@ (define mingetty-shepherd-service
;; Since the login prompt shows the host name, wait for the 'host-name'
;; service to be done. Also wait for udev essentially so that the tty
;; text is not lost in the middle of kernel messages (XXX).
(requirement '(user-processes host-name udev))
(requirement '(user-processes host-name udev virtual-terminal))
(start #~(make-forkexec-constructor
(list #$(file-append mingetty "/sbin/mingetty")
@ -2034,7 +2040,7 @@ (define kmscon-command
(shepherd-service
(documentation "kmscon virtual terminal")
(requirement '(user-processes udev dbus-system))
(requirement '(user-processes udev dbus-system virtual-terminal))
(provision (list (symbol-append 'term- (string->symbol virtual-terminal))))
(start #~(make-forkexec-constructor #$kmscon-command))
(stop #~(make-kill-destructor)))))))
@ -2044,6 +2050,7 @@ (define %base-services
;; Convenience variable holding the basic services.
(list (login-service)
(service virtual-terminal-service-type)
(service console-font-service-type
(map (lambda (tty)
(cons tty %default-console-font))

View file

@ -214,7 +214,9 @@ (define (normal-tty tty)
(define bare-bones-os
(load "examples/bare-bones.tmpl"))
(list (mingetty-service (mingetty-configuration
(list (service virtual-terminal-service-type)
(mingetty-service (mingetty-configuration
(tty "tty1")
(auto-login "root")))