Patch from Sven Neumann to make the include order consistent. (#71704)
[platform/upstream/glib.git] / glib / gspawn-win32.c
index 1ffecff..ab6eb2d 100644 (file)
 
 #include <config.h>
 
+#include "config.h"
+
 #include "glib.h"
+#include "gprintfint.h"
 
 #include <string.h>
 #include <stdlib.h>
@@ -99,6 +102,7 @@ enum {
 static gboolean make_pipe            (gint                  p[2],
                                       GError              **error);
 static gboolean do_spawn_with_pipes  (gboolean              dont_wait,
+                                     gboolean              dont_return_handle,
                                      const gchar          *working_directory,
                                       gchar               **argv,
                                       gchar               **envp,
@@ -254,6 +258,7 @@ g_spawn_sync (const gchar          *working_directory,
     *standard_error = NULL;
   
   if (!do_spawn_with_pipes (FALSE,
+                           TRUE,
                            working_directory,
                            argv,
                            envp,
@@ -444,6 +449,7 @@ g_spawn_async_with_pipes (const gchar          *working_directory,
                         !(flags & G_SPAWN_CHILD_INHERITS_STDIN), FALSE);
   
   return do_spawn_with_pipes (TRUE,
+                             !(flags & G_SPAWN_DO_NOT_REAP_CHILD),
                              working_directory,
                              argv,
                              envp,
@@ -552,12 +558,12 @@ do_spawn (gboolean              dont_wait,
   new_argv = g_new (gchar *, argc + 1 + ARG_COUNT);
 
   new_argv[0] = "gspawn-win32-helper";
-  sprintf (args[ARG_CHILD_ERR_REPORT], "%d", child_err_report_fd);
+  _g_sprintf (args[ARG_CHILD_ERR_REPORT], "%d", child_err_report_fd);
   new_argv[ARG_CHILD_ERR_REPORT] = args[ARG_CHILD_ERR_REPORT];
 
   if (stdin_fd >= 0)
     {
-      sprintf (args[ARG_STDIN], "%d", stdin_fd);
+      _g_sprintf (args[ARG_STDIN], "%d", stdin_fd);
       new_argv[ARG_STDIN] = args[ARG_STDIN];
     }
   else if (child_inherits_stdin)
@@ -573,7 +579,7 @@ do_spawn (gboolean              dont_wait,
 
   if (stdout_fd >= 0)
     {
-      sprintf (args[ARG_STDOUT], "%d", stdout_fd);
+      _g_sprintf (args[ARG_STDOUT], "%d", stdout_fd);
       new_argv[ARG_STDOUT] = args[ARG_STDOUT];
     }
   else if (stdout_to_null)
@@ -587,7 +593,7 @@ do_spawn (gboolean              dont_wait,
 
   if (stderr_fd >= 0)
     {
-      sprintf (args[ARG_STDERR], "%d", stderr_fd);
+      _g_sprintf (args[ARG_STDERR], "%d", stderr_fd);
       new_argv[ARG_STDERR] = args[ARG_STDERR];
     }
   else if (stderr_to_null)
@@ -714,6 +720,7 @@ read_ints (int      fd,
 
 static gboolean
 do_spawn_with_pipes (gboolean              dont_wait,
+                    gboolean              dont_return_handle,
                     const gchar          *working_directory,
                     gchar               **argv,
                     gchar               **envp,
@@ -787,7 +794,7 @@ do_spawn_with_pipes (gboolean              dont_wait,
   switch (buf[0])
     {
     case CHILD_NO_ERROR:
-      if (child_pid && dont_wait)
+      if (child_pid && dont_wait && !dont_return_handle)
        {
          /* helper is our HANDLE for gspawn-win32-helper. It has
           * told us the HANDLE of its child. Duplicate that into
@@ -830,6 +837,7 @@ do_spawn_with_pipes (gboolean              dont_wait,
     *standard_error = stderr_pipe[0];
   if (exit_status)
     *exit_status = buf[1];
+  CloseHandle ((HANDLE) helper);
   
   return TRUE;