[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 03/04: shepherd: In non-signalfd, fix dynamic state of signal
From: |
Ludovic Courtès |
Subject: |
[shepherd] 03/04: shepherd: In non-signalfd, fix dynamic state of signal handlers. |
Date: |
Sun, 24 Dec 2023 09:06:18 -0500 (EST) |
civodul pushed a commit to branch main
in repository shepherd.
commit 1ff1527641c7b0a34e3bd20ea12e2c48ab6b3885
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Sun Dec 24 12:10:23 2023 +0100
shepherd: In non-signalfd, fix dynamic state of signal handlers.
* modules/shepherd.scm (main): Move ‘sigaction’ calls for all of
%PRECIOUS-SIGNALS under ‘unless signal-port’. Wrap handler in
‘capture-dynamic-state’.
* tests/signals.sh: Use ‘make-forkexec-constructor’ and ‘kill’.
---
modules/shepherd.scm | 17 ++++++++---------
tests/signals.sh | 8 ++++++--
2 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/modules/shepherd.scm b/modules/shepherd.scm
index 9040ae1..6b22b22 100644
--- a/modules/shepherd.scm
+++ b/modules/shepherd.scm
@@ -450,12 +450,6 @@ fork in the child process."
(false-if-exception
(dynamic-link (string-append %pkglibdir "/crash-handler"))))
- ;; Install signal handlers for everything but SIGCHLD, which is taken
- ;; care of in (shepherd services).
- (for-each (lambda (signal)
- (sigaction signal (signal-handler signal)))
- (delete SIGCHLD %precious-signals))
-
;; Run Fibers in such a way that it does not create any POSIX thread,
;; because POSIX threads and 'fork' cannot be used together.
(run-fibers
@@ -467,11 +461,16 @@ fork in the child process."
(register-services (list root-service))
(start-service root-service)
- ;; Install the SIGCHLD handler on systems that don't support
+ ;; Install signal handlers on systems that don't support
;; signalfd(2). Capture the current dynamic state so that
- ;; 'current-process-monitor' has the right value when the
- ;; handler is invoked.
+ ;; 'current-process-monitor' & co. have the right value when
+ ;; the handler is invoked.
(unless signal-port
+ (for-each (lambda (signal)
+ (sigaction signal
+ (capture-dynamic-state (signal-handler
signal))))
+ (delete SIGCHLD %precious-signals))
+
(sigaction SIGCHLD (capture-dynamic-state handle-SIGCHLD)
SA_NOCLDSTOP))
diff --git a/tests/signals.sh b/tests/signals.sh
index 59fd183..5081b1c 100644
--- a/tests/signals.sh
+++ b/tests/signals.sh
@@ -36,8 +36,12 @@ cat > "$conf"<<EOF
(register-services
(list (service
'(test)
- #:start (const #t)
- #:stop (lambda _
+ ;; Use a real process to exhibit the scenario where
+ ;; the signal handler needs to send a message to
+ ;; the process monitor and/or service registry.
+ #:start (make-forkexec-constructor '("sleep" "100"))
+ #:stop (lambda (pid)
+ (kill pid SIGKILL)
(call-with-output-file "$stamp"
(lambda (port)
(display "stopped" port)))