civodul pushed a commit to branch devel
in repository shepherd.
commit 55ae77963119a29c1ad1640c77cb0947f56053d9
Author: Ludovic Courtès <[email protected]>
AuthorDate: Sun Jun 2 15:36:29 2024 +0200
service: Factorize ‘lookup-service*’.
* modules/shepherd/service.scm (lookup-service*): New procedure.
(deregister-service): Use it.
---
modules/shepherd/service.scm | 30 +++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index a92c0c3..32a09d4 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -924,6 +924,13 @@ while starting ~a: ~s")
(loop (- i 1) failures)))
failures)))))
+(define (lookup-service* name)
+ "Like @code{lookup-service}, but raise an exception if @var{name} is not
+found in the service registry."
+ (match (lookup-service name)
+ (#f (raise (condition (&missing-service-error (name name)))))
+ (service service)))
+
(define (start-service service . args)
"Start @var{service} and its dependencies, passing @var{args} to its
@code{start} method. Return its running value, @code{#f} on failure."
@@ -2677,19 +2684,16 @@ requested to be removed."
(unregister-services (delq root-service (service-list))))
(else
;; Removing only one service.
- (match (lookup-service name)
- (#f
- (raise (condition (&missing-service-error (name name)))))
- (service
- ;; Are we removing a user service…
- (if (eq? (service-canonical-name service) name)
- (local-output (l10n "Removing service '~a'...") name)
- ;; or a virtual service?
- (local-output
- "Removing service '~a' providing '~a'..."
- (service-canonical-name service) name))
- (unregister-services (list service))
- (local-output (l10n "Done."))))))))
+ (let ((service (lookup-service* name)))
+ ;; Are we removing a user service…
+ (if (eq? (service-canonical-name service) name)
+ (local-output (l10n "Removing service '~a'...") name)
+ ;; or a virtual service?
+ (local-output
+ "Removing service '~a' providing '~a'..."
+ (service-canonical-name service) name))
+ (unregister-services (list service))
+ (local-output (l10n "Done.")))))))
(define (load-config file-name)
(local-output (l10n "Loading ~a.") file-name)