~ruther/guix-local

3bb6147fdcba173708da33cc7d33124ebc639e56 — Maxim Cournoyer 1 year, 2 months ago 9b281fd
services: udev: Also create subsystem nodes at boot.

This is a more correct fix to CDROM/DVDROM events/auto-mounting than was made
in the now-reverted commit 670724edcfe7d ("gnu: eudev: Fix optical discs
detection/auto-mounting.")

This changes causes the 60-block.rules udev rules file shipped with eudev to
correctly set the default polling period to 2000 ms on block devices, which is
necessary for kernel events to be fired for CDROM drives for example.  To
validate it is set:

  # cat /sys/module/block/parameters/events_dfl_poll_msecs
  2000

Before, it would return 0.

* gnu/services/base.scm (udev-shepherd-service): <#:start>: Add a 'udevadm
trigger --change=add --type=subsystems' invocation, so that it also creates
subsystem nodes, as done in Void Linux or LinuxFromScratch init scripts for
example.
* gnu/tests/base.scm (run-basic-test): Add test.

Fixes: <https://issues.guix.gnu.org/35584>
Change-Id: Idc0eb5640163b27e41b72cc0c1885412a60805c1
2 files changed, 23 insertions(+), 7 deletions(-)

M gnu/services/base.scm
M gnu/tests/base.scm
M gnu/services/base.scm => gnu/services/base.scm +9 -6
@@ 2740,19 2740,22 @@ item of PACKAGES."
                         (cons*
                          (string-append "LINUX_MODULE_DIRECTORY="
                                         (getenv "LINUX_MODULE_DIRECTORY"))
                          (default-environment-variables)))))
                          (default-environment-variables))))
                   (udevadm #$(file-append udev "/bin/udevadm")))
               ;; Wait until udevd is up and running.  This appears to
               ;; be needed so that the events triggered below are
               ;; actually handled.
               (wait-for-udevd)

               ;; Trigger device node creation.
               (system* #$(file-append udev "/bin/udevadm")
                        "trigger" "--action=add")
               ;; Trigger device and subsystem nodes creation.  Note that as
               ;; of eudev v3.2.14, it is missing the '--type=all' found in
               ;; systemd.
               (system* udevadm "trigger" "--action=add" "--type=devices")
               (system* udevadm "trigger" "--action=add" "--type=subsystems")

               ;; Wait for things to settle down.
               (system* #$(file-append udev "/bin/udevadm")
                        "settle")
               (system* udevadm "settle")

               pid))))
      (stop #~(make-kill-destructor))


M gnu/tests/base.scm => gnu/tests/base.scm +14 -1
@@ 1,7 1,7 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2016-2020, 2022, 2024-2025 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org>
;;; Copyright © 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;; Copyright © 2022, 2025 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;; Copyright © 2022 Marius Bakke <marius@gnu.org>
;;; Copyright © 2024 Dariqq <dariqq@posteo.net>
;;;


@@ 546,6 546,19 @@ info --version")
                                      #$(operating-system-host-name os)))))
             #:ocr #$(file-append ocrad "/bin/ocrad")))

          (test-equal "block devices have correct default polling value"
            "2000"
            ;; This tests that the 'udevadm trigger' correctly creates the
            ;; subsystems nodes, by checking that the standard 60-block.rules
            ;; udev rules was applied.
            (marionette-eval
             '(begin
                (use-modules (ice-9 textual-ports))
                (call-with-input-file
                    "/sys/module/block/parameters/events_dfl_poll_msecs"
                  (compose string-trim-right get-string-all)))
             marionette))

          (test-end))))

  (gexp->derivation name test))