services: static-networking: Run set-up/tear-down as a separate process.

Running that code in PID 1 was fun but it’s not really beneficial and
somewhat risky: risk of blocking, file descriptor leak, inability to
reload Guile-Netlink in shepherd when it’s upgraded, and so on.

This change runs set-up and tear-down as separate processes, which, for
the price of one fork(1), buys us peace of mind.

* gnu/services/base.scm (network-set-up/hurd, network-tear-down/hurd)
(network-tear-down/linux): Use ‘program-file’ instead of ‘scheme-file’.
(network-set-up/linux): Likewise, and remove #:blocking? argument to
‘wait-for-link’.

Change-Id: Ia41479b50eab31ea40c67243fcb1cffe29ac874a
This commit is contained in:
Ludovic Courtès 2024-12-25 18:56:30 +01:00
parent 911f205dda
commit 8d649a8d17
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -3055,8 +3055,8 @@ (define (network-set-up/hurd config)
;; The Hurd implements SIOCGIFADDR and other old-style ioctls, but the only
;; way to set up IPv6 is by starting pfinet with the right options.
(if (equal? (static-networking-provision config) '(loopback))
(scheme-file "set-up-pflocal" #~(begin 'nothing-to-do! #t))
(scheme-file "set-up-pfinet"
(program-file "set-up-pflocal" #~(begin 'nothing-to-do! #t))
(program-file "set-up-pfinet"
(with-imported-modules '((guix build utils))
#~(begin
(use-modules (guix build utils)
@ -3077,7 +3077,7 @@ (define (network-set-up/hurd config)
options)))))))
(define (network-tear-down/hurd config)
(scheme-file "tear-down-pfinet"
(program-file "tear-down-pfinet"
(with-imported-modules '((guix build utils))
#~(begin
(use-modules (guix build utils))
@ -3094,7 +3094,7 @@ (define (network-tear-down/hurd config)
(define (network-set-up/linux config)
(match-record config <static-networking>
(addresses links routes)
(scheme-file "set-up-network"
(program-file "set-up-network"
(with-extensions (list guile-netlink)
#~(begin
(use-modules (ip addr) (ip link) (ip route)
@ -3174,8 +3174,7 @@ (define (alist->keyword+value alist)
;; Before going any further, wait for the
;; device to show up.
(wait-for-link
#$(network-address-device address)
#:blocking? #f)
#$(network-address-device address))
(addr-add #$(network-address-device address)
#$(network-address-value address)
@ -3203,7 +3202,7 @@ (define (alist->keyword+value alist)
(define (network-tear-down/linux config)
(match-record config <static-networking>
(addresses links routes)
(scheme-file "tear-down-network"
(program-file "tear-down-network"
(with-extensions (list guile-netlink)
#~(begin
(use-modules (ip addr) (ip link) (ip route)
@ -3267,16 +3266,18 @@ (define (static-networking-shepherd-service config)
(start #~(lambda _
;; Return #t if successfully started.
(load #$(let-system (system target)
(zero? (system*
#$(let-system (system target)
(if (string-contains (or target system) "-linux")
(network-set-up/linux config)
(network-set-up/hurd config))))))
(network-set-up/hurd config)))))))
(stop #~(lambda _
;; Return #f is successfully stopped.
(load #$(let-system (system target)
(zero? (system*
#$(let-system (system target)
(if (string-contains (or target system) "-linux")
(network-tear-down/linux config)
(network-tear-down/hurd config))))))
(network-tear-down/hurd config)))))))
(respawn? #f)))))
(define (static-networking-shepherd-services networks)