From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:5f26::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id QE8yIC9Zf2W41wAAkFu2QA (envelope-from ) for ; Sun, 17 Dec 2023 21:25:19 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id 6PmmHC9Zf2WLSAEAqHPOHw (envelope-from ) for ; Sun, 17 Dec 2023 21:25:19 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b="jkrDL/6u"; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1702844719; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=9JQx6RlxXevWORVf9XOF0AU2TcuyJRIg2eR1Hqz8C28=; b=AWneA9nJpzIBxY24PsLoLguH8dF3QhXoQKEB6wf91gO3EwzU2lra+Hq1pRkJ/RNKp3sTQP rKkBMzcgti5evRGnwWjfafHnw5J4qsmKwKNeT4uKj7AY+tg45db+P47ra4ZnqizpD0rEd8 bb23gj3j3GlRFBipCaQ+moTsS3QgF4vqZL+RBIcxGvzreFX+ULQbT4xMQbc4/+5Wdi8AaU jbeAOVPM4ZISE1PyvMxIu5ERiUyiytM6GMFYw+XZW7ychgkrV2WeRgSD4Lo6Y89T65kAz5 qcWS6+ZS25qgRdo98D+XSeutPGfrtwtTWKHiXNw1ERLplsWpYUmD8wTY5UihdA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1702844719; a=rsa-sha256; cv=none; b=duUeuKlfp1gc+I4Y70NV0QXPogfZ125y6T6VfFwUrVL+6FodfmbR+9+lOT0LSAAimrS1zj ZRqCmMtcJi9Bv3FGY8SH6nQg0LlM4aFUUCOVWJ4TMLSVG69jRwoiLFOwx+1767CgkP7pjx yztJf9jYDXKdslp66ztYFe8HgUnzS8PNTAs+/wUORL6IjMPfux8g64V3JDx7KSUKtFWOc9 IsahYDWh33FGaJ9lLwfq1Cn6hxQbuNA64oBq+3A/I5zCe+3KwEFcVnxTtJPttu7N0x+Cnn qEsu7TDZPj1nP+OyVG2bEutk5hWh38Q9tn1QBsh4Ib60vrmYjp7zHjeifviTMA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b="jkrDL/6u"; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 1754230799 for ; Sun, 17 Dec 2023 21:25:18 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rExh9-0003Ts-4R; Sun, 17 Dec 2023 15:25:03 -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 1rExh6-0003T0-VI for bug-guix@gnu.org; Sun, 17 Dec 2023 15:25:00 -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 1rExh6-0002AA-NC for bug-guix@gnu.org; Sun, 17 Dec 2023 15:25:00 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rExh7-00018B-SQ; Sun, 17 Dec 2023 15:25:01 -0500 X-Loop: help-debbugs@gnu.org Subject: bug#30948: [PATCH core-updates] build-system/gnu: Turn PID 1 into an =?UTF-8?Q?=E2=80=9Cinit=E2=80=9D-style?= process by default. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: maxim.cournoyer@gmail.com, carlo@zancanaro.id.au, bug-guix@gnu.org Resent-Date: Sun, 17 Dec 2023 20:25:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30948 X-GNU-PR-Package: guix X-GNU-PR-Keywords: patch To: 30948@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Carlo Zancanaro , Maxim Cournoyer , Carlo Zancanaro X-Debbugs-Original-Xcc: Maxim Cournoyer , Carlo Zancanaro Received: via spool by 30948-submit@debbugs.gnu.org id=B30948.17028446594275 (code B ref 30948); Sun, 17 Dec 2023 20:25:01 +0000 Received: (at 30948) by debbugs.gnu.org; 17 Dec 2023 20:24:19 +0000 Received: from localhost ([127.0.0.1]:59055 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rExgQ-00016s-Mx for submit@debbugs.gnu.org; Sun, 17 Dec 2023 15:24:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40960) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rExgO-00016Z-HE for 30948@debbugs.gnu.org; Sun, 17 Dec 2023 15:24:17 -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 1rExgF-0001tW-Cf; Sun, 17 Dec 2023 15:24:07 -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=9JQx6RlxXevWORVf9XOF0AU2TcuyJRIg2eR1Hqz8C28=; b=jkrDL/6uu98aJVRtwCT+ neCCKxE/ppXqOOx6bUwr8dl57zMxx2C80BaN66zYhhRPsqgz/5cPmTapOLhrS2I8ORYo2jPxIFT7x IOVFz48gUfqmxCYMZigprardrili9Lmje+aUsLoXub8V7n1BGrF2eaEhHMZEbEdaeT22TteKIJblJ kBzrhC9NOvP/s2DXGKqWXnAbthLsiKSP+fmhHQ2G5tP3GgYeihKGsEP5aVw1NjuGUZmGDFKT7EyzO vHv0EovnT/PmPS9foYLOfAfxssr91tmMHIGfP+5s8Ap3q2sW0EXM+ayTHXaWy2fO16NAfnXzXBN1W KXvI9pSHYUzO3w==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Sun, 17 Dec 2023 21:23:52 +0100 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: <87lenvce8r.fsf@gnu.org> References: <87lenvce8r.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: bug-guix-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -4.42 X-Spam-Score: -4.42 X-Migadu-Queue-Id: 1754230799 X-Migadu-Scanner: mx12.migadu.com X-TUID: UlettntqDv7d 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(-) Hi! This is a second attempt I’m currently testing as part of an initially unrelated ‘core-updates’ series: https://issues.guix.gnu.org/67824 The principle is simple: if the build process runs as PID 1, fork so that PID 1 does nothing but call ‘waitpid’ in a loop while the actual build process runs as PID 2. This is simple and robust. The code is written in a defensive way as an extra phase that can be disabled. Thoughts? Ludo’. 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 base-commit: 2f3b64b9d967b4eea5cbdb32c859f4e3ac3b1a83 -- 2.41.0