summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2026-07-11 10:24:56 +0200
committerLudovic Courtès <ludo@gnu.org>2026-08-27 14:41:26 +0200
commit46a6cfa7e3bfd6fa4646342196bac165efd275a2 (patch)
tree2768e13a031e87b079b9e7f0c8096597b484728a
parentd5a73f4734f21ac15b9ade3ec71162f00ae746c4 (diff)
least-authority-wrapper: Set ‘LISTEN_PID’ to the right PID.
This fixes socket activation of least-authority-wrapped programs. Partly addresses shepherd/shepherd#122. * guix/least-authority.scm (least-authority-wrapper): Define ‘listen-pid?’ and set ‘LISTEN_PID’ to namespace-local PID when it is set. Reported-by: Maxim Cournoyer <maxim@guixotic.coop> Signed-off-by: Ludovic Courtès <ludo@gnu.org> Merges: #9866
-rw-r--r--guix/least-authority.scm12
1 files changed, 11 insertions, 1 deletions
diff --git a/guix/least-authority.scm b/guix/least-authority.scm
index cd846aaa61d..68dc7e68e8c 100644
--- a/guix/least-authority.scm
+++ b/guix/least-authority.scm
@@ -1,5 +1,5 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2022-2023 Ludovic Courtès <ludo@gnu.org> 2;;; Copyright © 2022-2023, 2026 Ludovic Courtès <ludo@gnu.org>
3;;; 3;;;
4;;; This file is part of GNU Guix. 4;;; This file is part of GNU Guix.
5;;; 5;;;
@@ -82,6 +82,12 @@ resulting wrapper be executed as root so it can call setgid(2) and setuid(2)."
82 (string-append variable "=" value)))) 82 (string-append variable "=" value))))
83 '#$preserved-environment-variables)) 83 '#$preserved-environment-variables))
84 84
85 (define listen-pid?
86 ;; The 'LISTEN_PID' variable, used for socket activation, needs to
87 ;; point to the correct PID.
88 (eqv? (and=> (getenv "LISTEN_PID") string->number)
89 (getpid)))
90
85 (define (read-file file) 91 (define (read-file file)
86 (call-with-input-file file read)) 92 (call-with-input-file file read))
87 93
@@ -136,6 +142,10 @@ resulting wrapper be executed as root so it can call setgid(2) and setuid(2)."
136 (chdir #$directory) 142 (chdir #$directory)
137 (environ variables) 143 (environ variables)
138 144
145 (when listen-pid?
146 ;; Set 'LISTEN_PID' to the PID in this namespace.
147 (setenv "LISTEN_PID" (number->string (getpid))))
148
139 (unless (memq 'user namespaces) 149 (unless (memq 'user namespaces)
140 ;; This process lives in its parent user namespace, 150 ;; This process lives in its parent user namespace,
141 ;; presumably as root; now is the time to setgid/setuid if 151 ;; presumably as root; now is the time to setgid/setuid if