Paul Eggert wrote:
> > How about module 'fts'? Should the directory fds that it allocates also be
> > made O_CLOEXEC?
> 
> Yes, I'd say so; I see little reason for a child process to continue an fts 
> scan.

Done through this patch. In fact, you had already done most of the work
on 2017-08-12.

Bruno
>From 708c76165712d6cbad59379b7e039870f81ca63c Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Thu, 28 May 2020 21:48:13 +0200
Subject: [PATCH] fts: Make more robust in multithreaded applications.

* lib/fts.c (fts_open): Pass an O_CLOEXEC flag to open().
* modules/fts (Depends-on): Add 'open'.
---
 ChangeLog   | 6 ++++++
 lib/fts.c   | 2 +-
 modules/fts | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index e637b57..4145796 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2020-05-28  Bruno Haible  <br...@clisp.org>
 
+	fts: Make more robust in multithreaded applications.
+	* lib/fts.c (fts_open): Pass an O_CLOEXEC flag to open().
+	* modules/fts (Depends-on): Add 'open'.
+
+2020-05-28  Bruno Haible  <br...@clisp.org>
+
 	relocatable-prog: Make more robust in multithreaded applications.
 	* lib/progreloc.c (O_CLOEXEC): Define fallback to 0 when use from module
 	relocatable-prog-wrapper.
diff --git a/lib/fts.c b/lib/fts.c
index 3b2f693..5e357be 100644
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -402,7 +402,7 @@ fts_open (char * const *argv,
                early, doing it here saves us the trouble of ensuring
                later (where it'd be messier) that "." can in fact
                be opened.  If not, revert to FTS_NOCHDIR mode.  */
-            int fd = open (".", O_SEARCH);
+            int fd = open (".", O_SEARCH | O_CLOEXEC);
             if (fd < 0)
               {
                 /* Even if "." is unreadable, don't revert to FTS_NOCHDIR mode
diff --git a/modules/fts b/modules/fts
index 480700b..b06d5b8 100644
--- a/modules/fts
+++ b/modules/fts
@@ -22,6 +22,7 @@ hash
 i-ring
 lstat
 memmove
+open
 openat-h
 opendir
 opendirat
-- 
2.7.4

Reply via email to