guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 02/04: Remove racy optimized file descriptor closing loo


From: Ludovic Courtès
Subject: [Guile-commits] 02/04: Remove racy optimized file descriptor closing loop in 'spawn'.
Date: Sun, 2 Apr 2023 09:41:46 -0400 (EDT)

civodul pushed a commit to branch main
in repository guile.

commit 7d7067fe15a6dc82068cbafb11846a2de2896a83
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Tue Mar 28 23:43:31 2023 +0200

    Remove racy optimized file descriptor closing loop in 'spawn'.
    
    This reverts 9332b632407894c2e1951cce1bc678f19e1fa8e4, thereby
    reinstating the performance issue in <https://bugs.gnu.org/59321>.
    
    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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]