[libgsystem] fileutils: Consistently use O_CLOEXEC



commit b7a7c839965c1bb6d8436129c3e3b9d564d885a3
Author: Colin Walters <walters verbum org>
Date:   Wed Jan 7 08:12:25 2015 -0500

    fileutils: Consistently use O_CLOEXEC
    
    For the standard thread+fork safety reasons.

 src/gsystem-file-utils.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
---
diff --git a/src/gsystem-file-utils.c b/src/gsystem-file-utils.c
index bbb6b75..5c1b251 100644
--- a/src/gsystem-file-utils.c
+++ b/src/gsystem-file-utils.c
@@ -92,7 +92,7 @@ gs_file_openat_noatime (int            dfd,
 
 #ifdef O_NOATIME
   do
-    fd = openat (dfd, name, O_RDONLY | O_NOATIME, 0);
+    fd = openat (dfd, name, O_RDONLY | O_NOATIME | O_CLOEXEC, 0);
   while (G_UNLIKELY (fd == -1 && errno == EINTR));
   /* Only the owner or superuser may use O_NOATIME; so we may get
    * EPERM.  EINVAL may happen if the kernel is really old...
@@ -100,7 +100,7 @@ gs_file_openat_noatime (int            dfd,
   if (fd == -1 && (errno == EPERM || errno == EINVAL))
 #endif
     do
-      fd = openat (dfd, name, O_RDONLY, 0);
+      fd = openat (dfd, name, O_RDONLY | O_CLOEXEC, 0);
     while (G_UNLIKELY (fd == -1 && errno == EINTR));
   
   if (fd == -1)
@@ -562,7 +562,7 @@ gs_file_open_in_tmpdir_at (int                tmpdir_fd,
       tmp_name = gs_fileutil_gen_tmp_name (NULL, NULL);
 
       do
-        fd = openat (tmpdir_fd, tmp_name, O_WRONLY | O_CREAT | O_EXCL, mode);
+        fd = openat (tmpdir_fd, tmp_name, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, mode);
       while (fd == -1 && errno == EINTR);
       if (fd < 0 && errno != EEXIST)
         {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]