[glib/backport-2325-symlink-replace-file-glib-2-66: 5/5] glocalfileoutputstream: Add a missing O_CLOEXEC flag to replace()
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/backport-2325-symlink-replace-file-glib-2-66: 5/5] glocalfileoutputstream: Add a missing O_CLOEXEC flag to replace()
- Date: Wed, 10 Mar 2021 16:59:30 +0000 (UTC)
commit 8488cb0b4d412688132bec42f311852fdc9de2bd
Author: Philip Withnall <pwithnall endlessos org>
Date: Wed Feb 24 17:42:24 2021 +0000
glocalfileoutputstream: Add a missing O_CLOEXEC flag to replace()
Signed-off-by: Philip Withnall <pwithnall endlessos org>
gio/glocalfileoutputstream.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/gio/glocalfileoutputstream.c b/gio/glocalfileoutputstream.c
index 162e94da6..2b87776bc 100644
--- a/gio/glocalfileoutputstream.c
+++ b/gio/glocalfileoutputstream.c
@@ -63,6 +63,12 @@
#define O_BINARY 0
#endif
+#ifndef O_CLOEXEC
+#define O_CLOEXEC 0
+#else
+#define HAVE_O_CLOEXEC 1
+#endif
+
struct _GLocalFileOutputStreamPrivate {
char *tmp_filename;
char *original_filename;
@@ -1233,7 +1239,7 @@ _g_local_file_output_stream_replace (const char *filename,
sync_on_close = FALSE;
/* If the file doesn't exist, create it */
- open_flags = O_CREAT | O_EXCL | O_BINARY;
+ open_flags = O_CREAT | O_EXCL | O_BINARY | O_CLOEXEC;
if (readable)
open_flags |= O_RDWR;
else
@@ -1263,8 +1269,11 @@ _g_local_file_output_stream_replace (const char *filename,
set_error_from_open_errno (filename, error);
return NULL;
}
-
-
+#ifndef HAVE_O_CLOEXEC
+ else
+ fcntl (fd, F_SETFD, FD_CLOEXEC);
+#endif
+
stream = g_object_new (G_TYPE_LOCAL_FILE_OUTPUT_STREAM, NULL);
stream->priv->fd = fd;
stream->priv->sync_on_close = sync_on_close;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]