summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAttila Lendvai <attila.lendvai@gmail.com>2023-12-17 01:44:24 +0100
committerLudovic Courtès <ludo@gnu.org>2023-12-17 22:51:46 +0100
commit9be0b7e6fbe3c2e743b5626f4dff7c7bf9becc16 (patch)
tree611866b3612c01b5e22b94a8ae89bba7dddbe1c3
parentd13c0568d02e47fd69f0e5e786dca0a19d2be24c (diff)
downloadshepherd-9be0b7e6fbe3c2e743b5626f4dff7c7bf9becc16.tar.gz
shepherd: Make sure ‘with-process-monitor’ covers everything needed.
Fixes <https://issues.guix.gnu.org/67839>. * modules/shepherd.scm (main): Switch with-service-registry and with-process-monitor. This way the parameterize of the process monitor covers everything else. This fixes the bug that caused `guix system reconfigure` to hang in certain situations. Fix proposed by @emixa-d at: https://github.com/wingo/fibers/issues/29#issuecomment-1858922276. * tests/replacement.sh: Use ‘fork+exec-command’ in #:start and add #:stop. Make sure ‘test’ can be restarted. Co-authored-by: Ludovic Courtès <ludo@gnu.org>
-rw-r--r--modules/shepherd.scm10
-rw-r--r--tests/replacement.sh15
2 files changed, 19 insertions, 6 deletions
diff --git a/modules/shepherd.scm b/modules/shepherd.scm
index efc5517..3303de3 100644
--- a/modules/shepherd.scm
+++ b/modules/shepherd.scm
@@ -450,13 +450,13 @@ fork in the child process."
;; because POSIX threads and 'fork' cannot be used together.
(run-fibers
(lambda ()
- (with-service-registry
+ (with-process-monitor
+ (with-service-registry
- ;; Register and start the 'root' service.
- (register-services (list root-service))
- (start-service root-service)
+ ;; Register and start the 'root' service.
+ (register-services (list root-service))
+ (start-service root-service)
- (with-process-monitor
;; Replace the default 'system*' binding with one that
;; cooperates instead of blocking on 'waitpid'. Replace
;; 'primitive-load' (in C as of 3.0.9) with one that does
diff --git a/tests/replacement.sh b/tests/replacement.sh
index 2e93555..76bdcd0 100644
--- a/tests/replacement.sh
+++ b/tests/replacement.sh
@@ -67,7 +67,8 @@ cat > "$rconf"<<EOF
'(test)
#:start (lambda _
(display "The replacement is starting.\n")
- #t)
+ (fork+exec-command '("$(type -P sleep)" "300")))
+ #:stop (make-kill-destructor)
#:actions (actions
(say-goodbye (lambda _
(call-with-output-file "$stamp"
@@ -95,3 +96,15 @@ $herd stop test
$herd disable test
$herd load root "$rconf"
$herd status test | grep disabled
+
+# Restarting the service from here used to trigger a bug:
+# <https://issues.guix.gnu.org/67839>.
+$herd enable test
+$herd start test
+
+child_pid="$($herd status test | grep Running \
+ | sed '-es/.*Running value is \([0-9]\+\)\./\1/g')"
+kill -0 "$child_pid"
+
+$herd stop test
+if kill -0 "$child_pid"; then false; else true; fi