civodul pushed a commit to branch devel
in repository shepherd.

commit e6d510b4e6e309de7843acaf917f0d4c5e6e2ce9
Author: Ludovic Courtès <[email protected]>
AuthorDate: Sun Jun 2 16:40:26 2024 +0200

    service: Gracefully handle nonexistent dependencies.
    
    Previously shepherd would crash as it would pass #f to ‘start-service’.
    
    * modules/shepherd/service.scm (start-service): Use ‘lookup-service*’ for
    SERVICE’s requirements.
    * tests/config-failure.sh: Add test with ‘nonexistent-dependencies’.
---
 modules/shepherd/service.scm |  2 +-
 tests/config-failure.sh      | 12 +++++++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 3e2d537..e6ce7f2 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -932,7 +932,7 @@ found in the service registry."
   ;; It is not running; go ahead and launch it.
   (let ((problems
         ;; Resolve all dependencies.
-        (start-in-parallel (map lookup-service
+        (start-in-parallel (map lookup-service*
                                  (service-requirement service)))))
     (if (pair? problems)
         (begin
diff --git a/tests/config-failure.sh b/tests/config-failure.sh
index a3a4361..d6b5130 100644
--- a/tests/config-failure.sh
+++ b/tests/config-failure.sh
@@ -48,7 +48,12 @@ cat > "$conf" <<EOF
                    (call-with-output-file "$stamp" (const #t))
                    (error "faileddddd!"))
         #:stop (const #f)
-        #:respawn? #f)))
+        #:respawn? #f)
+       (service
+         '(nonexistent-dependencies)
+         #:requirement '(dependency-that-does-not-exist)
+         #:start (const #t)
+         #:stop (const #f))))
 
 (start-in-the-background '(this-thing-does-not-exist-but-that-is-fine))
 
@@ -73,6 +78,11 @@ while ! test -f "$stamp" ; do sleep 0.3 ; done
 $herd status failing | grep "stopped"
 $herd status succeeding | grep "running"
 
+# Check that a service with nonexistent dependencies cannot be started.
+$herd start nonexistent-dependencies && false
+$herd start nonexistent-dependencies 2>&1 | \
+    grep "dependency-that-does-not-exist.*not.*found"
+
 $herd stop root
 
 while kill -0 "$shepherd_pid" ; do sleep 0.3 ; done

Reply via email to