[vte] spawn: Remove unused functionality



commit 280cf8160122065bd4d82f1828c33c49cfb33485
Author: Christian Persch <chpe src gnome org>
Date:   Mon Apr 27 20:49:04 2020 +0200

    spawn: Remove unused functionality
    
    Vte always connects stdin, stdout and stderr to the PTY, so
    G_SPAWN_STD{OUT,ERR}_TO_DEV_NULL and G_SPAWN_CHILD_INHERITS_STDIN
    are not supported.

 src/vtegtk.cc   | 10 +++++++++
 src/vtepty.cc   | 13 ++++++++++++
 src/vtespawn.cc | 65 +++------------------------------------------------------
 3 files changed, 26 insertions(+), 62 deletions(-)
---
diff --git a/src/vtegtk.cc b/src/vtegtk.cc
index 0838b6bc..c91bb923 100644
--- a/src/vtegtk.cc
+++ b/src/vtegtk.cc
@@ -2708,6 +2708,11 @@ vte_terminal_watch_child (VteTerminal *terminal,
  *
  * Note that %G_SPAWN_DO_NOT_REAP_CHILD will always be added to @spawn_flags.
  *
+ * Note also that %G_SPAWN_STDOUT_TO_DEV_NULL, %G_SPAWN_STDERR_TO_DEV_NULL,
+ * and %G_SPAWN_CHILD_INHERITS_STDIN are not supported in @spawn_flags, since
+ * stdin, stdout and stderr of the child process will always be connected to
+ * the PTY.
+ *
  * Note that all open file descriptors will be closed in the child. If you want
  * to keep some file descriptor open for use in the child process, you need to
  * use a child setup function that unsets the FD_CLOEXEC flag on that file
@@ -2896,6 +2901,11 @@ spawn_async_cb (GObject *source,
  * When the operation fails, @callback will be called with a -1 #GPid,
  * and a non-%NULL #GError containing the error information.
  *
+ * Note that %G_SPAWN_STDOUT_TO_DEV_NULL, %G_SPAWN_STDERR_TO_DEV_NULL,
+ * and %G_SPAWN_CHILD_INHERITS_STDIN are not supported in @spawn_flags, since
+ * stdin, stdout and stderr of the child process will always be connected to
+ * the PTY.
+ *
  * Beginning with 0.60, and on linux only, and unless %VTE_SPAWN_NO_SYSTEMD_SCOPE is
  * passed in @spawn_flags, the newly created child process will be moved to its own
  * systemd user scope; and if %VTE_SPAWN_REQUIRE_SYSTEMD_SCOPE is passed, and creation
diff --git a/src/vtepty.cc b/src/vtepty.cc
index ec2a0d28..a056ce25 100644
--- a/src/vtepty.cc
+++ b/src/vtepty.cc
@@ -162,6 +162,10 @@ vte_pty_child_setup (VtePty *pty)
  * Note that the %G_SPAWN_LEAVE_DESCRIPTORS_OPEN flag is not supported;
  * it will be cleared!
  *
+ * Note also that %G_SPAWN_STDOUT_TO_DEV_NULL, %G_SPAWN_STDERR_TO_DEV_NULL,
+ * and %G_SPAWN_CHILD_INHERITS_STDIN are not supported, since stdin, stdout
+ * and stderr of the child process will always be connected to the PTY.
+ *
  * If spawning the command in @working_directory fails because the child
  * is unable to chdir() to it, falls back trying to spawn the command
  * in the parent's working directory.
@@ -512,6 +516,10 @@ vte_pty_error_quark(void)
  *
  * Also, you MUST pass the %G_SPAWN_DO_NOT_REAP_CHILD flag.
  *
+ * Note also that %G_SPAWN_STDOUT_TO_DEV_NULL, %G_SPAWN_STDERR_TO_DEV_NULL,
+ * and %G_SPAWN_CHILD_INHERITS_STDIN are not supported, since stdin, stdout
+ * and stderr of the child process will always be connected to the PTY.
+ *
  * Note that you should set the PTY's size using vte_pty_set_size() before
  * spawning the child process, so that the child process has the correct
  * size from the start instead of starting with a default size and then
@@ -680,6 +688,11 @@ async_spawn_run_in_thread(GTask *task,
  *
  * Note that %G_SPAWN_DO_NOT_REAP_CHILD will always be added to @spawn_flags.
  *
+ * Note also that %G_SPAWN_STDOUT_TO_DEV_NULL, %G_SPAWN_STDERR_TO_DEV_NULL,
+ * and %G_SPAWN_CHILD_INHERITS_STDIN are not supported in @spawn_flags, since
+ * stdin, stdout and stderr of the child process will always be connected to
+ * the PTY.
+ *
  * Note that all open file descriptors will be closed in the child. If you want
  * to keep some file descriptor open for use in the child process, you need to
  * use a child setup function that unsets the FD_CLOEXEC flag on that file
diff --git a/src/vtespawn.cc b/src/vtespawn.cc
index 83774094..42768377 100644
--- a/src/vtespawn.cc
+++ b/src/vtespawn.cc
@@ -82,9 +82,6 @@ static gboolean fork_exec (gboolean              intermediate_child,
                            gboolean              close_descriptors,
                            gboolean              search_path,
                            gboolean              search_path_from_envp,
-                           gboolean              stdout_to_null,
-                           gboolean              stderr_to_null,
-                           gboolean              child_inherits_stdin,
                            gboolean              file_and_argv_zero,
                            gboolean              cloexec_pipes,
                            GSpawnChildSetupFunc  child_setup,
@@ -151,15 +148,9 @@ vte_spawn_async_cancellable (const gchar          *working_directory,
                              GError              **error)
 {
   g_return_val_if_fail (argv != NULL, FALSE);
-#if 0
-  g_return_val_if_fail (standard_output == NULL ||
-                        !(flags & G_SPAWN_STDOUT_TO_DEV_NULL), FALSE);
-  g_return_val_if_fail (standard_error == NULL ||
-                        !(flags & G_SPAWN_STDERR_TO_DEV_NULL), FALSE);
-  /* can't inherit stdin if we have an input pipe. */
-  g_return_val_if_fail (standard_input == NULL ||
-                        !(flags & G_SPAWN_CHILD_INHERITS_STDIN), FALSE);
-#endif
+  g_return_val_if_fail ((flags & (G_SPAWN_STDOUT_TO_DEV_NULL |
+                                  G_SPAWN_STDERR_TO_DEV_NULL |
+                                  G_SPAWN_CHILD_INHERITS_STDIN)) == 0, FALSE);
 
   return fork_exec (!(flags & G_SPAWN_DO_NOT_REAP_CHILD),
                     working_directory,
@@ -168,9 +159,6 @@ vte_spawn_async_cancellable (const gchar          *working_directory,
                     !(flags & G_SPAWN_LEAVE_DESCRIPTORS_OPEN),
                     (flags & G_SPAWN_SEARCH_PATH) != 0,
                     (flags & G_SPAWN_SEARCH_PATH_FROM_ENVP) != 0,
-                    (flags & G_SPAWN_STDOUT_TO_DEV_NULL) != 0,
-                    (flags & G_SPAWN_STDERR_TO_DEV_NULL) != 0,
-                    (flags & G_SPAWN_CHILD_INHERITS_STDIN) != 0,
                     (flags & G_SPAWN_FILE_AND_ARGV_ZERO) != 0,
                     (flags & G_SPAWN_CLOEXEC_PIPES) != 0,
                     child_setup,
@@ -509,18 +497,6 @@ sane_dup2 (gint fd1, gint fd2)
   return ret;
 }
 
-static gint
-sane_open (const char *path, gint mode)
-{
-  gint ret;
-
-  do
-    ret = open (path, mode);
-  while (ret < 0 && errno == EINTR);
-
-  return ret;
-}
-
 enum
 {
   CHILD_CHDIR_FAILED,
@@ -537,9 +513,6 @@ do_exec (gint                  child_err_report_fd,
          gboolean              close_descriptors,
          gboolean              search_path,
          gboolean              search_path_from_envp,
-         gboolean              stdout_to_null,
-         gboolean              stderr_to_null,
-         gboolean              child_inherits_stdin,
          gboolean              file_and_argv_zero,
          GSpawnChildSetupFunc  child_setup,
          gpointer              user_data)
@@ -548,32 +521,6 @@ do_exec (gint                  child_err_report_fd,
     write_err_and_exit (child_err_report_fd,
                         CHILD_CHDIR_FAILED);
 
-  /* Redirect pipes as required */
-
-  if (!child_inherits_stdin)
-    {
-      /* Keep process from blocking on a read of stdin */
-      gint read_null = open ("/dev/null", O_RDONLY);
-      g_assert (read_null != -1);
-      sane_dup2 (read_null, 0);
-      close_and_invalidate (&read_null);
-    }
-
-  if (stdout_to_null)
-    {
-      gint write_null = sane_open ("/dev/null", O_WRONLY);
-      g_assert (write_null != -1);
-      sane_dup2 (write_null, 1);
-      close_and_invalidate (&write_null);
-    }
-
-  if (stderr_to_null)
-    {
-      gint write_null = sane_open ("/dev/null", O_WRONLY);
-      sane_dup2 (write_null, 2);
-      close_and_invalidate (&write_null);
-    }
-
   /* Close all file descriptors but stdin, stdout and stderr
    * before we exec. Note that this includes
    * child_err_report_fd, which keeps the parent from blocking
@@ -747,9 +694,6 @@ fork_exec (gboolean              intermediate_child,
            gboolean              close_descriptors,
            gboolean              search_path,
            gboolean              search_path_from_envp,
-           gboolean              stdout_to_null,
-           gboolean              stderr_to_null,
-           gboolean              child_inherits_stdin,
            gboolean              file_and_argv_zero,
            gboolean              cloexec_pipes,
            GSpawnChildSetupFunc  child_setup,
@@ -814,9 +758,6 @@ fork_exec (gboolean              intermediate_child,
                close_descriptors,
                search_path,
                search_path_from_envp,
-               stdout_to_null,
-               stderr_to_null,
-               child_inherits_stdin,
                file_and_argv_zero,
                child_setup,
                user_data);


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