services: udev: Explicitly depend on (gnu build linux-boot).

* gnu/services/base.scm (udev-shepherd-service): Wrap 'start' method in
'with-imported-modules'.
This commit is contained in:
Ludovic Courtès 2019-10-06 12:42:41 +02:00
parent 62c2217570
commit 38b1ea0434
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 55 additions and 52 deletions

View File

@ -1996,64 +1996,67 @@ item of @var{packages}."
(requirement '(root-file-system)) (requirement '(root-file-system))
(documentation "Populate the /dev directory, dynamically.") (documentation "Populate the /dev directory, dynamically.")
(start #~(lambda () (start
(define udevd (with-imported-modules (source-module-closure
;; 'udevd' from eudev. '((gnu build linux-boot)))
#$(file-append udev "/sbin/udevd")) #~(lambda ()
(define udevd
;; 'udevd' from eudev.
#$(file-append udev "/sbin/udevd"))
(define (wait-for-udevd) (define (wait-for-udevd)
;; Wait until someone's listening on udevd's control ;; Wait until someone's listening on udevd's control
;; socket. ;; socket.
(let ((sock (socket AF_UNIX SOCK_SEQPACKET 0))) (let ((sock (socket AF_UNIX SOCK_SEQPACKET 0)))
(let try () (let try ()
(catch 'system-error (catch 'system-error
(lambda () (lambda ()
(connect sock PF_UNIX "/run/udev/control") (connect sock PF_UNIX "/run/udev/control")
(close-port sock)) (close-port sock))
(lambda args (lambda args
(format #t "waiting for udevd...~%") (format #t "waiting for udevd...~%")
(usleep 500000) (usleep 500000)
(try)))))) (try))))))
;; Allow udev to find the modules. ;; Allow udev to find the modules.
(setenv "LINUX_MODULE_DIRECTORY" (setenv "LINUX_MODULE_DIRECTORY"
"/run/booted-system/kernel/lib/modules") "/run/booted-system/kernel/lib/modules")
;; The first one is for udev, the second one for eudev. ;; The first one is for udev, the second one for eudev.
(setenv "UDEV_CONFIG_FILE" #$udev.conf) (setenv "UDEV_CONFIG_FILE" #$udev.conf)
(setenv "EUDEV_RULES_DIRECTORY" (setenv "EUDEV_RULES_DIRECTORY"
#$(file-append rules "/lib/udev/rules.d")) #$(file-append rules "/lib/udev/rules.d"))
(let* ((kernel-release (let* ((kernel-release
(utsname:release (uname))) (utsname:release (uname)))
(linux-module-directory (linux-module-directory
(getenv "LINUX_MODULE_DIRECTORY")) (getenv "LINUX_MODULE_DIRECTORY"))
(directory (directory
(string-append linux-module-directory "/" (string-append linux-module-directory "/"
kernel-release)) kernel-release))
(old-umask (umask #o022))) (old-umask (umask #o022)))
;; If we're in a container, DIRECTORY might not exist, ;; If we're in a container, DIRECTORY might not exist,
;; for instance because the host runs a different ;; for instance because the host runs a different
;; kernel. In that case, skip it; we'll just miss a few ;; kernel. In that case, skip it; we'll just miss a few
;; nodes like /dev/fuse. ;; nodes like /dev/fuse.
(when (file-exists? directory) (when (file-exists? directory)
(make-static-device-nodes directory)) (make-static-device-nodes directory))
(umask old-umask)) (umask old-umask))
(let ((pid (fork+exec-command (list udevd)))) (let ((pid (fork+exec-command (list udevd))))
;; Wait until udevd is up and running. This appears to ;; Wait until udevd is up and running. This appears to
;; be needed so that the events triggered below are ;; be needed so that the events triggered below are
;; actually handled. ;; actually handled.
(wait-for-udevd) (wait-for-udevd)
;; Trigger device node creation. ;; Trigger device node creation.
(system* #$(file-append udev "/bin/udevadm") (system* #$(file-append udev "/bin/udevadm")
"trigger" "--action=add") "trigger" "--action=add")
;; Wait for things to settle down. ;; Wait for things to settle down.
(system* #$(file-append udev "/bin/udevadm") (system* #$(file-append udev "/bin/udevadm")
"settle") "settle")
pid))) pid))))
(stop #~(make-kill-destructor)) (stop #~(make-kill-destructor))
;; When halting the system, 'udev' is actually killed by ;; When halting the system, 'udev' is actually killed by
@ -2061,7 +2064,7 @@ item of @var{packages}."
;; Thus, make sure it is not respawned. ;; Thus, make sure it is not respawned.
(respawn? #f) (respawn? #f)
;; We need additional modules. ;; We need additional modules.
(modules `((gnu build linux-boot) (modules `((gnu build linux-boot) ;'make-static-device-nodes'
,@%default-modules)) ,@%default-modules))
(actions (list (shepherd-action (actions (list (shepherd-action