[gimp] app, libgimp: don't close parent pipes in libgimp; use gimp_spawn_set_cloexec()



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

    app, libgimp: don't close parent pipes in libgimp; use gimp_spawn_set_cloexec()
    
    In gimp_plug_in_open(), use gimp_spawn_set_cloexec() to prevent the
    parent's end of the read/write pipes from being inherited by the
    spawned plug-in, instead of passing the corresponding file
    descriptors to the plug-in as command-line arguments, and having
    gimp_main() close them.
    
    Adding new command-line arguments to plug-ins is problematic, since
    their ability to handle them depends on their protocol version,
    which is only communicated after the plug-in is spawned.
    
    Regardless, this is much simpler.

 app/plug-in/gimpplugin.c |   20 +++++---------------
 libgimp/gimp.c           |    6 ------
 2 files changed, 5 insertions(+), 21 deletions(-)
---
diff --git a/app/plug-in/gimpplugin.c b/app/plug-in/gimpplugin.c
index d51d282..8869bc4 100644
--- a/app/plug-in/gimpplugin.c
+++ b/app/plug-in/gimpplugin.c
@@ -218,12 +218,11 @@ gimp_plug_in_open (GimpPlugIn         *plug_in,
   gint          my_read[2];
   gint          my_write[2];
   gchar       **envp;
-  const gchar  *args[11];
+  const gchar  *args[9];
   gchar       **argv;
   gint          argc;
   gchar        *interp, *interp_arg;
   gchar        *his_read_fd, *his_write_fd;
-  gchar        *my_read_fd, *my_write_fd;
   const gchar  *mode;
   gchar        *stm;
   GError       *error = NULL;
@@ -254,11 +253,11 @@ gimp_plug_in_open (GimpPlugIn         *plug_in,
   setmode (my_write[1], _O_BINARY);
 #endif
 
-#ifdef G_OS_WIN32
-  /* Prevent the plug-in from inheriting our ends of the pipes */
-  SetHandleInformation ((HANDLE) _get_osfhandle (my_read[0]), HANDLE_FLAG_INHERIT, 0);
-  SetHandleInformation ((HANDLE) _get_osfhandle (my_write[1]), HANDLE_FLAG_INHERIT, 0);
+  /* Prevent the plug-in from inheriting our end of the pipes */
+  gimp_spawn_set_cloexec (my_read[0]);
+  gimp_spawn_set_cloexec (my_write[1]);
 
+#ifdef G_OS_WIN32
   plug_in->my_read   = g_io_channel_win32_new_fd (my_read[0]);
   plug_in->my_write  = g_io_channel_win32_new_fd (my_write[1]);
   plug_in->his_read  = g_io_channel_win32_new_fd (my_write[0]);
@@ -292,11 +291,6 @@ gimp_plug_in_open (GimpPlugIn         *plug_in,
   his_write_fd = g_strdup_printf ("%d",
                                   g_io_channel_unix_get_fd (plug_in->his_write));
 
-  my_read_fd   = g_strdup_printf ("%d",
-                                  g_io_channel_unix_get_fd (plug_in->my_read));
-  my_write_fd  = g_strdup_printf ("%d",
-                                  g_io_channel_unix_get_fd (plug_in->my_write));
-
   switch (call_mode)
     {
     case GIMP_PLUG_IN_CALL_QUERY:
@@ -337,8 +331,6 @@ gimp_plug_in_open (GimpPlugIn         *plug_in,
   args[argc++] = "-gimp";
   args[argc++] = his_read_fd;
   args[argc++] = his_write_fd;
-  args[argc++] = my_read_fd;
-  args[argc++] = my_write_fd;
   args[argc++] = mode;
   args[argc++] = stm;
   args[argc++] = NULL;
@@ -411,8 +403,6 @@ gimp_plug_in_open (GimpPlugIn         *plug_in,
 
   g_free (his_read_fd);
   g_free (his_write_fd);
-  g_free (my_read_fd);
-  g_free (my_write_fd);
   g_free (stm);
   g_free (interp);
   g_free (interp_arg);
diff --git a/libgimp/gimp.c b/libgimp/gimp.c
index d15cd89..5905f5e 100644
--- a/libgimp/gimp.c
+++ b/libgimp/gimp.c
@@ -259,8 +259,6 @@ gimp_main (const GimpPlugInInfo *info,
     ARG_GIMP,
     ARG_READ_FD,
     ARG_WRITE_FD,
-    ARG_PARENT_READ_FD,
-    ARG_PARENT_WRITE_FD,
     ARG_MODE,
     ARG_STACK_TRACE_MODE,
 
@@ -506,10 +504,6 @@ gimp_main (const GimpPlugInInfo *info,
 #else
   _readchannel  = g_io_channel_unix_new (atoi (argv[ARG_READ_FD]));
   _writechannel = g_io_channel_unix_new (atoi (argv[ARG_WRITE_FD]));
-
-  /* Close parent end of pipes */
-  close (atoi (argv[ARG_PARENT_READ_FD]));
-  close (atoi (argv[ARG_PARENT_WRITE_FD]));
 #endif
 
   g_io_channel_set_encoding (_readchannel, NULL, NULL);


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