From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Josselin Poiret via "Bug reports for GUILE, GNU's Ubiquitous Extension Language" Newsgroups: gmane.lisp.guile.bugs Subject: bug#52835: [PATCH v4 0/4] Improve safety of start_child and piped-process. Date: Sat, 28 May 2022 14:46:30 +0200 Message-ID: <20220528124634.17353-1-dev@jpoiret.xyz> References: <20220207165543.12723-1-dev@jpoiret.xyz> Reply-To: Josselin Poiret Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30459"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 52835@debbugs.gnu.org To: Josselin Poiret , Timothy Sample Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Sat May 28 14:48:08 2022 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nuvrT-0007je-DV for guile-bugs@m.gmane-mx.org; Sat, 28 May 2022 14:48:07 +0200 Original-Received: from localhost ([::1]:47974 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nuvrS-0004L5-AP for guile-bugs@m.gmane-mx.org; Sat, 28 May 2022 08:48:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35542) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nuvrO-0004Kq-0m for bug-guile@gnu.org; Sat, 28 May 2022 08:48:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42724) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nuvrN-0004EA-Of for bug-guile@gnu.org; Sat, 28 May 2022 08:48:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nuvrN-00014W-L6 for bug-guile@gnu.org; Sat, 28 May 2022 08:48:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Josselin Poiret Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sat, 28 May 2022 12:48:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 52835 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch Original-Received: via spool by 52835-submit@debbugs.gnu.org id=B52835.16537420393922 (code B ref 52835); Sat, 28 May 2022 12:48:01 +0000 Original-Received: (at 52835) by debbugs.gnu.org; 28 May 2022 12:47:19 +0000 Original-Received: from localhost ([127.0.0.1]:36619 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nuvqV-00010z-Qc for submit@debbugs.gnu.org; Sat, 28 May 2022 08:47:19 -0400 Original-Received: from jpoiret.xyz ([206.189.101.64]:34330) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nuvqH-0000zJ-AO for 52835@debbugs.gnu.org; Sat, 28 May 2022 08:46:57 -0400 Original-Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id A27381851D2; Sat, 28 May 2022 12:46:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1653742009; 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=9a2TKcgtH3gM8aPOWqJRXSou9Q7z2mi4S3ctlqFY7lY=; b=JDvFtXlEHuBqgUbJkwhzgHhiLxfWe166HHIVAN1+4jkf1hCQM0clUoqx7zPh8L1ODgYXJR THjBHHi+o1yUCJaX6JNFIqcLCs1QMqjrjvPFM46bgGQ1dtqFMaZh28fZuERCKAUaEWRmcE MueeNLfcYeuTVabVwWow4UA7369I1D7A9qQkWtTATT3Er77GSLOJF77xES7fAWlLNUWXVZ /HsezcKKLIZxUzECQZGY8x3kmC/pHCGCTx08CV7pVk63EBwLVHyPlspKUeIP9raaOXKGyE LDaMFlzangrfLoC516Tiy0XIC2Ejr0mIVtkK4TsXzlGu/HIlpw0AycZhMaiwOQ== In-Reply-To: <20220207165543.12723-1-dev@jpoiret.xyz> Authentication-Results: jpoiret.xyz; auth=pass smtp.auth=jpoiret@jpoiret.xyz smtp.mailfrom=dev@jpoiret.xyz X-Spamd-Bar: ++++ X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.io gmane.lisp.guile.bugs:10286 Archived-At: retitle 52835 Improve safety of start_child and piped-process. thanks Hello everyone, This time, it's another Guix bug [1] that prompted me to have a closer look at piped-process and start_child, which don't seem to be very multi-thread safe. I've ended up with a couple of improvements that IMO would make all procedures relying on them more robust. Here's roughly what I did: * Fix the fd closing code that was bogus for unusual values for in, out, err for start_child. * Check for double closes and avoid them, so that we don't accidentally close an fd that another thread could have opened. * Remove some closing code in the child, since we're already generically closing all fds. * Add a pipe from the child to the parent that the former uses to report its errno to the latter. This avoids the use of strerror and printf in the child after forking, since they are not async-signal safe. As a side effect, this lets piped-error raise the proper system exception for the child errno, instead of returning the PID of a process that hasn't exec'd successfully. [1] https://issues.guix.gnu.org/55441 Best, Josselin Poiret (4): Fix child spawning closing standard fds prematurely. Avoid double closes in piped-process. Remove useless closing code in start_child. Make start_child propagate the child errno to the parent. configure.ac | 3 +- libguile/posix.c | 187 ++++++++++++++++++++++++++++++++++------------- 2 files changed, 138 insertions(+), 52 deletions(-) -- 2.36.0