[glib/th/gspawn-no-safe-close: 11/11] gspawn: use _g_safe_close()




commit c83b5b5b4e9ddab3c69e43e150d466137c44d69c
Author: Thomas Haller <thaller redhat com>
Date:   Wed Oct 12 23:30:37 2022 +0200

    gspawn: use _g_safe_close()
    
    _g_safe_close() gets all the parts right. We really should use it
    everywhere, instead of g_close() and instead of close().
    
    Update "gspawn.c" to drop its safe_close() function and use
    _g_safe_close() instead.

 glib/gspawn.c | 34 ++++++----------------------------
 1 file changed, 6 insertions(+), 28 deletions(-)
---
diff --git a/glib/gspawn.c b/glib/gspawn.c
index c644cebb11..b748cc9fe5 100644
--- a/glib/gspawn.c
+++ b/glib/gspawn.c
@@ -58,6 +58,7 @@
 #include "gthread.h"
 #include "gtrace-private.h"
 #include "glib/gstdio.h"
+#include "gutilsprivate.h"
 
 #include "genviron.h"
 #include "gmem.h"
@@ -162,8 +163,6 @@ extern char **environ;
  */
 
 
-static void safe_close (gint fd);
-
 static gint g_execute (const gchar  *file,
                        gchar       **argv,
                        gchar       **argv_buffer,
@@ -267,11 +266,9 @@ close_and_invalidate (gint *fd)
 {
   if (*fd < 0)
     return;
-  else
-    {
-      safe_close (*fd);
-      *fd = -1;
-    }
+
+  _g_safe_close (*fd);
+  *fd = -1;
 }
 
 /* Some versions of OS X define READ_OK in public headers */
@@ -1338,32 +1335,13 @@ dupfd_cloexec (int old_fd, int new_fd_min)
   return fd;
 }
 
-/* This function is called between fork() and exec() and hence must be
- * async-signal-safe (see signal-safety(7)). */
-static void
-safe_close (gint fd)
-{
-  /* Note that this function is (also) called after fork(), so it cannot use
-   * g_close().
-   * Note that it is however called both from the parent and the child
-   * process.
-   *
-   * This function returns no error, because there is nothing what the caller
-   * could do with that information. That is even the case for EINTR. See
-   * g_close() about the specialty of EINTR and why that is correct.
-   * If g_close() ever gets extended to handle EINTR specially, then this place
-   * and all other direct calls to close() need updating.
-   */
-  close (fd);
-}
-
 /* This function is called between fork() and exec() and hence must be
  * async-signal-safe (see signal-safety(7)). */
 G_GNUC_UNUSED static int
 close_func (void *data, int fd)
 {
   if (fd >= GPOINTER_TO_INT (data))
-    safe_close (fd);
+    _g_safe_close (fd);
 
   return 0;
 }
@@ -1458,7 +1436,7 @@ safe_fdwalk (int (*cb)(void *data, int fd), void *data)
             }
         }
 
-      safe_close (dir_fd);
+      _g_safe_close (dir_fd);
       return res;
     }
 


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