From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org
Subject: use O_CLOEXEC in more places
Date: Wed, 27 May 2020 20:43:45 +0200 [thread overview]
Message-ID: <2127200.Gmmp1eMdPG@omega> (raw)
[-- Attachment #1: Type: text/plain, Size: 4226 bytes --]
The gnulib module 'open' supports O_CLOEXEC since 2017-08-14. We can use it
to make multithreaded application that call fork() and exec() more robust.
Here are proposed patches.
How about module 'fts'? Should the directory fds that it allocates also be
made O_CLOEXEC?
2020-05-27 Bruno Haible <bruno@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.
(find_executable): Pass an O_CLOEXEC flag to open().
* modules/relocatable-prog (Depends-on): Add 'open'.
2020-05-27 Bruno Haible <bruno@clisp.org>
getloadavg: Make more robust in multithreaded applications.
* lib/getloadavg.c (getloadavg): Pass an O_CLOEXEC flag to open().
Simplify use of O_CLOEXEC.
* modules/getloadavg (Depends-on): Add 'open'.
2020-05-27 Bruno Haible <bruno@clisp.org>
vma-iter: Make more robust in multithreaded applications.
* lib/vma-iter.c (rof_open, vma_iterate): Pass an O_CLOEXEC flag to
open().
* modules/vma-iter (Depends-on): Add 'open'.
2020-05-27 Bruno Haible <bruno@clisp.org>
truncate: Make more robust in multithreaded applications.
* lib/truncate.c (truncate): Pass an O_CLOEXEC flag to open().
2020-05-27 Bruno Haible <bruno@clisp.org>
pagealign_alloc: Make more robust in multithreaded applications.
* lib/pagealign_alloc.c (pagealign_alloc): Pass an O_CLOEXEC flag to
open().
* modules/pagealign_alloc (Depends-on): Add 'open'.
2020-05-27 Bruno Haible <bruno@clisp.org>
openat: Make more robust in multithreaded applications.
* lib/openat.c (openat_needs_fchdir): Pass an O_CLOEXEC flag to open().
2020-05-27 Bruno Haible <bruno@clisp.org>
at-internal: Make more robust in multithreaded applications.
* lib/openat-proc.c (openat_proc_name): Pass an O_CLOEXEC flag to
open().
2020-05-27 Bruno Haible <bruno@clisp.org>
mountlist: Make more robust in multithreaded applications.
* lib/mountlist.c (read_file_system_list): Pass an O_CLOEXEC flag to
open().
* modules/mountlist (Depends-on): Add 'open'.
2020-05-27 Bruno Haible <bruno@clisp.org>
login_tty: Make more robust in multithreaded applications.
* lib/login_tty.c (login_tty): Pass an O_CLOEXEC flag to open().
* modules/login_tty (Depends-on): Add 'open'.
2020-05-27 Bruno Haible <bruno@clisp.org>
javacomp: Make more robust in multithreaded applications.
* lib/javacomp.c (get_classfile_version): Pass an O_CLOEXEC flag to
open().
* modules/javacomp (Depends-on): Add 'open'.
2020-05-27 Bruno Haible <bruno@clisp.org>
getprogname: Make more robust in multithreaded applications.
* lib/getprogname.c (getprogname): Pass an O_CLOEXEC flag to open().
* modules/getprogname (Depends-on): Add 'open'.
2020-05-27 Bruno Haible <bruno@clisp.org>
get_progname_of: Make more robust in multithreaded applications.
* lib/get_progname_of.c (get_progname_of): Pass an O_CLOEXEC flag to
open().
* modules/get_progname_of (Depends-on): Add 'open'.
2020-05-27 Bruno Haible <bruno@clisp.org>
get_ppid_of: Make more robust in multithreaded applications.
* lib/get_ppid_of.c (get_ppid_of): Pass an O_CLOEXEC flag to open().
* modules/get_ppid_of (Depends-on): Add 'open'.
2020-05-27 Bruno Haible <bruno@clisp.org>
get-rusage-as: Make more robust in multithreaded applications.
* lib/get-rusage-as.c (get_rusage_as_via_setrlimit): Pass an O_CLOEXEC
flag to open().
* modules/get-rusage-as (Depends-on): Add 'open'.
2020-05-27 Bruno Haible <bruno@clisp.org>
crypto/gc: Make more robust in multithreaded applications.
* lib/gc-gnulib.c (randomize): Pass an O_CLOEXEC flag to open().
* modules/crypto/gc (Depends-on): Add 'open'.
2020-05-27 Bruno Haible <bruno@clisp.org>
copy-file: Make more robust in multithreaded applications.
* lib/copy-file.c (qcopy_file_preserving): Pass an O_CLOEXEC flag to
open().
2020-05-27 Bruno Haible <bruno@clisp.org>
chown: Make more robust in multithreaded applications.
* lib/chown.c (rpl_chown): Pass an O_CLOEXEC flag to open().
2020-05-27 Bruno Haible <bruno@clisp.org>
doc: Fix statement about O_CLOEXEC (wrong since 2017-08-14).
* doc/posix-headers/fcntl.texi: Gnulib no longer defines O_CLOEXEC to 0.
[-- Attachment #2: 0001-doc-Fix-statement-about-O_CLOEXEC-wrong-since-2017-0.patch --]
[-- Type: text/x-patch, Size: 1603 bytes --]
From 83fe45c21f41b1d454271e4e93bd6208130c74db Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 27 May 2020 20:33:28 +0200
Subject: [PATCH 01/18] doc: Fix statement about O_CLOEXEC (wrong since
2017-08-14).
* doc/posix-headers/fcntl.texi: Gnulib no longer defines O_CLOEXEC to 0.
---
ChangeLog | 5 +++++
| 5 ++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index aa08439..d26c96a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2020-05-27 Bruno Haible <bruno@clisp.org>
+ doc: Fix statement about O_CLOEXEC (wrong since 2017-08-14).
+ * doc/posix-headers/fcntl.texi: Gnulib no longer defines O_CLOEXEC to 0.
+
+2020-05-27 Bruno Haible <bruno@clisp.org>
+
javacomp: Make more robust in multithreaded applications.
* lib/javacomp.c (write_temp_file): Pass an 'e' flag to fopen_temp.
* modules/javacomp (Depends-on): Add fopen-gnu.
--git a/doc/posix-headers/fcntl.texi b/doc/posix-headers/fcntl.texi
index 6313cb2..8d7a50a 100644
--- a/doc/posix-headers/fcntl.texi
+++ b/doc/posix-headers/fcntl.texi
@@ -16,7 +16,10 @@ The type @code{mode_t} is not defined on some platforms:
MSVC 14.
@item
-@samp{O_CLOEXEC}, @samp{O_DIRECTORY}, @samp{O_DSYNC}, @samp{O_NOCTTY},
+@samp{O_CLOEXEC} is not defined on some platforms.
+
+@item
+@samp{O_DIRECTORY}, @samp{O_DSYNC}, @samp{O_NOCTTY},
@samp{O_NOFOLLOW}, @samp{O_RSYNC}, @samp{O_SYNC},
and @samp{O_TTY_INIT} are not defined on some platforms. Gnulib defines
these macros to 0, which is generally safe.
--
2.7.4
[-- Attachment #3: 0002-chown-Make-more-robust-in-multithreaded-applications.patch --]
[-- Type: text/x-patch, Size: 1430 bytes --]
From 244e67314cfbc3d0e20b893c66cec9e48e2ddb67 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 27 May 2020 19:35:28 +0200
Subject: [PATCH 02/18] chown: Make more robust in multithreaded applications.
* lib/chown.c (rpl_chown): Pass an O_CLOEXEC flag to open().
---
ChangeLog | 5 +++++
lib/chown.c | 2 +-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index d26c96a..cc937d2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2020-05-27 Bruno Haible <bruno@clisp.org>
+ chown: Make more robust in multithreaded applications.
+ * lib/chown.c (rpl_chown): Pass an O_CLOEXEC flag to open().
+
+2020-05-27 Bruno Haible <bruno@clisp.org>
+
doc: Fix statement about O_CLOEXEC (wrong since 2017-08-14).
* doc/posix-headers/fcntl.texi: Gnulib no longer defines O_CLOEXEC to 0.
diff --git a/lib/chown.c b/lib/chown.c
index 46e753e..6a8a76c 100644
--- a/lib/chown.c
+++ b/lib/chown.c
@@ -87,7 +87,7 @@ rpl_chown (const char *file, uid_t uid, gid_t gid)
on the symlink itself. To work around that, we open the
file (but this can fail due to lack of read or write permission) and
use fchown on the resulting descriptor. */
- int open_flags = O_NONBLOCK | O_NOCTTY;
+ int open_flags = O_NONBLOCK | O_NOCTTY | O_CLOEXEC;
int fd = open (file, O_RDONLY | open_flags);
if (0 <= fd
|| (errno == EACCES
--
2.7.4
[-- Attachment #4: 0003-copy-file-Make-more-robust-in-multithreaded-applicat.patch --]
[-- Type: text/x-patch, Size: 1854 bytes --]
From d4a01ed426a9f3ce87807406e1714667cf1e6377 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 27 May 2020 19:36:54 +0200
Subject: [PATCH 03/18] copy-file: Make more robust in multithreaded
applications.
* lib/copy-file.c (qcopy_file_preserving): Pass an O_CLOEXEC flag to
open().
---
ChangeLog | 6 ++++++
lib/copy-file.c | 6 ++++--
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index cc937d2..1c279d7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2020-05-27 Bruno Haible <bruno@clisp.org>
+ copy-file: Make more robust in multithreaded applications.
+ * lib/copy-file.c (qcopy_file_preserving): Pass an O_CLOEXEC flag to
+ open().
+
+2020-05-27 Bruno Haible <bruno@clisp.org>
+
chown: Make more robust in multithreaded applications.
* lib/chown.c (rpl_chown): Pass an O_CLOEXEC flag to open().
diff --git a/lib/copy-file.c b/lib/copy-file.c
index c574b75..8ae64b2 100644
--- a/lib/copy-file.c
+++ b/lib/copy-file.c
@@ -52,7 +52,7 @@ qcopy_file_preserving (const char *src_filename, const char *dest_filename)
int mode;
int dest_fd;
- src_fd = open (src_filename, O_RDONLY | O_BINARY);
+ src_fd = open (src_filename, O_RDONLY | O_BINARY | O_CLOEXEC);
if (src_fd < 0)
return GL_COPY_ERR_OPEN_READ;
if (fstat (src_fd, &statbuf) < 0)
@@ -65,7 +65,9 @@ qcopy_file_preserving (const char *src_filename, const char *dest_filename)
off_t inbytes = S_ISREG (statbuf.st_mode) ? statbuf.st_size : -1;
bool empty_regular_file = inbytes == 0;
- dest_fd = open (dest_filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0600);
+ dest_fd = open (dest_filename,
+ O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_CLOEXEC,
+ 0600);
if (dest_fd < 0)
{
err = GL_COPY_ERR_OPEN_BACKUP_WRITE;
--
2.7.4
[-- Attachment #5: 0004-crypto-gc-Make-more-robust-in-multithreaded-applicat.patch --]
[-- Type: text/x-patch, Size: 1613 bytes --]
From 459f13b0bab1257e631164ed0bee804f84fcb35d Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 27 May 2020 19:38:36 +0200
Subject: [PATCH 04/18] crypto/gc: Make more robust in multithreaded
applications.
* lib/gc-gnulib.c (randomize): Pass an O_CLOEXEC flag to open().
* modules/crypto/gc (Depends-on): Add 'open'.
---
ChangeLog | 6 ++++++
lib/gc-gnulib.c | 2 +-
modules/crypto/gc | 1 +
3 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 1c279d7..0945095 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2020-05-27 Bruno Haible <bruno@clisp.org>
+ crypto/gc: Make more robust in multithreaded applications.
+ * lib/gc-gnulib.c (randomize): Pass an O_CLOEXEC flag to open().
+ * modules/crypto/gc (Depends-on): Add 'open'.
+
+2020-05-27 Bruno Haible <bruno@clisp.org>
+
copy-file: Make more robust in multithreaded applications.
* lib/copy-file.c (qcopy_file_preserving): Pass an O_CLOEXEC flag to
open().
diff --git a/lib/gc-gnulib.c b/lib/gc-gnulib.c
index bb62ab1..8e9b88f 100644
--- a/lib/gc-gnulib.c
+++ b/lib/gc-gnulib.c
@@ -167,7 +167,7 @@ randomize (int level, char *data, size_t datalen)
if (strcmp (device, "no") == 0)
return GC_RANDOM_ERROR;
- fd = open (device, O_RDONLY);
+ fd = open (device, O_RDONLY | O_CLOEXEC);
if (fd < 0)
return GC_RANDOM_ERROR;
diff --git a/modules/crypto/gc b/modules/crypto/gc
index f9f9253..46ccde1 100644
--- a/modules/crypto/gc
+++ b/modules/crypto/gc
@@ -10,6 +10,7 @@ m4/libgcrypt.m4
Depends-on:
havelib
+open
configure.ac:
gl_GC
--
2.7.4
[-- Attachment #6: 0005-get-rusage-as-Make-more-robust-in-multithreaded-appl.patch --]
[-- Type: text/x-patch, Size: 1800 bytes --]
From 5ac55edadd1c131f876459c8ccdd899f3c042902 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 27 May 2020 19:40:08 +0200
Subject: [PATCH 05/18] get-rusage-as: Make more robust in multithreaded
applications.
* lib/get-rusage-as.c (get_rusage_as_via_setrlimit): Pass an O_CLOEXEC
flag to open().
* modules/get-rusage-as (Depends-on): Add 'open'.
---
ChangeLog | 7 +++++++
lib/get-rusage-as.c | 2 +-
modules/get-rusage-as | 1 +
3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 0945095..4139e7c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2020-05-27 Bruno Haible <bruno@clisp.org>
+ get-rusage-as: Make more robust in multithreaded applications.
+ * lib/get-rusage-as.c (get_rusage_as_via_setrlimit): Pass an O_CLOEXEC
+ flag to open().
+ * modules/get-rusage-as (Depends-on): Add 'open'.
+
+2020-05-27 Bruno Haible <bruno@clisp.org>
+
crypto/gc: Make more robust in multithreaded applications.
* lib/gc-gnulib.c (randomize): Pass an O_CLOEXEC flag to open().
* modules/crypto/gc (Depends-on): Add 'open'.
diff --git a/lib/get-rusage-as.c b/lib/get-rusage-as.c
index 120fae0..da6b47d 100644
--- a/lib/get-rusage-as.c
+++ b/lib/get-rusage-as.c
@@ -176,7 +176,7 @@ get_rusage_as_via_setrlimit (void)
const int fd = -1;
# else /* !HAVE_MAP_ANONYMOUS */
const int flags = MAP_FILE | MAP_PRIVATE;
- int fd = open ("/dev/zero", O_RDONLY, 0666);
+ int fd = open ("/dev/zero", O_RDONLY | O_CLOEXEC, 0666);
if (fd < 0)
return 0;
# endif
diff --git a/modules/get-rusage-as b/modules/get-rusage-as
index 0d30aff..0dadd5c 100644
--- a/modules/get-rusage-as
+++ b/modules/get-rusage-as
@@ -11,6 +11,7 @@ stdint
unistd
extensions
getpagesize
+open
vma-iter
configure.ac:
--
2.7.4
[-- Attachment #7: 0006-get_ppid_of-Make-more-robust-in-multithreaded-applic.patch --]
[-- Type: text/x-patch, Size: 2692 bytes --]
From 543f2a7c00ca8bc3a050ffb3ab936ba6fb1d67c2 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 27 May 2020 19:41:38 +0200
Subject: [PATCH 06/18] get_ppid_of: Make more robust in multithreaded
applications.
* lib/get_ppid_of.c (get_ppid_of): Pass an O_CLOEXEC flag to open().
* modules/get_ppid_of (Depends-on): Add 'open'.
---
ChangeLog | 6 ++++++
lib/get_ppid_of.c | 10 +++++-----
modules/get_ppid_of | 1 +
3 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 4139e7c..fec6b52 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2020-05-27 Bruno Haible <bruno@clisp.org>
+ get_ppid_of: Make more robust in multithreaded applications.
+ * lib/get_ppid_of.c (get_ppid_of): Pass an O_CLOEXEC flag to open().
+ * modules/get_ppid_of (Depends-on): Add 'open'.
+
+2020-05-27 Bruno Haible <bruno@clisp.org>
+
get-rusage-as: Make more robust in multithreaded applications.
* lib/get-rusage-as.c (get_rusage_as_via_setrlimit): Pass an O_CLOEXEC
flag to open().
diff --git a/lib/get_ppid_of.c b/lib/get_ppid_of.c
index 1560e7d..5579cd9 100644
--- a/lib/get_ppid_of.c
+++ b/lib/get_ppid_of.c
@@ -74,7 +74,7 @@ get_ppid_of (pid_t pid)
int fd;
sprintf (filename, "/proc/%u/status", (unsigned int) pid);
- fd = open (filename, O_RDONLY);
+ fd = open (filename, O_RDONLY | O_CLOEXEC);
if (fd >= 0)
{
char buf[4096 + 1];
@@ -115,7 +115,7 @@ get_ppid_of (pid_t pid)
int fd;
sprintf (filename, "/proc/%u/status", (unsigned int) pid);
- fd = open (filename, O_RDONLY);
+ fd = open (filename, O_RDONLY | O_CLOEXEC);
if (fd >= 0)
{
char buf[4096 + 1];
@@ -152,7 +152,7 @@ get_ppid_of (pid_t pid)
int fd;
sprintf (filename, "/proc/%u/psinfo", (unsigned int) pid);
- fd = open (filename, O_RDONLY);
+ fd = open (filename, O_RDONLY | O_CLOEXEC);
if (fd >= 0)
{
char buf[4096 + 1];
@@ -190,7 +190,7 @@ get_ppid_of (pid_t pid)
int fd;
sprintf (filename, "/proc/%u/psinfo", (unsigned int) pid);
- fd = open (filename, O_RDONLY);
+ fd = open (filename, O_RDONLY | O_CLOEXEC);
if (fd >= 0)
{
/* The contents is a 'struct psinfo'. But since 'struct psinfo'
@@ -283,7 +283,7 @@ get_ppid_of (pid_t pid)
int fd;
sprintf (filename, "/proc/pinfo/%u", pid);
- fd = open (filename, O_RDONLY);
+ fd = open (filename, O_RDONLY | O_CLOEXEC);
if (0 <= fd)
{
prpsinfo_t buf;
diff --git a/modules/get_ppid_of b/modules/get_ppid_of
index 4f2cad1..84e3d79 100644
--- a/modules/get_ppid_of
+++ b/modules/get_ppid_of
@@ -9,6 +9,7 @@ Depends-on:
extensions
sys_types
unistd
+open
configure.ac:
--
2.7.4
[-- Attachment #8: 0007-get_progname_of-Make-more-robust-in-multithreaded-ap.patch --]
[-- Type: text/x-patch, Size: 2602 bytes --]
From 00332bf89e656f96510b6282dcc1b96a4154f3bb Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 27 May 2020 19:43:23 +0200
Subject: [PATCH 07/18] get_progname_of: Make more robust in multithreaded
applications.
* lib/get_progname_of.c (get_progname_of): Pass an O_CLOEXEC flag to
open().
* modules/get_progname_of (Depends-on): Add 'open'.
---
ChangeLog | 7 +++++++
lib/get_progname_of.c | 8 ++++----
modules/get_progname_of | 1 +
3 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index fec6b52..259fa85 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2020-05-27 Bruno Haible <bruno@clisp.org>
+ get_progname_of: Make more robust in multithreaded applications.
+ * lib/get_progname_of.c (get_progname_of): Pass an O_CLOEXEC flag to
+ open().
+ * modules/get_progname_of (Depends-on): Add 'open'.
+
+2020-05-27 Bruno Haible <bruno@clisp.org>
+
get_ppid_of: Make more robust in multithreaded applications.
* lib/get_ppid_of.c (get_ppid_of): Pass an O_CLOEXEC flag to open().
* modules/get_ppid_of (Depends-on): Add 'open'.
diff --git a/lib/get_progname_of.c b/lib/get_progname_of.c
index 59f1e0e..4b08489 100644
--- a/lib/get_progname_of.c
+++ b/lib/get_progname_of.c
@@ -105,7 +105,7 @@ get_progname_of (pid_t pid)
int fd;
sprintf (filename, "/proc/%u/cmdline", (unsigned int) pid);
- fd = open (filename, O_RDONLY);
+ fd = open (filename, O_RDONLY | O_CLOEXEC);
if (fd >= 0)
{
char buf[4096 + 1];
@@ -158,7 +158,7 @@ get_progname_of (pid_t pid)
int fd;
sprintf (filename, "/proc/%u/psinfo", (unsigned int) pid);
- fd = open (filename, O_RDONLY);
+ fd = open (filename, O_RDONLY | O_CLOEXEC);
if (fd >= 0)
{
char buf[4096 + 1];
@@ -223,7 +223,7 @@ get_progname_of (pid_t pid)
int fd;
sprintf (filename, "/proc/%u/psinfo", (unsigned int) pid);
- fd = open (filename, O_RDONLY);
+ fd = open (filename, O_RDONLY | O_CLOEXEC);
if (fd >= 0)
{
/* The contents is a 'struct psinfo'. But since 'struct psinfo'
@@ -378,7 +378,7 @@ get_progname_of (pid_t pid)
int fd;
sprintf (filename, "/proc/pinfo/%u", pid);
- fd = open (filename, O_RDONLY);
+ fd = open (filename, O_RDONLY | O_CLOEXEC);
if (0 <= fd)
{
prpsinfo_t buf;
diff --git a/modules/get_progname_of b/modules/get_progname_of
index 012cc59..51cef7e 100644
--- a/modules/get_progname_of
+++ b/modules/get_progname_of
@@ -8,6 +8,7 @@ lib/get_progname_of.c
Depends-on:
extensions
unistd
+open
configure.ac:
--
2.7.4
[-- Attachment #9: 0008-getprogname-Make-more-robust-in-multithreaded-applic.patch --]
[-- Type: text/x-patch, Size: 1664 bytes --]
From fe55ae3df5d0818441e337ba2396d77f70f490b2 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 27 May 2020 19:45:19 +0200
Subject: [PATCH 08/18] getprogname: Make more robust in multithreaded
applications.
* lib/getprogname.c (getprogname): Pass an O_CLOEXEC flag to open().
* modules/getprogname (Depends-on): Add 'open'.
---
ChangeLog | 6 ++++++
lib/getprogname.c | 2 +-
modules/getprogname | 1 +
3 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 259fa85..e793a13 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2020-05-27 Bruno Haible <bruno@clisp.org>
+ getprogname: Make more robust in multithreaded applications.
+ * lib/getprogname.c (getprogname): Pass an O_CLOEXEC flag to open().
+ * modules/getprogname (Depends-on): Add 'open'.
+
+2020-05-27 Bruno Haible <bruno@clisp.org>
+
get_progname_of: Make more robust in multithreaded applications.
* lib/get_progname_of.c (get_progname_of): Pass an O_CLOEXEC flag to
open().
diff --git a/lib/getprogname.c b/lib/getprogname.c
index 43c7f76..377e216 100644
--- a/lib/getprogname.c
+++ b/lib/getprogname.c
@@ -223,7 +223,7 @@ getprogname (void)
int fd;
sprintf (filename, "/proc/pinfo/%d", (int) getpid ());
- fd = open (filename, O_RDONLY);
+ fd = open (filename, O_RDONLY | O_CLOEXEC);
if (0 <= fd)
{
prpsinfo_t buf;
diff --git a/modules/getprogname b/modules/getprogname
index 0b3d8fc..e8038d8 100644
--- a/modules/getprogname
+++ b/modules/getprogname
@@ -9,6 +9,7 @@ m4/getprogname.m4
Depends-on:
dirname-lgpl
extensions
+open
configure.ac:
gl_FUNC_GETPROGNAME
--
2.7.4
[-- Attachment #10: 0009-javacomp-Make-more-robust-in-multithreaded-applicati.patch --]
[-- Type: text/x-patch, Size: 1720 bytes --]
From bdf45d582b3761b281bd4eef8e5254f5a03e992a Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 27 May 2020 19:46:45 +0200
Subject: [PATCH 09/18] javacomp: Make more robust in multithreaded
applications.
* lib/javacomp.c (get_classfile_version): Pass an O_CLOEXEC flag to
open().
* modules/javacomp (Depends-on): Add 'open'.
---
ChangeLog | 7 +++++++
lib/javacomp.c | 2 +-
modules/javacomp | 1 +
3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index e793a13..8d139b4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2020-05-27 Bruno Haible <bruno@clisp.org>
+ javacomp: Make more robust in multithreaded applications.
+ * lib/javacomp.c (get_classfile_version): Pass an O_CLOEXEC flag to
+ open().
+ * modules/javacomp (Depends-on): Add 'open'.
+
+2020-05-27 Bruno Haible <bruno@clisp.org>
+
getprogname: Make more robust in multithreaded applications.
* lib/getprogname.c (getprogname): Pass an O_CLOEXEC flag to open().
* modules/getprogname (Depends-on): Add 'open'.
diff --git a/lib/javacomp.c b/lib/javacomp.c
index ac56196..4717a5f 100644
--- a/lib/javacomp.c
+++ b/lib/javacomp.c
@@ -597,7 +597,7 @@ get_classfile_version (const char *compiled_file_name)
int fd;
/* Open the class file. */
- fd = open (compiled_file_name, O_RDONLY | O_BINARY, 0);
+ fd = open (compiled_file_name, O_RDONLY | O_BINARY | O_CLOEXEC, 0);
if (fd >= 0)
{
/* Read its first 8 bytes. */
diff --git a/modules/javacomp b/modules/javacomp
index fccdaac..0552797 100644
--- a/modules/javacomp
+++ b/modules/javacomp
@@ -16,6 +16,7 @@ classpath
xsetenv
sh-quote
binary-io
+open
safe-read
xalloc
xmalloca
--
2.7.4
[-- Attachment #11: 0010-login_tty-Make-more-robust-in-multithreaded-applicat.patch --]
[-- Type: text/x-patch, Size: 1695 bytes --]
From beca2cc498f76ac3449969fba04ede9fe205fbfa Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 27 May 2020 20:01:30 +0200
Subject: [PATCH 10/18] login_tty: Make more robust in multithreaded
applications.
* lib/login_tty.c (login_tty): Pass an O_CLOEXEC flag to open().
* modules/login_tty (Depends-on): Add 'open'.
---
ChangeLog | 6 ++++++
lib/login_tty.c | 2 +-
modules/login_tty | 1 +
3 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 8d139b4..7c7d6b5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2020-05-27 Bruno Haible <bruno@clisp.org>
+ login_tty: Make more robust in multithreaded applications.
+ * lib/login_tty.c (login_tty): Pass an O_CLOEXEC flag to open().
+ * modules/login_tty (Depends-on): Add 'open'.
+
+2020-05-27 Bruno Haible <bruno@clisp.org>
+
javacomp: Make more robust in multithreaded applications.
* lib/javacomp.c (get_classfile_version): Pass an O_CLOEXEC flag to
open().
diff --git a/lib/login_tty.c b/lib/login_tty.c
index 4dfd263..581c276 100644
--- a/lib/login_tty.c
+++ b/lib/login_tty.c
@@ -55,7 +55,7 @@ login_tty (int slave_fd)
slave_name = ttyname (slave_fd);
if (slave_name == NULL)
return -1;
- dummy_fd = open (slave_name, O_RDWR);
+ dummy_fd = open (slave_name, O_RDWR | O_CLOEXEC);
if (dummy_fd < 0)
return -1;
close (dummy_fd);
diff --git a/modules/login_tty b/modules/login_tty
index 59e5e9b..551691e 100644
--- a/modules/login_tty
+++ b/modules/login_tty
@@ -9,6 +9,7 @@ m4/pty.m4
Depends-on:
pty
sys_ioctl
+open [test $ac_cv_func_login_tty = no]
configure.ac:
gl_FUNC_LOGIN_TTY
--
2.7.4
[-- Attachment #12: 0011-mountlist-Make-more-robust-in-multithreaded-applicat.patch --]
[-- Type: text/x-patch, Size: 1730 bytes --]
From a36ae88ccb65931124cb6aafc1a8d2dac63bd699 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 27 May 2020 20:02:57 +0200
Subject: [PATCH 11/18] mountlist: Make more robust in multithreaded
applications.
* lib/mountlist.c (read_file_system_list): Pass an O_CLOEXEC flag to
open().
* modules/mountlist (Depends-on): Add 'open'.
---
ChangeLog | 7 +++++++
lib/mountlist.c | 2 +-
modules/mountlist | 1 +
3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 7c7d6b5..a840c8e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2020-05-27 Bruno Haible <bruno@clisp.org>
+ mountlist: Make more robust in multithreaded applications.
+ * lib/mountlist.c (read_file_system_list): Pass an O_CLOEXEC flag to
+ open().
+ * modules/mountlist (Depends-on): Add 'open'.
+
+2020-05-27 Bruno Haible <bruno@clisp.org>
+
login_tty: Make more robust in multithreaded applications.
* lib/login_tty.c (login_tty): Pass an O_CLOEXEC flag to open().
* modules/login_tty (Depends-on): Add 'open'.
diff --git a/lib/mountlist.c b/lib/mountlist.c
index 4cb19c8..9cf78c8 100644
--- a/lib/mountlist.c
+++ b/lib/mountlist.c
@@ -902,7 +902,7 @@ read_file_system_list (bool need_fs_type)
# ifndef MNTTAB_LOCK
# define MNTTAB_LOCK "/etc/.mnttab.lock"
# endif
- lockfd = open (MNTTAB_LOCK, O_RDONLY);
+ lockfd = open (MNTTAB_LOCK, O_RDONLY | O_CLOEXEC);
if (0 <= lockfd)
{
struct flock flock;
diff --git a/modules/mountlist b/modules/mountlist
index 5bb45ed..7542048 100644
--- a/modules/mountlist
+++ b/modules/mountlist
@@ -10,6 +10,7 @@ m4/mountlist.m4
Depends-on:
fopen-gnu
getline
+open
stdbool
stdint
strstr-simple
--
2.7.4
[-- Attachment #13: 0012-at-internal-Make-more-robust-in-multithreaded-applic.patch --]
[-- Type: text/x-patch, Size: 1603 bytes --]
From bbafdbca04ecb68d90b181d1760f234e8f12044e Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 27 May 2020 20:04:38 +0200
Subject: [PATCH 12/18] at-internal: Make more robust in multithreaded
applications.
* lib/openat-proc.c (openat_proc_name): Pass an O_CLOEXEC flag to
open().
---
ChangeLog | 6 ++++++
lib/openat-proc.c | 5 +++--
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index a840c8e..e5460c7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2020-05-27 Bruno Haible <bruno@clisp.org>
+ at-internal: Make more robust in multithreaded applications.
+ * lib/openat-proc.c (openat_proc_name): Pass an O_CLOEXEC flag to
+ open().
+
+2020-05-27 Bruno Haible <bruno@clisp.org>
+
mountlist: Make more robust in multithreaded applications.
* lib/mountlist.c (read_file_system_list): Pass an O_CLOEXEC flag to
open().
diff --git a/lib/openat-proc.c b/lib/openat-proc.c
index 9111cd3..b5aaee8 100644
--- a/lib/openat-proc.c
+++ b/lib/openat-proc.c
@@ -73,8 +73,9 @@ openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file)
problem is exhibited on code that built on Solaris 8 and
running on Solaris 10. */
- int proc_self_fd = open ("/proc/self/fd",
- O_SEARCH | O_DIRECTORY | O_NOCTTY | O_NONBLOCK);
+ int proc_self_fd =
+ open ("/proc/self/fd",
+ O_SEARCH | O_DIRECTORY | O_NOCTTY | O_NONBLOCK | O_CLOEXEC);
if (proc_self_fd < 0)
proc_status = -1;
else
--
2.7.4
[-- Attachment #14: 0013-openat-Make-more-robust-in-multithreaded-application.patch --]
[-- Type: text/x-patch, Size: 1190 bytes --]
From e1ed63942e873357e02e84eb975656b82e887615 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 27 May 2020 20:06:37 +0200
Subject: [PATCH 13/18] openat: Make more robust in multithreaded applications.
* lib/openat.c (openat_needs_fchdir): Pass an O_CLOEXEC flag to open().
---
ChangeLog | 5 +++++
lib/openat.c | 2 +-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index e5460c7..afc0106 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2020-05-27 Bruno Haible <bruno@clisp.org>
+ openat: Make more robust in multithreaded applications.
+ * lib/openat.c (openat_needs_fchdir): Pass an O_CLOEXEC flag to open().
+
+2020-05-27 Bruno Haible <bruno@clisp.org>
+
at-internal: Make more robust in multithreaded applications.
* lib/openat-proc.c (openat_proc_name): Pass an O_CLOEXEC flag to
open().
diff --git a/lib/openat.c b/lib/openat.c
index fbe1d2e..baf6566 100644
--- a/lib/openat.c
+++ b/lib/openat.c
@@ -291,7 +291,7 @@ bool
openat_needs_fchdir (void)
{
bool needs_fchdir = true;
- int fd = open ("/", O_SEARCH);
+ int fd = open ("/", O_SEARCH | O_CLOEXEC);
if (0 <= fd)
{
--
2.7.4
[-- Attachment #15: 0014-pagealign_alloc-Make-more-robust-in-multithreaded-ap.patch --]
[-- Type: text/x-patch, Size: 1795 bytes --]
From 20db649aa96aa03b8cc3a2e37466c49d4c8c37af Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 27 May 2020 20:08:33 +0200
Subject: [PATCH 14/18] pagealign_alloc: Make more robust in multithreaded
applications.
* lib/pagealign_alloc.c (pagealign_alloc): Pass an O_CLOEXEC flag to
open().
* modules/pagealign_alloc (Depends-on): Add 'open'.
---
ChangeLog | 7 +++++++
lib/pagealign_alloc.c | 2 +-
modules/pagealign_alloc | 1 +
3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index afc0106..c71ecf8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2020-05-27 Bruno Haible <bruno@clisp.org>
+ pagealign_alloc: Make more robust in multithreaded applications.
+ * lib/pagealign_alloc.c (pagealign_alloc): Pass an O_CLOEXEC flag to
+ open().
+ * modules/pagealign_alloc (Depends-on): Add 'open'.
+
+2020-05-27 Bruno Haible <bruno@clisp.org>
+
openat: Make more robust in multithreaded applications.
* lib/openat.c (openat_needs_fchdir): Pass an O_CLOEXEC flag to open().
diff --git a/lib/pagealign_alloc.c b/lib/pagealign_alloc.c
index 1995e9c..3bd803e 100644
--- a/lib/pagealign_alloc.c
+++ b/lib/pagealign_alloc.c
@@ -132,7 +132,7 @@ pagealign_alloc (size_t size)
const int flags = MAP_FILE | MAP_PRIVATE;
if (fd == -1)
{
- fd = open ("/dev/zero", O_RDONLY, 0666);
+ fd = open ("/dev/zero", O_RDONLY | O_CLOEXEC, 0666);
if (fd < 0)
error (EXIT_FAILURE, errno, _("Failed to open /dev/zero for read"));
}
diff --git a/modules/pagealign_alloc b/modules/pagealign_alloc
index 5209b64..b97f9bb 100644
--- a/modules/pagealign_alloc
+++ b/modules/pagealign_alloc
@@ -12,6 +12,7 @@ error
extensions
getpagesize
gettext-h
+open
stdlib
xalloc
unistd
--
2.7.4
[-- Attachment #16: 0015-truncate-Make-more-robust-in-multithreaded-applicati.patch --]
[-- Type: text/x-patch, Size: 1443 bytes --]
From 663fc0066a4aabce029451922abacdd5a614c03f Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 27 May 2020 20:09:49 +0200
Subject: [PATCH 15/18] truncate: Make more robust in multithreaded
applications.
* lib/truncate.c (truncate): Pass an O_CLOEXEC flag to open().
---
ChangeLog | 5 +++++
lib/truncate.c | 4 ++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c71ecf8..8922897 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2020-05-27 Bruno Haible <bruno@clisp.org>
+ truncate: Make more robust in multithreaded applications.
+ * lib/truncate.c (truncate): Pass an O_CLOEXEC flag to open().
+
+2020-05-27 Bruno Haible <bruno@clisp.org>
+
pagealign_alloc: Make more robust in multithreaded applications.
* lib/pagealign_alloc.c (pagealign_alloc): Pass an O_CLOEXEC flag to
open().
diff --git a/lib/truncate.c b/lib/truncate.c
index 456f7aa..b04f7c7 100644
--- a/lib/truncate.c
+++ b/lib/truncate.c
@@ -29,13 +29,13 @@ truncate (const char *filename, off_t length)
if (length == 0)
{
- fd = open (filename, O_WRONLY | O_TRUNC);
+ fd = open (filename, O_WRONLY | O_TRUNC | O_CLOEXEC);
if (fd < 0)
return -1;
}
else
{
- fd = open (filename, O_WRONLY);
+ fd = open (filename, O_WRONLY | O_CLOEXEC);
if (fd < 0)
return -1;
if (ftruncate (fd, length) < 0)
--
2.7.4
[-- Attachment #17: 0016-vma-iter-Make-more-robust-in-multithreaded-applicati.patch --]
[-- Type: text/x-patch, Size: 3773 bytes --]
From e1139059e5c5e05c955adb2d6fec357235b158b2 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 27 May 2020 20:11:27 +0200
Subject: [PATCH 16/18] vma-iter: Make more robust in multithreaded
applications.
* lib/vma-iter.c (rof_open, vma_iterate): Pass an O_CLOEXEC flag to
open().
* modules/vma-iter (Depends-on): Add 'open'.
---
ChangeLog | 7 +++++++
lib/vma-iter.c | 16 ++++++++--------
modules/vma-iter | 1 +
3 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 8922897..4946b1d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2020-05-27 Bruno Haible <bruno@clisp.org>
+ vma-iter: Make more robust in multithreaded applications.
+ * lib/vma-iter.c (rof_open, vma_iterate): Pass an O_CLOEXEC flag to
+ open().
+ * modules/vma-iter (Depends-on): Add 'open'.
+
+2020-05-27 Bruno Haible <bruno@clisp.org>
+
truncate: Make more robust in multithreaded applications.
* lib/truncate.c (truncate): Pass an O_CLOEXEC flag to open().
diff --git a/lib/vma-iter.c b/lib/vma-iter.c
index a1f67f0..10ccda4 100644
--- a/lib/vma-iter.c
+++ b/lib/vma-iter.c
@@ -174,7 +174,7 @@ rof_open (struct rofile *rof, const char *filename)
unsigned long pagesize;
size_t size;
- fd = open (filename, O_RDONLY);
+ fd = open (filename, O_RDONLY | O_CLOEXEC);
if (fd < 0)
return -1;
rof->position = 0;
@@ -267,7 +267,7 @@ rof_open (struct rofile *rof, const char *filename)
if (lseek (fd, 0, SEEK_SET) < 0)
{
close (fd);
- fd = open (filename, O_RDONLY);
+ fd = open (filename, O_RDONLY | O_CLOEXEC);
if (fd < 0)
goto fail2;
}
@@ -924,7 +924,7 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
fname -= 6;
memcpy (fname, "/proc/", 6);
- fd = open (fname, O_RDONLY);
+ fd = open (fname, O_RDONLY | O_CLOEXEC);
if (fd < 0)
return -1;
@@ -939,7 +939,7 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
So use mmap(), and ignore the resulting VMA. */
memneed = ((memneed - 1) / pagesize + 1) * pagesize;
# if !HAVE_MAP_ANONYMOUS
- zero_fd = open ("/dev/zero", O_RDONLY, 0644);
+ zero_fd = open ("/dev/zero", O_RDONLY | O_CLOEXEC, 0644);
if (zero_fd < 0)
goto fail2;
# endif
@@ -1049,7 +1049,7 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
fname -= 6;
memcpy (fname, "/proc/", 6);
- fd = open (fname, O_RDONLY);
+ fd = open (fname, O_RDONLY | O_CLOEXEC);
if (fd < 0)
return -1;
@@ -1064,7 +1064,7 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
So use mmap(), and ignore the resulting VMA. */
memneed = ((memneed - 1) / pagesize + 1) * pagesize;
# if !HAVE_MAP_ANONYMOUS
- zero_fd = open ("/dev/zero", O_RDONLY, 0644);
+ zero_fd = open ("/dev/zero", O_RDONLY | O_CLOEXEC, 0644);
if (zero_fd < 0)
goto fail2;
# endif
@@ -1168,7 +1168,7 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
fname -= 6;
memcpy (fname, "/proc/", 6);
- fd = open (fname, O_RDONLY);
+ fd = open (fname, O_RDONLY | O_CLOEXEC);
if (fd < 0)
return -1;
@@ -1187,7 +1187,7 @@ vma_iterate (vma_iterate_callback_fn callback, void *data)
So use mmap(), and ignore the resulting VMA. */
memneed = ((memneed - 1) / pagesize + 1) * pagesize;
# if !HAVE_MAP_ANONYMOUS
- zero_fd = open ("/dev/zero", O_RDONLY, 0644);
+ zero_fd = open ("/dev/zero", O_RDONLY | O_CLOEXEC, 0644);
if (zero_fd < 0)
goto fail2;
# endif
diff --git a/modules/vma-iter b/modules/vma-iter
index 08f3c0f..4c8ce8c 100644
--- a/modules/vma-iter
+++ b/modules/vma-iter
@@ -11,6 +11,7 @@ stdint
unistd
extensions
getpagesize
+open
configure.ac:
gl_FUNC_MMAP_ANON
--
2.7.4
[-- Attachment #18: 0017-getloadavg-Make-more-robust-in-multithreaded-applica.patch --]
[-- Type: text/x-patch, Size: 2657 bytes --]
From 4faf8a77c0e24e7dbd945e7fdad6961a63335910 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 27 May 2020 20:16:33 +0200
Subject: [PATCH 17/18] getloadavg: Make more robust in multithreaded
applications.
* lib/getloadavg.c (getloadavg): Pass an O_CLOEXEC flag to open().
Simplify use of O_CLOEXEC.
* modules/getloadavg (Depends-on): Add 'open'.
---
ChangeLog | 7 +++++++
lib/getloadavg.c | 22 +++-------------------
modules/getloadavg | 1 +
3 files changed, 11 insertions(+), 19 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 4946b1d..e60de12 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2020-05-27 Bruno Haible <bruno@clisp.org>
+ getloadavg: Make more robust in multithreaded applications.
+ * lib/getloadavg.c (getloadavg): Pass an O_CLOEXEC flag to open().
+ Simplify use of O_CLOEXEC.
+ * modules/getloadavg (Depends-on): Add 'open'.
+
+2020-05-27 Bruno Haible <bruno@clisp.org>
+
vma-iter: Make more robust in multithreaded applications.
* lib/vma-iter.c (rof_open, vma_iterate): Pass an O_CLOEXEC flag to
open().
diff --git a/lib/getloadavg.c b/lib/getloadavg.c
index 7e11c32..61307d3 100644
--- a/lib/getloadavg.c
+++ b/lib/getloadavg.c
@@ -512,7 +512,7 @@ getloadavg (double loadavg[], int nelem)
char const *ptr = ldavgbuf;
int fd, count, saved_errno;
- fd = open (LINUX_LDAV_FILE, O_RDONLY);
+ fd = open (LINUX_LDAV_FILE, O_RDONLY | O_CLOEXEC);
if (fd == -1)
return -1;
count = read (fd, ldavgbuf, sizeof ldavgbuf - 1);
@@ -869,27 +869,11 @@ getloadavg (double loadavg[], int nelem)
if (!getloadavg_initialized)
{
# ifndef SUNOS_5
- /* Set the channel to close on exec, so it does not
- litter any child's descriptor table. */
-# ifndef O_CLOEXEC
-# define O_CLOEXEC 0
-# endif
int fd = open ("/dev/kmem", O_RDONLY | O_CLOEXEC);
if (0 <= fd)
{
-# if F_DUPFD_CLOEXEC
- if (fd <= STDERR_FILENO)
- {
- int fd1 = fcntl (fd, F_DUPFD_CLOEXEC, STDERR_FILENO + 1);
- close (fd);
- fd = fd1;
- }
-# endif
- if (0 <= fd)
- {
- channel = fd;
- getloadavg_initialized = true;
- }
+ channel = fd;
+ getloadavg_initialized = true;
}
# else /* SUNOS_5 */
/* We pass 0 for the kernel, corefile, and swapfile names
diff --git a/modules/getloadavg b/modules/getloadavg
index e14ddc8..a5a3c4e 100644
--- a/modules/getloadavg
+++ b/modules/getloadavg
@@ -9,6 +9,7 @@ Depends-on:
extensions
fopen-gnu
intprops
+open
stdbool
stdlib
--
2.7.4
[-- Attachment #19: 0018-relocatable-prog-Make-more-robust-in-multithreaded-a.patch --]
[-- Type: text/x-patch, Size: 3265 bytes --]
From 4dfe4949cb1b0ea23281b32f8a06c8f4aab2418f Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Wed, 27 May 2020 20:35:39 +0200
Subject: [PATCH 18/18] relocatable-prog: Make more robust in multithreaded
applications.
* lib/progreloc.c (O_CLOEXEC): Define fallback to 0 when use from module
relocatable-prog-wrapper.
(find_executable): Pass an O_CLOEXEC flag to open().
* modules/relocatable-prog (Depends-on): Add 'open'.
---
ChangeLog | 8 ++++++++
lib/progreloc.c | 13 +++++++++----
modules/relocatable-prog | 1 +
3 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e60de12..c35e2fd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2020-05-27 Bruno Haible <bruno@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.
+ (find_executable): Pass an O_CLOEXEC flag to open().
+ * modules/relocatable-prog (Depends-on): Add 'open'.
+
+2020-05-27 Bruno Haible <bruno@clisp.org>
+
getloadavg: Make more robust in multithreaded applications.
* lib/getloadavg.c (getloadavg): Pass an O_CLOEXEC flag to open().
Simplify use of O_CLOEXEC.
diff --git a/lib/progreloc.c b/lib/progreloc.c
index 45be1ca..de00bf6 100644
--- a/lib/progreloc.c
+++ b/lib/progreloc.c
@@ -70,6 +70,11 @@
# define O_EXEC O_RDONLY /* This is often close enough in older systems. */
#endif
+#if defined IN_RELOCWRAPPER && (!defined O_CLOEXEC || GNULIB_defined_O_CLOEXEC)
+# undef O_CLOEXEC
+# define O_CLOEXEC 0
+#endif
+
/* Declare canonicalize_file_name.
The <stdlib.h> included above may be the system's one, not the gnulib
one. */
@@ -242,7 +247,7 @@ find_executable (const char *argv0)
if (link != NULL && link[0] != '[')
return link;
if (executable_fd < 0)
- executable_fd = open ("/proc/self/exe", O_EXEC, 0);
+ executable_fd = open ("/proc/self/exe", O_EXEC | O_CLOEXEC, 0);
{
char buf[6+10+5];
@@ -251,7 +256,7 @@ find_executable (const char *argv0)
if (link != NULL && link[0] != '[')
return link;
if (executable_fd < 0)
- executable_fd = open (buf, O_EXEC, 0);
+ executable_fd = open (buf, O_EXEC | O_CLOEXEC, 0);
}
}
# endif
@@ -298,7 +303,7 @@ find_executable (const char *argv0)
the current directory. */
{
char namebuf[4096];
- int fd = open ("/proc/self/execname", O_RDONLY, 0);
+ int fd = open ("/proc/self/execname", O_RDONLY | O_CLOEXEC, 0);
if (fd >= 0)
{
size_t len = full_read (fd, namebuf, sizeof (namebuf));
@@ -321,7 +326,7 @@ find_executable (const char *argv0)
if (link != NULL)
return link;
if (executable_fd < 0)
- executable_fd = open ("/proc/self/exe", O_EXEC, 0);
+ executable_fd = open ("/proc/self/exe", O_EXEC | O_CLOEXEC, 0);
}
# endif
# if HAVE_MACH_O_DYLD_H && HAVE__NSGETEXECUTABLEPATH
diff --git a/modules/relocatable-prog b/modules/relocatable-prog
index 4111665..7e21682 100644
--- a/modules/relocatable-prog
+++ b/modules/relocatable-prog
@@ -20,6 +20,7 @@ progname
canonicalize-lgpl
xalloc
xreadlink
+open
stdbool
unistd
memcmp
--
2.7.4
next reply other threads:[~2020-05-27 18:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-27 18:43 Bruno Haible [this message]
2020-05-27 21:55 ` use O_CLOEXEC in more places Bernhard Voelker
2020-05-27 22:21 ` Jim Meyering
2020-05-27 23:33 ` Paul Eggert
2020-05-28 19:51 ` Bruno Haible
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2127200.Gmmp1eMdPG@omega \
--to=bruno@clisp.org \
--cc=bug-gnulib@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).