civodul pushed a commit to branch devel
in repository shepherd.
commit 6cc1842cd3d4521482833ba3c9ab84292688eb53
Author: Ludovic Courtès <[email protected]>
AuthorDate: Sun Jun 2 16:18:19 2024 +0200
service: ‘start-in-the-background’ gracefully handles unknown services.
Previously, that fiber would crash with a backtrace as it would pass #f
to ‘start-in-parallel’.
* modules/shepherd/service.scm (start-in-the-background)[lookup]: New
procedure.
Use it along with ‘filter-map’.
* tests/config-failure.sh: Add ‘start-in-the-background’ call in config
file.
---
modules/shepherd/service.scm | 11 ++++++++++-
tests/config-failure.sh | 2 ++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index f22faef..3e2d537 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -1311,9 +1311,18 @@ waiting until all of @var{services} have been started.
This procedure can be useful in a configuration file because it lets you
interact right away with shepherd using the @command{herd} command."
+ (define (lookup name)
+ (match (lookup-service name)
+ (#f
+ (local-output (l10n "Service '~a' is unknown and cannot be started.")
+ name)
+ #f)
+ (service
+ service)))
+
(spawn-fiber
(lambda ()
- (let ((services (map lookup-service services)))
+ (let ((services (filter-map lookup services)))
(match (start-in-parallel services)
(()
(local-output
diff --git a/tests/config-failure.sh b/tests/config-failure.sh
index 7453447..a3a4361 100644
--- a/tests/config-failure.sh
+++ b/tests/config-failure.sh
@@ -50,6 +50,8 @@ cat > "$conf" <<EOF
#:stop (const #f)
#:respawn? #f)))
+(start-in-the-background '(this-thing-does-not-exist-but-that-is-fine))
+
(start-service (lookup-service 'failing))
EOF