[glib: 13/15] gspawn-win32: Implement g_spawn_async_with_pipes_and_fds()




commit ea9fd4c2f24b20e55a842248d196534ea4229b80
Author: Philip Withnall <pwithnall endlessos org>
Date:   Mon Feb 15 13:35:15 2021 +0000

    gspawn-win32: Implement g_spawn_async_with_pipes_and_fds()
    
    The `source_fds`/`target_fds` functionality is not supported on Windows
    at the moment.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Fixes: #2097

 glib/gspawn-win32.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
---
diff --git a/glib/gspawn-win32.c b/glib/gspawn-win32.c
index f56a07ec7..104d5f383 100644
--- a/glib/gspawn-win32.c
+++ b/glib/gspawn-win32.c
@@ -1247,6 +1247,65 @@ g_spawn_async_with_fds (const gchar          *working_directory,
 
 }
 
+gboolean
+g_spawn_async_with_pipes_and_fds (const gchar           *working_directory,
+                                  const gchar * const   *argv,
+                                  const gchar * const   *envp,
+                                  GSpawnFlags            flags,
+                                  GSpawnChildSetupFunc   child_setup,
+                                  gpointer               user_data,
+                                  gint                   stdin_fd,
+                                  gint                   stdout_fd,
+                                  gint                   stderr_fd,
+                                  const gint            *source_fds,
+                                  const gint            *target_fds,
+                                  gsize                  n_fds,
+                                  GPid                  *child_pid_out,
+                                  gint                  *stdin_pipe_out,
+                                  gint                  *stdout_pipe_out,
+                                  gint                  *stderr_pipe_out,
+                                  GError               **error)
+{
+  g_return_val_if_fail (argv != NULL, FALSE);
+  g_return_val_if_fail (stdout_pipe_out == NULL ||
+                        !(flags & G_SPAWN_STDOUT_TO_DEV_NULL), FALSE);
+  g_return_val_if_fail (stderr_pipe_out == NULL ||
+                        !(flags & G_SPAWN_STDERR_TO_DEV_NULL), FALSE);
+  /* can't inherit stdin if we have an input pipe. */
+  g_return_val_if_fail (stdin_pipe_out == NULL ||
+                        !(flags & G_SPAWN_CHILD_INHERITS_STDIN), FALSE);
+  /* can’t use pipes and stdin/stdout/stderr FDs */
+  g_return_val_if_fail (stdin_pipe_out == NULL || stdin_fd < 0, FALSE);
+  g_return_val_if_fail (stdout_pipe_out == NULL || stdout_fd < 0, FALSE);
+  g_return_val_if_fail (stderr_pipe_out == NULL || stderr_fd < 0, FALSE);
+
+  /* source_fds/target_fds isn’t supported on Windows at the moment. */
+  if (n_fds != 0)
+    {
+      g_set_error_literal (error, G_SPAWN_ERROR, G_SPAWN_ERROR_INVAL,
+                           "FD redirection is not supported on Windows at the moment");
+      return FALSE;
+    }
+
+  return fork_exec (NULL,
+                    (flags & G_SPAWN_DO_NOT_REAP_CHILD),
+                    working_directory,
+                    argv,
+                    envp,
+                    flags,
+                    child_setup,
+                    user_data,
+                    child_pid_out,
+                    stdin_pipe_out,
+                    stdout_pipe_out,
+                    stderr_pipe_out,
+                    stdin_fd,
+                    stdout_fd,
+                    stderr_fd,
+                    NULL,
+                    error);
+}
+
 gboolean
 g_spawn_command_line_sync (const gchar  *command_line,
                            gchar       **standard_output,


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