From: attila.lendvai@gmail.com
To: guix-devel@gnu.org
Cc: Attila Lendvai <attila@lendvai.name>
Subject: [PATCH shepherd] service: Factor out SEND-TO-REGISTRY.
Date: Sun, 30 Jun 2024 18:13:05 +0200 [thread overview]
Message-ID: <20240630161303.22507-8-attila@lendvai.name> (raw)
In-Reply-To: <20240630161303.22507-2-attila@lendvai.name>
From: Attila Lendvai <attila@lendvai.name>
Also assert that (CURRENT-REGISTRY-CHANNEL) is valid.
* modules/shepherd/service.scm (with-service-registry): New function.
(stop-service), (fold-services), (service-name-count), (lookup-service),
(respawn-service), (register-services), (unregister-services): Use it.
---
modules/shepherd/service.scm | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index e1c602c..b5f3e23 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -1030,8 +1030,7 @@ in a list."
(report-exception 'stop service key args))))))
(when (transient-service? service)
- (put-message (current-registry-channel)
- `(unregister ,(list service)))
+ (send-to-registry `(unregister ,(list service)))
(local-output (l10n "Transient service ~a unregistered.")
(service-canonical-name service)))
@@ -1290,6 +1289,10 @@ task is one that should never fail)."
(parameterize ((current-registry-channel (spawn-service-registry)))
(thunk)))
+(define (send-to-registry message)
+ (assert (current-registry-channel))
+ (put-message (current-registry-channel) message))
+
(define-syntax-rule (with-service-registry exp ...)
"Spawn a new service monitor and evaluate @var{exp}... within that dynamic extent.
This allows @var{exp}... and their callees to send requests to delegate
@@ -2286,8 +2289,7 @@ This must be paired with @code{make-systemd-destructor}."
(lambda (proc init)
"Apply PROC to the registered services to build a result, and return that
result. Works in a manner akin to `fold' from SRFI-1."
- (put-message (current-registry-channel)
- `(service-list ,reply))
+ (send-to-registry `(service-list ,reply))
(fold (match-lambda*
(((name . service) result)
(if (eq? name (service-canonical-name service))
@@ -2311,15 +2313,14 @@ returned in unspecified."
(define (service-name-count)
"Return the number of currently-registered service names."
(let ((reply (make-channel)))
- (put-message (current-registry-channel)
- `(service-name-count ,reply))
+ (send-to-registry `(service-name-count ,reply))
(get-message reply)))
(define lookup-service
(let ((reply (make-channel)))
(lambda (name)
"Return the service that provides @var{name}, @code{#f} if there is none."
- (put-message (current-registry-channel) `(lookup ,name ,reply))
+ (send-to-registry `(lookup ,name ,reply))
(get-message reply))))
(define (lookup-services name)
@@ -2631,7 +2632,7 @@ then disable it."
(disable-service serv)
(when (transient-service? serv)
- (put-message (current-registry-channel) `(unregister (,serv)))
+ (send-to-registry `(unregister (,serv)))
(local-output (l10n "Transient service ~a terminated, now unregistered.")
(service-canonical-name serv))))))
@@ -2657,7 +2658,7 @@ If it is currently stopped, replace it immediately."
(assert (list-of-symbols? (service-requirement new)))
(assert (boolean? (respawn-service? new)))
- (put-message (current-registry-channel) `(register ,new)))
+ (send-to-registry `(register ,new)))
(let ((services (if (service? services)
(begin
@@ -2681,8 +2682,7 @@ already stopped."
services))
;; Remove STOPPED from the registry.
- (put-message (current-registry-channel)
- `(unregister ,stopped))
+ (send-to-registry `(unregister ,stopped))
#t)
(define (deregister-service service-name)
--
2.45.2
next prev parent reply other threads:[~2024-06-30 17:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-30 16:12 [PATCH shepherd] service: Add custom printer for <service> attila.lendvai
2024-06-30 16:13 ` [PATCH shepherd] service: Rename to QUERY-SERVICE-CONTROLLER and use CUT attila.lendvai
2024-06-30 16:13 ` [PATCH shepherd] service: Factor out SEND-TO-PROCESS-MONITOR attila.lendvai
2024-06-30 16:13 ` attila.lendvai [this message]
2024-06-30 16:13 ` [PATCH shepherd] service: Factor out SEND-TO-SERVICE-CONTROLLER attila.lendvai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240630161303.22507-8-attila@lendvai.name \
--to=attila.lendvai@gmail.com \
--cc=attila@lendvai.name \
--cc=guix-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.