[vte] app: Fix --no-pty mode thinko



commit 12814a1dfd33018268af10d257e96bb78bdcf5b8
Author: Christian Persch <chpe src gnome org>
Date:   Tue Mar 24 20:22:08 2020 +0100

    app: Fix --no-pty mode thinko

 src/app/app.cc | 36 ++++++++++++++----------------------
 1 file changed, 14 insertions(+), 22 deletions(-)
---
diff --git a/src/app/app.cc b/src/app/app.cc
index 4de6ce99..fb8a9d07 100644
--- a/src/app/app.cc
+++ b/src/app/app.cc
@@ -1313,29 +1313,21 @@ vteapp_window_fork(VteappWindow* window,
         return true;
 }
 
-static bool
-vteapp_window_fork_no_pty(VteappWindow* window,
-                          GError** error)
+static gboolean
+tick_cb(VteappWindow* window)
 {
-        auto pid = fork();
-        switch (pid) {
-        case -1: /* error */
-                g_set_error(error, G_IO_ERROR, G_IO_ERROR_FAILED, "Error forking: %m");
-                return false;
-
-        case 0: /* child */ {
-                for (auto i = 0; ; i++) {
-                        char buf[256];
-                        auto s = g_snprintf(buf, sizeof(buf), "%d\n", i);
-                        vte_terminal_feed(window->terminal, buf, s);
-                        g_usleep(G_USEC_PER_SEC);
-                }
-        }
-        default: /* parent */
-                verbose_print("Child PID is %d (mine is %d).\n", (int)pid, (int)getpid());
-                break;
-        }
+        static int i = 0;
+        char buf[256];
+        auto s = g_snprintf(buf, sizeof(buf), "%d\r\n", i++);
+        vte_terminal_feed(window->terminal, buf, s);
+        return G_SOURCE_CONTINUE;
+}
 
+static bool
+vteapp_window_tick(VteappWindow* window,
+                   GError** error)
+{
+        g_timeout_add_seconds(1, (GSourceFunc) tick_cb, window);
         return true;
 }
 
@@ -1354,7 +1346,7 @@ vteapp_window_launch(VteappWindow* window)
         else if (!options.no_pty)
                 rv = vteapp_window_fork(window, error);
         else
-                rv = vteapp_window_fork_no_pty(window, error);
+                rv = vteapp_window_tick(window, error);
 
         if (!rv)
                 verbose_printerr("Error launching: %s\n", error.message());


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