From 2625e7d0916bc035a645c7b0fc697dc6e1c560c1 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 27 May 2020 19:35:28 +0200 Subject: [PATCH] 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 f3de49807f..fa18753a3d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2020-05-28 Bruno Haible + + chown: Make more robust in multithreaded applications. + * lib/chown.c (rpl_chown): Pass an O_CLOEXEC flag to open(). + 2020-05-28 Bruno Haible doc: Fix statement about O_CLOEXEC (wrong since 2017-08-14). diff --git a/lib/chown.c b/lib/chown.c index 46e753e0e8..6a8a76c920 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.39.5