summary refs log tree commit diff
path: root/gnu/services/shepherd.scm
diff options
context:
space:
mode:
authorMaxim Cournoyer <maxim.cournoyer@gmail.com>2022-09-15 11:29:02 -0400
committerMaxim Cournoyer <maxim.cournoyer@gmail.com>2022-09-15 11:43:21 -0400
commit4920f6e634eeecb37b501bdc024dfe0aab849ed0 (patch)
treec7dd5859715071cb602133b67449a29488027f70 /gnu/services/shepherd.scm
parent513091dbd2eeba138b558f5f9bb1ee6e68eee01d (diff)
parent3d297a0017210f1dd135592efb10846840a8af88 (diff)
downloadguix-4920f6e634eeecb37b501bdc024dfe0aab849ed0.tar.gz
Merge branch 'staging' into core-updates
Conflicts resolved in:
	gnu/local.mk
	gnu/packages/cmake.scm
	gnu/packages/glib.scm
	gnu/packages/gnome.scm
	gnu/packages/gtk.scm
	gnu/packages/sdl.scm

pango-next, vala-next and librsvg-bootstrap were removed in the process.
Diffstat (limited to 'gnu/services/shepherd.scm')
-rw-r--r--gnu/services/shepherd.scm27
1 files changed, 26 insertions, 1 deletions
diff --git a/gnu/services/shepherd.scm b/gnu/services/shepherd.scm
index 4fd4b2a497..61f759a19d 100644
--- a/gnu/services/shepherd.scm
+++ b/gnu/services/shepherd.scm
@@ -344,6 +344,31 @@ as shepherd package."
           (use-modules (srfi srfi-34)
                        (system repl error-handling))
 
+          (define (call-with-file file flags proc)
+            (let ((port #f))
+              (dynamic-wind
+                (lambda ()
+                  (set! port (open file flags)))
+                (lambda ()
+                  (proc port))
+                (lambda ()
+                  (close-port port)
+                  (set! port #f)))))
+
+          ;; There's code run from shepherd that uses 'call-with-input-file' &
+          ;; co.--e.g., the 'urandom-seed' service.  Starting from Shepherd
+          ;; 0.9.2, users need to make sure not to leak non-close-on-exec file
+          ;; descriptors to child processes.  To address that, replace the
+          ;; standard bindings with O_CLOEXEC variants.
+          (set! call-with-input-file
+                (lambda (file proc)
+                  (call-with-file file (logior O_RDONLY O_CLOEXEC)
+                                  proc)))
+          (set! call-with-output-file
+                (lambda (file proc)
+                  (call-with-file file (logior O_WRONLY O_CREAT O_CLOEXEC)
+                                  proc)))
+
           ;; Specify the default environment visible to all the services.
           ;; Without this statement, all the environment variables of PID 1
           ;; are inherited by child services.
@@ -387,7 +412,7 @@ as shepherd package."
             ;; call; this avoids situations where services wrongfully lead
             ;; PID 1 to read from stdin (the console), which users may not
             ;; have access to (see <https://bugs.gnu.org/23697>).
-            (redirect-port (open-input-file "/dev/null")
+            (redirect-port (open "/dev/null" (logior O_RDONLY O_CLOEXEC))
                            (current-input-port)))))
 
     (scheme-file "shepherd.conf" config)))