[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] branch main updated: service: Preserve replacement bindings a
From: |
Ludovic Courtès |
Subject: |
[shepherd] branch main updated: service: Preserve replacement bindings after ‘daemonize’. |
Date: |
Mon, 13 Jan 2025 05:39:58 -0500 |
This is an automated email from the git hooks/post-receive script.
civodul pushed a commit to branch main
in repository shepherd.
The following commit(s) were added to refs/heads/main by this push:
new ffcd374 service: Preserve replacement bindings after ‘daemonize’.
ffcd374 is described below
commit ffcd3745e5d8a3e4134ae76fe94a5ec80f52c465
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Mon Jan 13 11:36:41 2025 +0100
service: Preserve replacement bindings after ‘daemonize’.
Partly fixes <https://issues.guix.gnu.org/75460>.
* modules/shepherd.scm (replace-core-bindings!): Add
#:preserve-replacement-bindings?
to the ‘primitive-fork’ replacement and honor it.
* modules/shepherd/service.scm (root-service) <daemonize>:
Pass #:preserve-replacement-bindings? #t to ‘primitive-fork’.
* tests/daemonize.sh: Add test.
Reported-by: Simen Endsjø <contact@simendsjo.me>
---
NEWS | 13 +++++++++++++
modules/shepherd.scm | 10 +++++++---
modules/shepherd/service.scm | 8 ++++++--
tests/daemonize.sh | 12 +++++++++++-
4 files changed, 37 insertions(+), 6 deletions(-)
diff --git a/NEWS b/NEWS
index ccda00e..605b754 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,19 @@ Copyright © 2013-2014, 2016, 2018-2020, 2022-2025 Ludovic
Courtès <ludo@gnu.or
Please send Shepherd bug reports to bug-guix@gnu.org.
+* Changes in 1.0.2
+
+** ‘daemonize’ action preserves replacement bindings for ‘sleep’ etc.
+ (<https://issues.guix.gnu.org/75460>)
+
+The shepherd process replaces bindings for ‘sleep’, ‘system*’, ‘system’, and
+other core Guile procedures with cooperative variants thereof—for instance, it
+replaces ‘sleep’ with Fibers’ own ‘sleep’ procedure, which does not block.
+
+Previously, the ‘daemonize’ action would remove those binding replacements,
+which could lead to blocking in shepherd, with symptoms such as ‘herd status’
+not responding. This is now fixed.
+
* Changes in 1.0.1
** ‘reboot --kexec’ aborts early on if no kexec image was loaded
diff --git a/modules/shepherd.scm b/modules/shepherd.scm
index c370439..4f5b2cd 100644
--- a/modules/shepherd.scm
+++ b/modules/shepherd.scm
@@ -1,5 +1,5 @@
;; shepherd.scm -- The daemon shepherd.
-;; Copyright (C) 2013-2014, 2016, 2018-2020, 2022-2024 Ludovic Courtès
<ludo@gnu.org>
+;; Copyright (C) 2013-2014, 2016, 2018-2020, 2022-2025 Ludovic Courtès
<ludo@gnu.org>
;; Copyright (C) 2002, 2003 Wolfgang Jährling <wolfgang@pro-linux.de>
;; Copyright (C) 2018 Carlo Zancanaro <carlo@zancanaro.id.au>
;; Copyright (C) 2018 Danny Milosavljevic <dannym@scratchpost.org>
@@ -347,9 +347,13 @@ fork in the child process."
((_ () <> ((binding value) ...))
(let ((real-primitive-fork primitive-fork))
(set! primitive-fork
- (lambda ()
+ (lambda* (#:key preserve-replacement-bindings?)
+ ;; Like 'primitive-fork', but restore the original core Guile
+ ;; bindings in the child process, unless
+ ;; PRESERVE-REPLACEMENT-BINDINGS? is true.
(let ((result (real-primitive-fork)))
- (when (zero? result)
+ (when (and (zero? result)
+ (not preserve-replacement-bindings?))
(set! binding value)
...
(set! primitive-fork real-primitive-fork))
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index b0be2c5..b4424e1 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -1,5 +1,5 @@
;; service.scm -- Representation of services.
-;; Copyright (C) 2013-2024 Ludovic Courtès <ludo@gnu.org>
+;; Copyright (C) 2013-2025 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>
@@ -2845,7 +2845,11 @@ we want to receive these signals."
#f)
(else
(local-output (l10n "Daemonizing..."))
- (if (zero? (primitive-fork))
+
+ ;; Tell the 'primitive-fork' replacement installed by
+ ;; (shepherd) that it must preserve the replacement bindings
+ ;; for 'sleep', 'system*', etc.
+ (if (zero? (primitive-fork #:preserve-replacement-bindings? #t))
(begin
(catch-system-error (prctl PR_SET_CHILD_SUBREAPER 1))
(setsid) ;detach from controlling terminal
diff --git a/tests/daemonize.sh b/tests/daemonize.sh
index 86df442..cad129a 100644
--- a/tests/daemonize.sh
+++ b/tests/daemonize.sh
@@ -1,5 +1,5 @@
# GNU Shepherd --- Check the 'daemonize' action of the root service.
-# Copyright © 2023-2024 Ludovic Courtès <ludo@gnu.org>
+# Copyright © 2023-2025 Ludovic Courtès <ludo@gnu.org>
#
# This file is part of the GNU Shepherd.
#
@@ -70,4 +70,14 @@ $herd status root | grep "PID: $new_pid"
$herd status
until $herd status a | grep running; do sleep 0.3; done
+# Were the non-blocking bindings for 'sleep', 'system*', etc. preserved after
+# daemonization? Check the 'sleep' binding.
+$herd eval root '(when (eq? sleep (@ (fibers) sleep)) (display "GOOD\n"))' \
+ | grep GOOD
+
+# If it's the non-blocking 'sleep' variant, the 'herd status' command below
+# completes immediately; otherwise it blocks until 'sleep' terminates.
+$herd eval root '(sleep 500)' &
+$herd status
+
$herd stop root
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [shepherd] branch main updated: service: Preserve replacement bindings after ‘daemonize’.,
Ludovic Courtès <=