From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id 4K7kDmsHVWTjfAEASxT56A (envelope-from ) for ; Fri, 05 May 2023 15:40:59 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id WOswDmsHVWTs6gAAG6o9tA (envelope-from ) for ; Fri, 05 May 2023 15:40:59 +0200 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 0E8533EB11 for ; Fri, 5 May 2023 15:40:59 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1puvfL-0007Gf-MQ; Fri, 05 May 2023 09:40:07 -0400 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 1puvfH-0007F3-5e for bug-guix@gnu.org; Fri, 05 May 2023 09:40:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1puvfG-00055v-TG for bug-guix@gnu.org; Fri, 05 May 2023 09:40:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1puvfG-0005pg-Ol for bug-guix@gnu.org; Fri, 05 May 2023 09:40:02 -0400 X-Loop: help-debbugs@gnu.org Subject: bug#62334: [PATCH 1/3] Add error handling for spawn's posix_spawn_file_actions_adddup2 Resent-From: Josselin Poiret Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Fri, 05 May 2023 13:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62334 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Josselin Poiret Cc: 63024@debbugs.gnu.org, 62334@debbugs.gnu.org, Greg Hogan , Simon Tournier Received: via spool by 62334-submit@debbugs.gnu.org id=B62334.168329397522345 (code B ref 62334); Fri, 05 May 2023 13:40:02 +0000 Received: (at 62334) by debbugs.gnu.org; 5 May 2023 13:39:35 +0000 Received: from localhost ([127.0.0.1]:53446 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1puveo-0005oF-Jx for submit@debbugs.gnu.org; Fri, 05 May 2023 09:39:34 -0400 Received: from jpoiret.xyz ([206.189.101.64]:53524) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1puveg-0005n0-OD; Fri, 05 May 2023 09:39:31 -0400 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id BC7721851DD; Fri, 5 May 2023 13:39:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1683293965; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m7U8nFMR82QpcxjD/8xowHP0U5YYMieJYXnhRA4KGu0=; b=GzOorNFotxJPi3dRKkZFlHZe3/B8vZojK0YLD6NoGs7BLU5t5LJEQGQj8MzqkkQglUuM73 JryD9YMWiR1zwKMkgvmAqT6PnmG0KNj372OMxher2mdmqnNpVqDfpBsXU6vcp2oJnKZsyV UU1bjJ1uI4iNrZ9QMhrzd2+X8BaVQFqNKqfHwJt2cqcOnoDFz+JZ1b79jSTcndcUDNPzML bQs5tibOJKgABiRODAyasrhG6izv3xni8MKbqa3UFiKpgFPeVf+jBFY67yh6bZ0Bz5omZ5 ZM20WWWmhaAsthy9nSpCE7oSGJXSRbav5i/pnbhB1d+CIALC2hj5QR8wWUdABQ== Date: Fri, 5 May 2023 15:39:22 +0200 Message-Id: In-Reply-To: <87mt2l4whd.fsf@gnu.org> References: <87mt2l4whd.fsf@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Bar: ++++++ 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: , Reply-to: Josselin Poiret From: Josselin Poiret via Bug reports for GNU Guix 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 ARC-Seal: i=1; s=key1; d=yhetil.org; t=1683294059; a=rsa-sha256; cv=none; b=jeni5g2wRVrRhSgD1AdidstnA2o2BrtJGP+26RnzU6a1JOHAshScqpw437bAU2JEfy5KR+ B9vaZpjn9TY3pJBrRRyZR4XPkCcMyNBnASuGH/EsbhrhY4WRCf8tYSQCAH3OoH90bWqJEO iK79qHbgQf1I4kLS4azYQjaj6PsvRFRWu7MpJjKcRfiykFXhV4j/5Mwkrc1ysSPPulHnL+ WPMwIGaSQepJKJGdHB4jZbwaDLv1ALawES4yz3SkPFkBgTLOb8cvgjiyDudvp3m5FJlU47 /8gHdHG8LX8YMrfqgWVFUyAdBYc9eK1v3ksMIArY2NW8N1YCR745MSkQ1wyJMg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=jpoiret.xyz header.s=dkim header.b=GzOorNFo; dmarc=pass (policy=none) header.from=gnu.org; 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1683294059; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: 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=m7U8nFMR82QpcxjD/8xowHP0U5YYMieJYXnhRA4KGu0=; b=Mf+Hs2trN8hy7BFnxT86cjTI9gg8u3Bb73Q1Ta/N54GltJ0fMSBJ40fNm/YydKlVjCVjoS pa03ZRlohHu0fGgUEOVu4czotpFkwpcm1qNfsDqicu0AQzPGBI/RT1ZtcN6JTlE9goLiOj h0Ddo/GDNQVf9MqpXpJxoetlLinkuYQUum8cae9o0buCqDcnXp7JValjgI98yPbwgYHsyB bhb016SjEJ19hGS0yMpSt+RK4NDlbGZGJ1lJuzVe/w+nyi8aqeenWhXdiO/9CyzdxWCagP 6dBvfh5CamoOY/6RwLZEZbsREw8ld4pB2tOk+BaFfKrYnHnNTn0Y4U4LsemWYw== X-Migadu-Scanner: scn1.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=jpoiret.xyz header.s=dkim header.b=GzOorNFo; dmarc=pass (policy=none) header.from=gnu.org; 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" X-Migadu-Spam-Score: 4.80 X-Spam-Score: 4.80 X-Migadu-Queue-Id: 0E8533EB11 X-TUID: RJeLUkDOW06V From: Josselin Poiret * libguile/posix.c (do_spawn): Add error handling if posix_spawn_file_actions_adddup2 fails. --- Hi Ludo, Sorry for not noticing this thread sooner! Here's my take on it, a minor variation but that's what I'd prefer tbh. LMKWYT, Josselin libguile/posix.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libguile/posix.c b/libguile/posix.c index 3adc743c4..2969f1f24 100644 --- a/libguile/posix.c +++ b/libguile/posix.c @@ -1390,12 +1390,15 @@ do_spawn (char *exec_file, char **exec_argv, char **exec_env, /* Move the fds out of the way, so that duplicate fds or fds equal to 0, 1, 2 don't trample each other */ - posix_spawn_file_actions_adddup2 (&actions, in, fd_slot[0]); - posix_spawn_file_actions_adddup2 (&actions, out, fd_slot[1]); - posix_spawn_file_actions_adddup2 (&actions, err, fd_slot[2]); - posix_spawn_file_actions_adddup2 (&actions, fd_slot[0], 0); - posix_spawn_file_actions_adddup2 (&actions, fd_slot[1], 1); - posix_spawn_file_actions_adddup2 (&actions, fd_slot[2], 2); + int dup2_action_from[] = {in, out, err, + fd_slot[0], fd_slot[1], fd_slot[2]}; + int dup2_action_to [] = {fd_slot[0], fd_slot[1], fd_slot[2], + 0, 1, 2}; + + errno = 0; + for (int i = 0;i < sizeof (dup2_action_from) / sizeof (int);i++) + if ((errno = posix_spawn_file_actions_adddup2 (&actions, dup2_action_from[i], dup2_action_to[i]))) + return -1; #ifdef HAVE_ADDCLOSEFROM /* This function appears in glibc 2.34. It's both free from race base-commit: fe6cc6d04ab094ea802907bdc4f728416c0e97ba -- 2.39.2