]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blobdiff - src/seat-unity.c
Update environment variables that we pass to Mir.
[sojka/lightdm.git] / src / seat-unity.c
index a449aece548485ea05dad3c047db9b2d3b1969b6..e37548d85d9b6a54829be17307404c33714ef0e7 100644 (file)
@@ -27,7 +27,8 @@ typedef enum
    USC_MESSAGE_PONG = 1,
    USC_MESSAGE_READY = 2,
    USC_MESSAGE_SESSION_CONNECTED = 3,
-   USC_MESSAGE_SET_ACTIVE_SESSION = 4
+   USC_MESSAGE_SET_ACTIVE_SESSION = 4,
+   USC_MESSAGE_SET_NEXT_SESSION = 5,
 } USCMessageID;
 
 struct SeatUnityPrivate
@@ -47,6 +48,7 @@ struct SeatUnityPrivate
 
     /* IO channel listening on for messages from the compositor */
     GIOChannel *from_compositor_channel;
+    guint from_compositor_watch;
 
     /* TRUE when the compositor indicates it is ready */
     gboolean compositor_ready;
@@ -133,7 +135,14 @@ compositor_run_cb (Process *process, SeatUnity *seat)
     if (seat->priv->log_file)
     {
          int fd;
+         gchar *old_filename;
 
+         /* Move old file out of the way */
+         old_filename = g_strdup_printf ("%s.old", seat->priv->log_file);
+         rename (seat->priv->log_file, old_filename);
+         g_free (old_filename);
+
+         /* Create new file and log to it */
          fd = g_open (seat->priv->log_file, O_WRONLY | O_CREAT | O_TRUNC, 0600);
          if (fd < 0)
              l_warning (seat, "Failed to open log file %s: %s", seat->priv->log_file, g_strerror (errno));
@@ -296,7 +305,7 @@ static gboolean
 seat_unity_start (Seat *seat)
 {
     const gchar *compositor_command;
-    gchar *command, *absolute_command, *dir;
+    gchar *command, *absolute_command, *dir, *value;
     gboolean result;
     int timeout;
 
@@ -336,7 +345,7 @@ seat_unity_start (Seat *seat)
 
     /* Listen for messages from the compositor */
     SEAT_UNITY (seat)->priv->from_compositor_channel = g_io_channel_unix_new (SEAT_UNITY (seat)->priv->from_compositor_pipe[0]);
-    g_io_add_watch (SEAT_UNITY (seat)->priv->from_compositor_channel, G_IO_IN | G_IO_HUP, read_cb, seat);
+    SEAT_UNITY (seat)->priv->from_compositor_watch = g_io_add_watch (SEAT_UNITY (seat)->priv->from_compositor_channel, G_IO_IN | G_IO_HUP, read_cb, seat);
 
     /* Setup logging */
     dir = config_get_string (config_get_instance (), "LightDM", "log-directory");
@@ -344,10 +353,24 @@ seat_unity_start (Seat *seat)
     l_debug (seat, "Logging to %s", SEAT_UNITY (seat)->priv->log_file);
     g_free (dir);
 
+    /* Setup environment */
+    process_set_clear_environment (SEAT_UNITY (seat)->priv->compositor_process, TRUE);
+    process_set_env (SEAT_UNITY (seat)->priv->compositor_process, "XDG_SEAT", "seat0");
+    value = g_strdup_printf ("%d", SEAT_UNITY (seat)->priv->vt);
+    process_set_env (SEAT_UNITY (seat)->priv->compositor_process, "XDG_VTNR", value);
+    g_free (value);
+    /* Variable required for regression tests */
+    if (g_getenv ("LIGHTDM_TEST_ROOT"))
+    {
+        process_set_env (SEAT_UNITY (seat)->priv->compositor_process, "LIGHTDM_TEST_ROOT", g_getenv ("LIGHTDM_TEST_ROOT"));
+        process_set_env (SEAT_UNITY (seat)->priv->compositor_process, "LD_PRELOAD", g_getenv ("LD_PRELOAD"));
+        process_set_env (SEAT_UNITY (seat)->priv->compositor_process, "LD_LIBRARY_PATH", g_getenv ("LD_LIBRARY_PATH"));
+    }
+
     SEAT_UNITY (seat)->priv->mir_socket_filename = g_strdup ("/tmp/mir_socket"); // FIXME: Use this socket by default as XMir is hardcoded to this
     timeout = seat_get_integer_property (seat, "unity-compositor-timeout");
     compositor_command = seat_get_string_property (seat, "unity-compositor-command");
-    command = g_strdup_printf ("%s --from-dm-fd %d --to-dm-fd %d --vt %d", compositor_command, SEAT_UNITY (seat)->priv->to_compositor_pipe[0], SEAT_UNITY (seat)->priv->from_compositor_pipe[1], SEAT_UNITY (seat)->priv->vt);
+    command = g_strdup_printf ("%s --standalone --file '%s' --from-dm-fd %d --to-dm-fd %d --vt %d", compositor_command, SEAT_UNITY (seat)->priv->mir_socket_filename, SEAT_UNITY (seat)->priv->to_compositor_pipe[0], SEAT_UNITY (seat)->priv->from_compositor_pipe[1], SEAT_UNITY (seat)->priv->vt);
 
     absolute_command = get_absolute_command (command);
     g_free (command);
@@ -382,7 +405,7 @@ static DisplayServer *
 create_x_server (Seat *seat)
 {
     XServerLocal *x_server;
-    const gchar *command = NULL, *layout = NULL, *config_file = NULL, *xdmcp_manager = NULL, *key_name = NULL;
+    const gchar *command = NULL, *layout = NULL, *config_file = NULL, *xdmcp_manager = NULL, *key_name = NULL, *xdg_seat = NULL;
     gboolean allow_tcp;
     gint port = 0;
 
@@ -410,6 +433,10 @@ create_x_server (Seat *seat)
     layout = seat_get_string_property (seat, "xserver-layout");
     if (layout)
         x_server_local_set_layout (x_server, layout);
+    
+    xdg_seat = seat_get_string_property (seat, "xdg-seat");
+    if (xdg_seat)
+        x_server_local_set_xdg_seat (x_server, xdg_seat);
 
     config_file = seat_get_string_property (seat, "xserver-config");
     if (config_file)
@@ -482,7 +509,6 @@ create_mir_server (Seat *seat)
         id = g_strdup_printf ("%d", SEAT_UNITY (seat)->priv->next_id);
         SEAT_UNITY (seat)->priv->next_id++;
         mir_server_set_id (mir_server, id);
-        mir_server_set_parent_socket (mir_server, SEAT_UNITY (seat)->priv->mir_socket_filename);
         g_free (id);
     }   
 
@@ -508,14 +534,21 @@ seat_unity_create_greeter_session (Seat *seat)
 {
     Greeter *greeter_session;
     const gchar *xdg_seat;
+    gint vt = -1;
 
     greeter_session = SEAT_CLASS (seat_unity_parent_class)->create_greeter_session (seat);
-    xdg_seat = "seat0";
+    xdg_seat = seat_get_string_property (seat, "xdg-seat");
+    if (!xdg_seat)
+        xdg_seat = "seat0";
     l_debug (seat, "Setting XDG_SEAT=%s", xdg_seat);
     session_set_env (SESSION (greeter_session), "XDG_SEAT", xdg_seat);
+
     if (!SEAT_UNITY (seat)->priv->use_vt_switching)
+        vt = SEAT_UNITY (seat)->priv->vt;
+
+    if (vt >= 0)
     {
-        gchar *value = g_strdup_printf ("%d", SEAT_UNITY (seat)->priv->vt);
+        gchar *value = g_strdup_printf ("%d", vt);
         l_debug (seat, "Setting XDG_VTNR=%s", value);
         session_set_env (SESSION (greeter_session), "XDG_VTNR", value);
         g_free (value);
@@ -531,14 +564,21 @@ seat_unity_create_session (Seat *seat)
 {
     Session *session;
     const gchar *xdg_seat;
+    gint vt = -1;
 
     session = SEAT_CLASS (seat_unity_parent_class)->create_session (seat);
-    xdg_seat = "seat0";
+    xdg_seat = seat_get_string_property (seat, "xdg-seat");
+    if (!xdg_seat)
+        xdg_seat = "seat0";
     l_debug (seat, "Setting XDG_SEAT=%s", xdg_seat);
     session_set_env (session, "XDG_SEAT", xdg_seat);
+
     if (!SEAT_UNITY (seat)->priv->use_vt_switching)
+        vt = SEAT_UNITY (seat)->priv->vt;
+
+    if (vt >= 0)
     {
-        gchar *value = g_strdup_printf ("%d", SEAT_UNITY (seat)->priv->vt);
+        gchar *value = g_strdup_printf ("%d", vt);
         l_debug (seat, "Setting XDG_VTNR=%s", value);
         session_set_env (SESSION (session), "XDG_VTNR", value);
         g_free (value);
@@ -617,6 +657,39 @@ seat_unity_get_active_session (Seat *seat)
     return SEAT_UNITY (seat)->priv->active_session;
 }
 
+static void
+seat_unity_set_next_session (Seat *seat, Session *session)
+{
+    DisplayServer *display_server;
+    const gchar *id = NULL;
+
+    if (!session)
+        return;
+
+    /* If no compositor, don't worry about it */
+    if (SEAT_UNITY (seat)->priv->use_vt_switching)
+        return;
+
+    display_server = session_get_display_server (session);
+
+    if (IS_X_SERVER_LOCAL (display_server))
+        id = x_server_local_get_mir_id (X_SERVER_LOCAL (display_server));
+    else if (IS_MIR_SERVER (display_server))
+        id = mir_server_get_id (MIR_SERVER (display_server));
+
+    if (id)
+    {
+        l_debug (seat, "Marking Mir session %s as the next session", id);
+        write_message (SEAT_UNITY (seat), USC_MESSAGE_SET_NEXT_SESSION, (const guint8 *) id, strlen (id));
+    }
+    else
+    {
+        l_debug (seat, "Failed to work out session ID to mark");
+    }
+
+    SEAT_CLASS (seat_unity_parent_class)->set_next_session (seat, session);
+}
+
 static void
 seat_unity_run_script (Seat *seat, DisplayServer *display_server, Process *script)
 {
@@ -666,6 +739,7 @@ seat_unity_finalize (GObject *object)
     close (seat->priv->from_compositor_pipe[0]);
     close (seat->priv->from_compositor_pipe[1]);
     g_io_channel_unref (seat->priv->from_compositor_channel);
+    g_source_remove (seat->priv->from_compositor_watch);
     g_free (seat->priv->read_buffer);
     g_object_unref (seat->priv->compositor_process);
     if (seat->priv->active_session)
@@ -691,6 +765,7 @@ seat_unity_class_init (SeatUnityClass *klass)
     seat_class->create_session = seat_unity_create_session;
     seat_class->set_active_session = seat_unity_set_active_session;
     seat_class->get_active_session = seat_unity_get_active_session;
+    seat_class->set_next_session = seat_unity_set_next_session;
     seat_class->run_script = seat_unity_run_script;
     seat_class->stop = seat_unity_stop;