Blame SOURCES/0003-glocalfileoutputstream-Add-a-missing-O_CLOEXEC-flag-.patch

e5da31
From 7f0b0d7fd744ad2f51236444005db49c80a0293d Mon Sep 17 00:00:00 2001
e5da31
From: Philip Withnall <pwithnall@endlessos.org>
e5da31
Date: Wed, 24 Feb 2021 17:42:24 +0000
e5da31
Subject: [PATCH 3/3] glocalfileoutputstream: Add a missing O_CLOEXEC flag to
e5da31
 replace()
e5da31
e5da31
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
e5da31
---
e5da31
 gio/glocalfileoutputstream.c | 15 ++++++++++++---
e5da31
 1 file changed, 12 insertions(+), 3 deletions(-)
e5da31
e5da31
diff --git a/gio/glocalfileoutputstream.c b/gio/glocalfileoutputstream.c
e5da31
index 4a7766f68..275770fa4 100644
e5da31
--- a/gio/glocalfileoutputstream.c
e5da31
+++ b/gio/glocalfileoutputstream.c
e5da31
@@ -56,6 +56,12 @@
e5da31
 #define O_BINARY 0
e5da31
 #endif
e5da31
 
e5da31
+#ifndef O_CLOEXEC
e5da31
+#define O_CLOEXEC 0
e5da31
+#else
e5da31
+#define HAVE_O_CLOEXEC 1
e5da31
+#endif
e5da31
+
e5da31
 struct _GLocalFileOutputStreamPrivate {
e5da31
   char *tmp_filename;
e5da31
   char *original_filename;
e5da31
@@ -1127,7 +1133,7 @@ _g_local_file_output_stream_replace (const char        *filename,
e5da31
   sync_on_close = FALSE;
e5da31
 
e5da31
   /* If the file doesn't exist, create it */
e5da31
-  open_flags = O_CREAT | O_EXCL | O_BINARY;
e5da31
+  open_flags = O_CREAT | O_EXCL | O_BINARY | O_CLOEXEC;
e5da31
   if (readable)
e5da31
     open_flags |= O_RDWR;
e5da31
   else
e5da31
@@ -1157,8 +1163,11 @@ _g_local_file_output_stream_replace (const char        *filename,
e5da31
       set_error_from_open_errno (filename, error);
e5da31
       return NULL;
e5da31
     }
e5da31
-  
e5da31
- 
e5da31
+#if !defined(HAVE_O_CLOEXEC) && defined(F_SETFD)
e5da31
+  else
e5da31
+    fcntl (fd, F_SETFD, FD_CLOEXEC);
e5da31
+#endif
e5da31
+
e5da31
   stream = g_object_new (G_TYPE_LOCAL_FILE_OUTPUT_STREAM, NULL);
e5da31
   stream->priv->fd = fd;
e5da31
   stream->priv->sync_on_close = sync_on_close;
e5da31
-- 
e5da31
2.31.1
e5da31