[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 04/05: shepherd: Restore 'system*' in the child process after
From: |
Ludovic Courtès |
Subject: |
[shepherd] 04/05: shepherd: Restore 'system*' in the child process after fork. |
Date: |
Wed, 16 Nov 2022 18:00:58 -0500 (EST) |
civodul pushed a commit to branch master
in repository shepherd.
commit 279f0db355182ef431b8b844eacbff0d2a4e70f9
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Wed Nov 16 23:20:19 2022 +0100
shepherd: Restore 'system*' in the child process after fork.
This is a followup to 975b0aa0d6f0a184f712c935cd1ad284cd39deaf.
Users such as the marionette service in Guix expect to be able to call
'primitive-fork' from shepherd and be able to run Guile code right from
there, without exec'ing. This change makes sure they get a usable
'system*'.
* modules/shepherd.scm (main): Replace 'primitive-fork' with a procedure
that restores 'system*' in the child.
---
modules/shepherd.scm | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/modules/shepherd.scm b/modules/shepherd.scm
index 3e2e9ec..cce0507 100644
--- a/modules/shepherd.scm
+++ b/modules/shepherd.scm
@@ -420,7 +420,18 @@ already ~a threads running, disabling 'signalfd' support")
;; Replace the default 'system*' binding with one that
;; cooperates instead of blocking on 'waitpid'.
- (set! system* spawn-command)
+ (let ((real-system* system*))
+ (set! system* spawn-command)
+
+ ;; Restore 'system*' after fork.
+ (set! primitive-fork
+ (let ((real-fork primitive-fork))
+ (lambda ()
+ (let ((result (real-fork)))
+ (when (zero? result)
+ (set! primitive-fork real-fork)
+ (set! system* real-system*))
+ result)))))
(run-daemon #:socket-file socket-file
#:config-file config-file
- [shepherd] branch master updated (ada8807 -> 4c031cf), Ludovic Courtès, 2022/11/16
- [shepherd] 03/05: support: Make the 'load' and 'eval' actions suspendable., Ludovic Courtès, 2022/11/16
- [shepherd] 05/05: Update 'NEWS'., Ludovic Courtès, 2022/11/16
- [shepherd] 02/05: service: 'eval' action gracefully handles user code returning zero values., Ludovic Courtès, 2022/11/16
- [shepherd] 04/05: shepherd: Restore 'system*' in the child process after fork.,
Ludovic Courtès <=
- [shepherd] 01/05: service: 'make-kill-destructor' waits for termination, eventually SIGKILLs., Ludovic Courtès, 2022/11/16