From patchwork Mon Dec 18 16:30:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 57679 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 50C0F27BBEA; Mon, 18 Dec 2023 16:32:27 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 763DD27BBE9 for ; Mon, 18 Dec 2023 16:32:25 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rFGXQ-0001oP-2h; Mon, 18 Dec 2023 11:32:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rFGXD-0001kZ-6l for guix-patches@gnu.org; Mon, 18 Dec 2023 11:32:04 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rFGXC-0007f5-Qv for guix-patches@gnu.org; Mon, 18 Dec 2023 11:32:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rFGXE-00075f-Oq for guix-patches@gnu.org; Mon, 18 Dec 2023 11:32:04 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#67824] [PATCH core-updates v2 8/9] build-system/gnu: Turn PID 1 into an =?utf-8?b?4oCcaW5pdOKAnS1zdHlsZQ==?= process by default. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 18 Dec 2023 16:32:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67824 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 67824@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , Carlo Zancanaro Received: via spool by 67824-submit@debbugs.gnu.org id=B67824.170291706926207 (code B ref 67824); Mon, 18 Dec 2023 16:32:04 +0000 Received: (at 67824) by debbugs.gnu.org; 18 Dec 2023 16:31:09 +0000 Received: from localhost ([127.0.0.1]:33390 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rFGWL-0006nw-0R for submit@debbugs.gnu.org; Mon, 18 Dec 2023 11:31:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52784) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rFGWC-0006YG-Gt for 67824@debbugs.gnu.org; Mon, 18 Dec 2023 11:31:01 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rFGW3-0007V0-S1; Mon, 18 Dec 2023 11:30:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=us/RZNPz9QE+U7JBcmSVn0PlJR0j2F9GiJmk2W8LmWg=; b=i9OOXkMDu2IrIv0DsUrW ENHyfwEL75pS53trqp/KKt5pGWm7xjbgewxfivc19XDiH23bk2/XjqlVEBOwiW3c7AygwABoOjCOQ Vv8faB56DXLNQ4RrJ5n5IIy0I8fk9Cnr+Jq8+bpDq/eAXW7lxMXdFA9RO2xVftArNDCrDyAAAcXAi VTUSCebv3FNgYbVv3EMKgPhtIgmuXe6KAlYj7NiABBl32a7oOT+wcEhrof1RbbgC9fFwo2CMGthMG Cj9YPXtFC0YxUpva1ZVU3g1J/t+S+2QObtVZZv2mY+c9j6t2k+Go8OlEa0UuElKG3UEY9DkpsdPYB B1J3TDY+YEn0Dg==; From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Mon, 18 Dec 2023 17:30:19 +0100 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches Fixes . * 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 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 @@ (define* (gnu-build name inputs (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 @@ (define* (gnu-build name inputs (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 @@ (define* (gnu-cross-build name (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 @@ (define* (gnu-cross-build name (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 @@ (define (first-subdirectory directory) ((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 @@ (define %standard-phases ;; 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