[gimp] app: add gimp_spawn_set_cloexec()



commit cdb541f81b4ffc1b1ebe58a1b6c9c48f82493504
Author: Ell <ell_se yahoo com>
Date:   Tue Mar 6 16:10:29 2018 -0500

    app: add gimp_spawn_set_cloexec()
    
    ... which prevents child processes from inheriting a given pipe,
    under *nix and Windows.

 app/core/gimp-spawn.c |   20 ++++++++++++++++++++
 app/core/gimp-spawn.h |   12 +++++++-----
 configure.ac          |    2 +-
 3 files changed, 28 insertions(+), 6 deletions(-)
---
diff --git a/app/core/gimp-spawn.c b/app/core/gimp-spawn.c
index 7fcb093..071b135 100644
--- a/app/core/gimp-spawn.c
+++ b/app/core/gimp-spawn.c
@@ -27,6 +27,14 @@
 #include <errno.h>
 #endif
 
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+
+#ifdef G_OS_WIN32
+#include <windows.h>
+#endif
+
 #include <glib-object.h>
 
 #include "core-types.h"
@@ -226,3 +234,15 @@ gimp_spawn_async (gchar       **argv,
 
   return g_spawn_async (NULL, argv, envp, flags, NULL, NULL, child_pid, error);
 }
+
+void
+gimp_spawn_set_cloexec (gint fd)
+{
+#if defined (G_OS_WIN32)
+  SetHandleInformation ((HANDLE) _get_osfhandle (fd), HANDLE_FLAG_INHERIT, 0);
+#elif defined (HAVE_FCNTL_H)
+  fcntl (fd, F_SETFD, fcntl (fd, F_GETFD, 0) | FD_CLOEXEC);
+#elif defined (__GNUC__)
+#warning gimp_spawn_set_cloexec() is not implemented for the target platform
+#endif
+}
diff --git a/app/core/gimp-spawn.h b/app/core/gimp-spawn.h
index 432296e..a2494e9 100644
--- a/app/core/gimp-spawn.h
+++ b/app/core/gimp-spawn.h
@@ -22,11 +22,13 @@
 #define __GIMP_SPAWN_H__
 
 
-gboolean   gimp_spawn_async (gchar       **argv,
-                             gchar       **envp,
-                             GSpawnFlags   flags,
-                             GPid         *child_pid,
-                             GError      **error);
+gboolean   gimp_spawn_async       (gchar       **argv,
+                                   gchar       **envp,
+                                   GSpawnFlags   flags,
+                                   GPid         *child_pid,
+                                   GError      **error);
+
+void       gimp_spawn_set_cloexec (gint          fd);
 
 
 #endif /* __GIMP_SPAWN_H__ */
diff --git a/configure.ac b/configure.ac
index c9d65bf..b23171a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -562,7 +562,7 @@ AC_HEADER_STDC
 AC_HEADER_SYS_WAIT
 AC_HEADER_TIME
 
-AC_CHECK_HEADERS(execinfo.h sys/param.h sys/prctl.h sys/time.h sys/times.h sys/wait.h unistd.h)
+AC_CHECK_HEADERS(execinfo.h fcntl.h sys/param.h sys/prctl.h sys/time.h sys/times.h sys/wait.h unistd.h)
 AC_CHECK_FUNCS(backtrace, , AC_CHECK_LIB(execinfo, backtrace))
 
 AC_TYPE_PID_T


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