* bug#64365: [Shepherd] Export deregister-service.
2023-06-30 14:30 bug#64365: [Shepherd] Export deregister-service Bruno Victal
@ 2023-07-12 20:52 ` Ludovic Courtès
2023-07-13 3:10 ` Bruno Victal
0 siblings, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2023-07-12 20:52 UTC (permalink / raw)
To: Bruno Victal; +Cc: 64365
[-- Attachment #1: Type: text/plain, Size: 758 bytes --]
Hi,
Bruno Victal <mirai@makinata.eu> skribis:
> Although 'register-services' is exported its counterpart
> 'deregister-service' is not.
>
> Some notes:
> * 'register-services' is in its plural form while its counterpart
> is not, maybe one of them should be renamed for consistency sake?
>
> * From the docstring and code the interface of 'deregister-service'
> seems to differ from 'register-services' though I haven't
> confirmed it. Perhaps add some documented examples for reference?
All good points. Since ‘deregister-service’ is an internal helper with
a clunky interface (it takes a string, special-cases "all", prints
messages), I propose exposing ‘unregister-services’ as defined below.
WDYT?
Thanks,
Ludo’.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 2165 bytes --]
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 6b8c562..e44cbef 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -95,6 +95,7 @@
spawn-shell-command
%precious-signals
register-services
+ unregister-services
default-respawn-limit
default-service-termination-handler
@@ -2554,6 +2555,19 @@ If it is currently stopped, replace it immediately."
(warn-deprecated-form)
(register-services services)))))
+(define (unregister-services services)
+ "Remove all of @var{services} from the registry, stopping them if they are not
+already stopped."
+ (for-each (lambda (service)
+ (unless (service-stopped? service)
+ (stop-service service)))
+ services)
+
+ ;; Remove SERVICE from the registry.
+ (put-message (current-registry-channel)
+ `(unregister ,services))
+ #t)
+
(define (deregister-service service-name)
"For each string in SERVICE-NAME, stop the associated service if
necessary and remove it from the services table. If SERVICE-NAME is
@@ -2562,13 +2576,6 @@ the special string 'all', remove all services except of 'root'.
This will remove a service either if it is identified by its canonical
name, or if it is the only service providing the service that is
requested to be removed."
- (define (deregister service)
- (when (service-running? service)
- (stop-service service))
- ;; Remove services provided by service from the hash table.
- (put-message (current-registry-channel)
- `(unregister ,(list service))))
-
(let ((name (string->symbol service-name)))
(cond ((eq? name 'all)
;; Special 'remove all' case.
@@ -2587,7 +2594,7 @@ requested to be removed."
(local-output
"Removing service '~a' providing '~a'..."
(service-canonical-name service) name))
- (deregister service)
+ (unregister-services (list service))
(local-output (l10n "Done."))))))))
(define (load-config file-name)
^ permalink raw reply related [flat|nested] 4+ messages in thread