[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 01/02: service: ‘herd unload root all’ stops services before
From: |
Ludovic Courtès |
Subject: |
[shepherd] 01/02: service: ‘herd unload root all’ stops services before unregistering them. |
Date: |
Sun, 21 Jan 2024 17:22:24 -0500 (EST) |
civodul pushed a commit to branch main
in repository shepherd.
commit b7fcdad75dff73fb4a8f531d0834eb9a965bcfd6
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Wed Jan 10 03:33:15 2024 +0300
service: ‘herd unload root all’ stops services before unregistering them.
Fixes <https://issues.guix.gnu.org/68357>.
Fixes a bug whereby ‘herd unload root all’ would unregister services
without first stopping them, leaving the system in a bogus state.
* modules/shepherd/service.scm (service-registry): Remove
'unregister-all case.
(deregister-service): Call ‘unregister-services’ instead of sending
'unregister-all message to the registry.
* tests/forking-service.sh: Test ‘herd unload root all’.
* NEWS: Update.
Co-authored-by: ShinyZero0 <shinyzero0@tilde.club>
---
NEWS | 7 +++++++
modules/shepherd/service.scm | 12 +++---------
tests/forking-service.sh | 13 ++++++++++++-
3 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/NEWS b/NEWS
index 11e717a..1e3f750 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,13 @@ Copyright © 2013-2014, 2016, 2018-2020, 2022-2024 Ludovic
Courtès <ludo@gnu.or
Please send Shepherd bug reports to bug-guix@gnu.org.
+* Changes in 0.10.4
+
+** ‘herd unload root all’ stops services before unregistering them
+
+Previously, since version 0.10.0, ‘herd unload root all’ would unregister all
+services without first stopping them, leaving the system in a bogus state.
+
* Changes in 0.10.3
** Fix a bug that could lead shepherd to hang after loading replacements
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 5be78bd..a17ed8f 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -1,5 +1,5 @@
;; service.scm -- Representation of services.
-;; Copyright (C) 2013-2023 Ludovic Courtès <ludo@gnu.org>
+;; Copyright (C) 2013-2024 Ludovic Courtès <ludo@gnu.org>
;; Copyright (C) 2002, 2003 Wolfgang Järling <wolfgang@pro-linux.de>
;; Copyright (C) 2014 Alex Sassmannshausen <alex.sassmannshausen@gmail.com>
;; Copyright (C) 2016 Alex Kost <alezost@gmail.com>
@@ -1136,11 +1136,6 @@ requests arriving on @var{channel}."
(length lst))
(map service-canonical-name lst))
(loop registered))))
- (('unregister-all) ;no reply
- (let ((root (cdr (vhash-assq 'root registered))))
- (loop (fold (cut vhash-consq <> root <>)
- vlist-null
- (service-provision root)))))
(('lookup name reply)
;; Look up NAME and return it, or #f, to REPLY.
(put-message reply
@@ -2637,9 +2632,8 @@ name, or if it is the only service providing the service
that is
requested to be removed."
(let ((name (string->symbol service-name)))
(cond ((eq? name 'all)
- ;; Special 'remove all' case.
- (put-message (current-registry-channel) `(unregister-all))
- #t)
+ ;; Stop and then unload every service.
+ (unregister-services (delq root-service (service-list))))
(else
;; Removing only one service.
(match (lookup-service name)
diff --git a/tests/forking-service.sh b/tests/forking-service.sh
index 9742cfe..3dd87cf 100644
--- a/tests/forking-service.sh
+++ b/tests/forking-service.sh
@@ -1,5 +1,5 @@
# GNU Shepherd --- Test detecting a forked process' termination
-# Copyright © 2016, 2020, 2022, 2023 Ludovic Courtès <ludo@gnu.org>
+# Copyright © 2016, 2020, 2022-2024 Ludovic Courtès <ludo@gnu.org>
# Copyright © 2018 Carlo Zancanaro <carlo@zancanaro.id.au>
#
# This file is part of the GNU Shepherd.
@@ -183,4 +183,15 @@ grep ignoring "$log"
grep SIGKILL "$log"
$herd status test3 | grep stopped
+# Start 'test'. Make sure 'unload all' terminates it.
+rm -f "$service_pid"
+$herd enable test
+$herd start test
+child_pid="$(cat "$service_pid")"
+kill -0 "$child_pid"
+$herd unload root all
+$herd status test && false
+kill -0 "$child_pid" && false
+test $($herd status | wc -l) = 2
+
$herd status