[mutter/wip/wayland-kms: 687/697] MetaWayland: redirect stdin/stdout/stderr when running on bare metal



commit 6add80ce5d6f2484a33254dc66dec84353b73e35
Author: Giovanni Campagna <gcampagn redhat com>
Date:   Fri Aug 9 17:56:24 2013 +0200

    MetaWayland: redirect stdin/stdout/stderr when running on bare metal
    
    We need to spawn background processes for gnome-session and friends,
    so we need to make sure they don't try to read or write from our
    terminal.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=705861

 src/wayland/meta-wayland.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
---
diff --git a/src/wayland/meta-wayland.c b/src/wayland/meta-wayland.c
index 01ad437..79dad8d 100644
--- a/src/wayland/meta-wayland.c
+++ b/src/wayland/meta-wayland.c
@@ -33,6 +33,8 @@
 #include <sys/stat.h>
 #include <stdlib.h>
 #include <sys/wait.h>
+#include <fcntl.h>
+#include <unistd.h>
 
 #include <wayland-server.h>
 
@@ -1507,6 +1509,8 @@ meta_wayland_init (void)
   if (compositor->drm_fd >= 0)
     {
       GError *error;
+      char path[PATH_MAX];
+      int fd;
 
       /* Running on bare metal, let's initalize DRM master and VT handling */
       compositor->tty = meta_tty_new ();
@@ -1523,6 +1527,24 @@ meta_wayland_init (void)
          g_error ("Failed to become DRM master: %s", error->message);
          g_error_free (error);
        }
+
+      /* Open a log in the home directory. This is necessary because otherwise
+        all background processes (such as gnome-session and children) get SIGTTOU
+        trying to write to the terminal.
+
+        Then close (</dev/null) stdin, so we don't get SIGTTIN or other crazy stuff.
+      */
+      snprintf(path, PATH_MAX, "%s/gnome-wayland.log", g_get_user_cache_dir ());
+      fd = open (path, O_WRONLY | O_APPEND | O_CREAT | O_TRUNC, 0600);
+      if (fd < 0)
+       fd = open ("/dev/null", O_WRONLY | O_NOCTTY, 0600);
+
+      dup2 (fd, STDOUT_FILENO);
+      dup2 (fd, STDERR_FILENO);
+      close (fd);
+
+      fd = open ("/dev/null", O_WRONLY | O_NOCTTY, 0600);
+      dup2 (fd, STDIN_FILENO);
     }
 
   compositor->stage = meta_wayland_stage_new ();


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