From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Newsgroups: gmane.lisp.guile.bugs Subject: bug#61095: [PATCH 2/3] Remove racy optimized file descriptor closing loop in 'spawn'. Date: Thu, 30 Mar 2023 00:30:56 +0200 Message-ID: <20230329223057.28100-2-ludo@gnu.org> References: <87zg7vjimr.fsf@inria.fr> <20230329223057.28100-1-ludo@gnu.org> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25397"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Josselin Poiret , Omar Polo , Andrew Whatson To: 61095@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Thu Mar 30 00:32:09 2023 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 1pheKv-0006Lt-By for guile-bugs@m.gmane-mx.org; Thu, 30 Mar 2023 00:32:09 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pheKq-0001jt-CW; Wed, 29 Mar 2023 18:32:04 -0400 Original-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 1pheKp-0001jJ-5k for bug-guile@gnu.org; Wed, 29 Mar 2023 18:32:03 -0400 Original-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 1pheKo-00081u-To for bug-guile@gnu.org; Wed, 29 Mar 2023 18:32:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pheKo-0006db-5h; Wed, 29 Mar 2023 18:32:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: dev@jpoiret.xyz, op@omarpolo.com, whatson@tailcall.au, bug-guile@gnu.org Resent-Date: Wed, 29 Mar 2023 22:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61095 X-GNU-PR-Package: guile X-Debbugs-Original-Xcc: Josselin Poiret , Omar Polo , Andrew Whatson Original-Received: via spool by 61095-submit@debbugs.gnu.org id=B61095.168012909325456 (code B ref 61095); Wed, 29 Mar 2023 22:32:02 +0000 Original-Received: (at 61095) by debbugs.gnu.org; 29 Mar 2023 22:31:33 +0000 Original-Received: from localhost ([127.0.0.1]:55152 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pheKL-0006cU-Ap for submit@debbugs.gnu.org; Wed, 29 Mar 2023 18:31:33 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:44736) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pheKH-0006bv-Tr for 61095@debbugs.gnu.org; Wed, 29 Mar 2023 18:31:30 -0400 Original-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 1pheKC-0007yD-N6; Wed, 29 Mar 2023 18:31:24 -0400 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=9A48uyemplKqgvzDip8m1sP7er/I6W9txwwc+lujWFw=; b=FhnX0w0YfjPLOUOMEvx+ 20DjZ4JcVW1JsHuK8Pj+ibBQ8Msd2NXTRDaNPz17eOnXS+iGnUj3ufk70AWflPSetA6jtqdwGPgGC yF1axWFi7CZDKT+dM3X2XahI1mk7guy3DHsBKgJ9RduqzPfv5JKTc4j4ntLGWf/y8wxRYq/WlV5It bNw/gnR246+6Qcba3L8YaUYZJLJvty5o+QtDBmpQ3GYfqpyshElxLnHJ6XKo8Tyy11kGwNMipT7o6 4zRb5TcIYLwE0lNZDLdKAq32xdhT67OhDWNU3umK43VubyuL5ZFS/hTnCO+KXMmuldl+TW5iW8qlp Lh2YFd6BRaCUPg==; Original-Received: from vpn-0-27.aquilenet.fr ([2a0c:e300:4:27::] helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pheK8-00015b-N0; Wed, 29 Mar 2023 18:31:23 -0400 X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329223057.28100-1-ludo@gnu.org> 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-bounces+guile-bugs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.bugs:10586 Archived-At: This reverts 9332b632407894c2e1951cce1bc678f19e1fa8e4, thereby reinstating the performance issue in . This optimization was subject to race conditions in multi-threaded code: new file descriptors could pop up at any time and thus leak in the child. * libguile/posix.c (close_inherited_fds): Remove. (close_inherited_fds_slow): Rename to... (close_inherited_fds): ... this. --- libguile/posix.c | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/libguile/posix.c b/libguile/posix.c index 68e9bfade..b5830c43b 100644 --- a/libguile/posix.c +++ b/libguile/posix.c @@ -1323,7 +1323,7 @@ SCM_DEFINE (scm_fork, "primitive-fork", 0, 0, 0, #endif /* HAVE_FORK */ static void -close_inherited_fds_slow (posix_spawn_file_actions_t *actions, int max_fd) +close_inherited_fds (posix_spawn_file_actions_t *actions, int max_fd) { while (--max_fd > 2) { @@ -1346,34 +1346,6 @@ close_inherited_fds_slow (posix_spawn_file_actions_t *actions, int max_fd) } } -static void -close_inherited_fds (posix_spawn_file_actions_t *actions, int max_fd) -{ - DIR *dirp; - struct dirent *d; - int fd; - - /* Try to use the platform-specific list of open file descriptors, so - we don't need to use the brute force approach. */ - dirp = opendir ("/proc/self/fd"); - - if (dirp == NULL) - return close_inherited_fds_slow (actions, max_fd); - - while ((d = readdir (dirp)) != NULL) - { - fd = atoi (d->d_name); - - /* Skip "." and "..", garbage entries, stdin/stdout/stderr. */ - if (fd <= 2) - continue; - - posix_spawn_file_actions_addclose (actions, fd); - } - - closedir (dirp); -} - static pid_t do_spawn (char *exec_file, char **exec_argv, char **exec_env, int in, int out, int err, int spawnp) -- 2.39.2