[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
08/09: build-system/gnu: Turn PID 1 into an “init”-style process by defa
From: |
guix-commits |
Subject: |
08/09: build-system/gnu: Turn PID 1 into an “init”-style process by default. |
Date: |
Tue, 19 Dec 2023 17:53:19 -0500 (EST) |
civodul pushed a commit to branch core-updates
in repository guix.
commit 7ebe4b72727632561ddbf8bb0c58527929682989
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Sun Dec 17 15:14:33 2023 +0100
build-system/gnu: Turn PID 1 into an “init”-style process by default.
Fixes <https://issues.guix.gnu.org/30948>.
* guix/build/gnu-build-system.scm (separate-from-pid1): New procedure.
(%standard-phases): Add it.
* guix/build-system/gnu.scm (gnu-build): Add #:separate-from-pid1? and
honor it.
(gnu-cross-build): Likewise.
Reported-by: Carlo Zancanaro <carlo@zancanaro.id.au>
Change-Id: I6f3bc8d8186d1a571f983a38d5e3fd178ffa2678
---
guix/build-system/gnu.scm | 4 ++++
guix/build/gnu-build-system.scm | 39 ++++++++++++++++++++++++++++++++++++++-
2 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/guix/build-system/gnu.scm b/guix/build-system/gnu.scm
index 0f886fe21d..6a89bcc0d8 100644
--- a/guix/build-system/gnu.scm
+++ b/guix/build-system/gnu.scm
@@ -362,6 +362,7 @@ standard packages used as implicit inputs of the GNU build
system."
(license-file-regexp %license-file-regexp)
(phases '%standard-phases)
(locale "C.UTF-8")
+ (separate-from-pid1? #t)
(system (%current-system))
(build (nix-system->gnu-triplet system))
(imported-modules %default-gnu-imported-modules)
@@ -404,6 +405,7 @@ are allowed to refer to."
(sexp->gexp phases)
phases)
#:locale #$locale
+ #:separate-from-pid1? #$separate-from-pid1?
#:bootstrap-scripts #$bootstrap-scripts
#:configure-flags #$(if (pair? configure-flags)
(sexp->gexp configure-flags)
@@ -502,6 +504,7 @@ is one of `host' or `target'."
(license-file-regexp %license-file-regexp)
(phases '%standard-phases)
(locale "C.UTF-8")
+ (separate-from-pid1? #t)
(system (%current-system))
(build (nix-system->gnu-triplet system))
(imported-modules %default-gnu-imported-modules)
@@ -547,6 +550,7 @@ platform."
(sexp->gexp phases)
phases)
#:locale #$locale
+ #:separate-from-pid1? #$separate-from-pid1?
#:bootstrap-scripts #$bootstrap-scripts
#:configure-flags #$configure-flags
#:make-flags #$make-flags
diff --git a/guix/build/gnu-build-system.scm b/guix/build/gnu-build-system.scm
index 39707e7ace..51b8f9acbf 100644
--- a/guix/build/gnu-build-system.scm
+++ b/guix/build/gnu-build-system.scm
@@ -72,6 +72,42 @@ there are none."
((first . _) first)
(_ #f)))
+(define* (separate-from-pid1 #:key (separate-from-pid1? #t)
+ #:allow-other-keys)
+ "When running as PID 1 and SEPARATE-FROM-PID1? is true, run build phases as
+a child process; PID 1 then becomes responsible for reaping child processes."
+ (if separate-from-pid1?
+ (if (= 1 (getpid))
+ (dynamic-wind
+ (const #t)
+ (lambda ()
+ (match (primitive-fork)
+ (0 #t)
+ (builder-pid
+ (format (current-error-port)
+ "build process now running as PID ~a~%"
+ builder-pid)
+ (let loop ()
+ ;; Running as PID 1 so take responsibility for reaping
+ ;; child processes.
+ (match (waitpid WAIT_ANY)
+ ((pid . status)
+ (if (= pid builder-pid)
+ (if (zero? status)
+ (primitive-exit 0)
+ (begin
+ (format (current-error-port)
+ "build process ~a exited with status
~a~%"
+ pid status)
+ (primitive-exit 1)))
+ (loop))))))))
+ (const #t))
+ (format (current-error-port) "not running as PID 1 (PID: ~a)~%"
+ (getpid)))
+ (format (current-error-port)
+ "build process running as PID ~a; not forking~%"
+ (getpid))))
+
(define* (set-paths #:key target inputs native-inputs
(search-paths '()) (native-search-paths '())
#:allow-other-keys)
@@ -872,7 +908,8 @@ that traversing all the RUNPATH entries entails."
;; Standard build phases, as a list of symbol/procedure pairs.
(let-syntax ((phases (syntax-rules ()
((_ p ...) `((p . ,p) ...)))))
- (phases set-SOURCE-DATE-EPOCH set-paths install-locale unpack
+ (phases separate-from-pid1
+ set-SOURCE-DATE-EPOCH set-paths install-locale unpack
bootstrap
patch-usr-bin-file
patch-source-shebangs configure patch-generated-file-shebangs
- branch core-updates updated (8161a086ea -> 62e67aa799), guix-commits, 2023/12/19
- 02/09: build-system/gnu: Change default locale to C.UTF-8., guix-commits, 2023/12/19
- 04/09: profiles: Use C.UTF-8 instead of ‘glibc-utf8-locales’ where possible., guix-commits, 2023/12/19
- 05/09: packages: Output and error ports are line-buffered in ‘patch-and-repack’., guix-commits, 2023/12/19
- 01/09: packages: Remove reference to ‘glibc-utf8-locales’ in ‘patch-and-repack’., guix-commits, 2023/12/19
- 03/09: gnu: commencement: Remove ‘glibc-utf8-locales’ from ‘%final-inputs’., guix-commits, 2023/12/19
- 06/09: gnu: glibc-utf8-locales: Add the C.UTF-8 locale., guix-commits, 2023/12/19
- 07/09: gnu: glibc: Add patch for ‘ucontext’ on x86_64-gnu (GNU/Hurd)., guix-commits, 2023/12/19
- 08/09: build-system/gnu: Turn PID 1 into an “init”-style process by default.,
guix-commits <=
- 09/09: gnu: glib: Skip test that fails with glibc 2.38., guix-commits, 2023/12/19