GNU bug report logs -
#79415
[PATCH] Fix tmpfile close on execute
Previous Next
To reply to this bug, email your comments to 79415 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-guile <at> gnu.org
:
bug#79415
; Package
guile
.
(Tue, 09 Sep 2025 17:36:03 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
odion <at> efficios.com
:
New bug report received and forwarded. Copy sent to
bug-guile <at> gnu.org
.
(Tue, 09 Sep 2025 17:36:03 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
From: Olivier Dion <olivier.dion <at> polymtl.ca>
Guile duplicates the underlying file descriptor stored in a FILE pointer
returned by tmpfile(3). This is done to manage the file descriptor with
Guile's ports abstraction instead of using the C FILE pointer
abstraction.
However, the dup(2) system call does not copy the file descriptor
flags (O_CLOEXEC), which is important for respecting the semantic
expected from tmpfile(3) in that the temporary file will not leak to
child processes.
Fix this by using the fcntl(2) system call using the `F_DUPFD_CLOEXEC'
command.
* libguile/posix.c (scm_tmpfile): Use fcntl(2) instead of dup(2) on none
MINGW32 systems.
---
libguile/posix.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/libguile/posix.c b/libguile/posix.c
index c8bbb0f83..fc9a116ed 100644
--- a/libguile/posix.c
+++ b/libguile/posix.c
@@ -1825,7 +1825,19 @@ SCM_DEFINE (scm_tmpfile, "tmpfile", 0, 0, 0,
SCM_SYSERROR;
#ifndef __MINGW32__
- fd = dup (fileno (rv));
+ /* tmpfile(3) says:
+ [...] the file will be automatically deleted when it is closed
+ or the program terminates.
+
+ That last part can only be done if the `O_CLOEXEC' file descriptor
+ flag is set.
+
+ However, dup(2) does not copy the file descriptor flags to the new
+ file descriptor. fcntl(2) with the `F_DUPFD_CLOEXEC' command
+ essentially to the same thing as dup(2) but will set the
+ `O_CLOEXEC' flag on the new file descriptor, thus preserving the
+ expected behavior. */
+ fd = fcntl (fileno (rv), F_DUPFD_CLOEXEC, 0);
fclose (rv);
#else
fd = fileno (rv);
--
2.50.1
This bug report was last modified 5 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.