]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - src/seat-unity.c
In the unity seat, if we don't have proper VT support, fake VT 0 instead of a real...
[sojka/lightdm.git] / src / seat-unity.c
1 /*
2  * Copyright (C) 2012-2013 Robert Ancell.
3  * Author: Robert Ancell <robert.ancell@canonical.com>
4  *
5  * This program is free software: you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License as published by the Free Software
7  * Foundation, either version 3 of the License, or (at your option) any later
8  * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
9  * license.
10  */
11
12 #include <string.h>
13 #include <fcntl.h>
14 #include <errno.h>
15 #include <glib/gstdio.h>
16
17 #include "seat-unity.h"
18 #include "configuration.h"
19 #include "x-server-local.h"
20 #include "mir-server.h"
21 #include "vt.h"
22 #include "plymouth.h"
23
24 typedef enum
25 {
26    USC_MESSAGE_PING = 0,
27    USC_MESSAGE_PONG = 1,
28    USC_MESSAGE_READY = 2,
29    USC_MESSAGE_SESSION_CONNECTED = 3,
30    USC_MESSAGE_SET_ACTIVE_SESSION = 4,
31    USC_MESSAGE_SET_NEXT_SESSION = 5,
32 } USCMessageID;
33
34 struct SeatUnityPrivate
35 {
36     /* VT we are running on */
37     gint vt;
38
39     /* File to log to */
40     gchar *log_file;
41
42     /* Filename of Mir socket */
43     gchar *mir_socket_filename;
44
45     /* Pipes to communicate with compositor */
46     int to_compositor_pipe[2];
47     int from_compositor_pipe[2];
48
49     /* IO channel listening on for messages from the compositor */
50     GIOChannel *from_compositor_channel;
51     guint from_compositor_watch;
52
53     /* TRUE when the compositor indicates it is ready */
54     gboolean compositor_ready;
55
56     /* Buffer reading from channel */
57     guint8 *read_buffer;
58     gsize read_buffer_length;
59     gsize read_buffer_n_used;
60
61     /* Compositor process */
62     Process *compositor_process;
63
64     /* Timeout when waiting for compositor to start */
65     guint compositor_timeout;
66
67     /* Next Mir ID to use for a Mir sessions, X server and greeters */
68     gint next_session_id;
69     gint next_x_server_id;
70     gint next_greeter_id;
71
72     /* The currently visible session */
73     Session *active_session;
74     DisplayServer *active_display_server;
75 };
76
77 G_DEFINE_TYPE (SeatUnity, seat_unity, SEAT_TYPE);
78
79 static gboolean
80 seat_unity_get_start_local_sessions (Seat *seat)
81 {
82     return !seat_get_string_property (seat, "xdmcp-manager");
83 }
84
85 static void
86 seat_unity_setup (Seat *seat)
87 {
88     seat_set_can_switch (seat, TRUE);
89     SEAT_CLASS (seat_unity_parent_class)->setup (seat);
90 }
91
92 static void
93 compositor_stopped_cb (Process *process, SeatUnity *seat)
94 {
95     if (seat->priv->compositor_timeout != 0)
96         g_source_remove (seat->priv->compositor_timeout);
97     seat->priv->compositor_timeout = 0;
98
99     /* Finished with the VT */
100     vt_unref (seat->priv->vt);
101     seat->priv->vt = -1;
102
103     if (seat_get_is_stopping (SEAT (seat)))
104     {
105         SEAT_CLASS (seat_unity_parent_class)->stop (SEAT (seat));
106         return;
107     }
108
109     l_debug (seat, "Stopping Unity seat, compositor terminated");
110
111     seat_stop (SEAT (seat));
112 }
113
114 static void
115 compositor_run_cb (Process *process, SeatUnity *seat)
116 {
117     int fd;
118
119     /* Make input non-blocking */
120     fd = open ("/dev/null", O_RDONLY);
121     dup2 (fd, STDIN_FILENO);
122     close (fd);
123
124     /* Redirect output to logfile */
125     if (seat->priv->log_file)
126     {
127          int fd;
128          gchar *old_filename;
129
130          /* Move old file out of the way */
131          old_filename = g_strdup_printf ("%s.old", seat->priv->log_file);
132          rename (seat->priv->log_file, old_filename);
133          g_free (old_filename);
134
135          /* Create new file and log to it */
136          fd = g_open (seat->priv->log_file, O_WRONLY | O_CREAT | O_TRUNC, 0600);
137          if (fd < 0)
138              l_warning (seat, "Failed to open log file %s: %s", seat->priv->log_file, g_strerror (errno));
139          else
140          {
141              dup2 (fd, STDOUT_FILENO);
142              dup2 (fd, STDERR_FILENO);
143              close (fd);
144          }
145     }
146 }
147
148 static void
149 write_message (SeatUnity *seat, guint16 id, const guint8 *payload, guint16 payload_length)
150 {
151     guint8 *data;
152     gsize data_length = 4 + payload_length;
153
154     data = g_malloc (data_length);
155     data[0] = id >> 8;
156     data[1] = id & 0xFF;
157     data[2] = payload_length >> 8;
158     data[3] = payload_length & 0xFF;
159     memcpy (data + 4, payload, payload_length);
160
161     errno = 0;
162     if (write (seat->priv->to_compositor_pipe[1], data, data_length) != data_length)
163         l_warning (seat, "Failed to write to compositor: %s", strerror (errno));
164 }
165
166 static gboolean
167 read_cb (GIOChannel *source, GIOCondition condition, gpointer data)
168 {
169     SeatUnity *seat = data;
170     gsize n_to_read = 0;
171     guint16 id, payload_length;
172     /*guint8 *payload;*/
173   
174     if (condition == G_IO_HUP)
175     {
176         l_debug (seat, "Compositor closed communication channel");
177         return FALSE;
178     }
179
180     /* Work out how much required for a message */
181     if (seat->priv->read_buffer_n_used < 4)
182         n_to_read = 4 - seat->priv->read_buffer_n_used;
183     else
184     {
185         payload_length = seat->priv->read_buffer[2] << 8 | seat->priv->read_buffer[3];
186         n_to_read = 4 + payload_length - seat->priv->read_buffer_n_used;
187     }
188
189     /* Read from compositor */
190     if (n_to_read > 0)
191     {
192         gsize n_total, n_read = 0;
193         GIOStatus status;
194         GError *error = NULL;
195
196         n_total = seat->priv->read_buffer_n_used + n_to_read;
197         if (seat->priv->read_buffer_length < n_total)
198             seat->priv->read_buffer = g_realloc (seat->priv->read_buffer, n_total);
199
200         status = g_io_channel_read_chars (source,
201                                           (gchar *)seat->priv->read_buffer + seat->priv->read_buffer_n_used,
202                                           n_to_read,
203                                           &n_read,
204                                           &error);
205         if (error)
206             l_warning (seat, "Failed to read from compositor: %s", error->message);
207         if (status != G_IO_STATUS_NORMAL)
208             return TRUE;
209         g_clear_error (&error);
210         seat->priv->read_buffer_n_used += n_read;
211     }
212
213     /* Read header */
214     if (seat->priv->read_buffer_n_used < 4)
215          return TRUE;
216     id = seat->priv->read_buffer[0] << 8 | seat->priv->read_buffer[1];
217     payload_length = seat->priv->read_buffer[2] << 8 | seat->priv->read_buffer[3];
218
219     /* Read payload */
220     if (seat->priv->read_buffer_n_used < 4 + payload_length)
221         return TRUE;
222     /*payload = seat->priv->read_buffer + 4;*/
223
224     switch (id)
225     {
226     case USC_MESSAGE_PING:
227         l_debug (seat, "PING!");
228         write_message (seat, USC_MESSAGE_PONG, NULL, 0);
229         break;
230     case USC_MESSAGE_PONG:
231         l_debug (seat, "PONG!");
232         break;
233     case USC_MESSAGE_READY:
234         l_debug (seat, "READY");
235         if (!seat->priv->compositor_ready)
236         {
237             seat->priv->compositor_ready = TRUE;
238             l_debug (seat, "Compositor ready");
239             g_source_remove (seat->priv->compositor_timeout);
240             seat->priv->compositor_timeout = 0;
241             SEAT_CLASS (seat_unity_parent_class)->start (SEAT (seat));
242         }
243         break;
244     case USC_MESSAGE_SESSION_CONNECTED:
245         l_debug (seat, "SESSION CONNECTED");
246         break;
247     default:
248         l_warning (seat, "Ignoring unknown message %d with %d octets from system compositor", id, payload_length);
249         break;
250     }
251
252     /* Clear buffer */
253     seat->priv->read_buffer_n_used = 0;
254
255     return TRUE;
256 }
257
258 static gchar *
259 get_absolute_command (const gchar *command)
260 {
261     gchar **tokens;
262     gchar *absolute_binary, *absolute_command = NULL;
263
264     tokens = g_strsplit (command, " ", 2);
265
266     absolute_binary = g_find_program_in_path (tokens[0]);
267     if (absolute_binary)
268     {
269         if (tokens[1])
270             absolute_command = g_strjoin (" ", absolute_binary, tokens[1], NULL);
271         else
272             absolute_command = g_strdup (absolute_binary);
273         g_free (absolute_binary);
274     }
275     else
276         absolute_command = g_strdup (command);
277
278     g_strfreev (tokens);
279
280     return absolute_command;
281 }
282
283 static gboolean
284 compositor_timeout_cb (gpointer data)
285 {
286     SeatUnity *seat = data;
287
288     /* Stop the compositor - it is not working */
289     process_stop (seat->priv->compositor_process);
290
291     return TRUE;
292 }
293
294 static gboolean
295 seat_unity_start (Seat *seat)
296 {
297     const gchar *compositor_command;
298     gchar *command, *absolute_command, *dir, *value;
299     gboolean result;
300     int timeout;
301
302     /* Replace Plymouth if it is running */
303     if (plymouth_get_is_active () && plymouth_has_active_vt ())
304     {
305         gint active_vt = vt_get_active ();
306         if (active_vt >= vt_get_min ())
307         {
308             SEAT_UNITY (seat)->priv->vt = active_vt;
309             plymouth_quit (TRUE);
310         }
311         else
312             l_debug (seat, "Plymouth is running on VT %d, but this is less than the configured minimum of %d so not replacing it", active_vt, vt_get_min ());
313     }
314     if (plymouth_get_is_active ())
315         plymouth_quit (FALSE);
316     if (SEAT_UNITY (seat)->priv->vt < 0)
317         SEAT_UNITY (seat)->priv->vt = vt_can_multi_seat () ? vt_get_unused () : 0;
318     if (SEAT_UNITY (seat)->priv->vt < 0)
319     {
320         l_debug (seat, "Failed to get a VT to run on");
321         return FALSE;
322     }
323     vt_ref (SEAT_UNITY (seat)->priv->vt);
324
325     /* Create pipes to talk to compositor */
326     if (pipe (SEAT_UNITY (seat)->priv->to_compositor_pipe) < 0 || pipe (SEAT_UNITY (seat)->priv->from_compositor_pipe) < 0)
327     {
328         l_debug (seat, "Failed to create compositor pipes: %s", g_strerror (errno));
329         return FALSE;
330     }
331
332     /* Don't allow the daemon end of the pipes to be accessed in the compositor */
333     fcntl (SEAT_UNITY (seat)->priv->to_compositor_pipe[1], F_SETFD, FD_CLOEXEC);
334     fcntl (SEAT_UNITY (seat)->priv->from_compositor_pipe[0], F_SETFD, FD_CLOEXEC);
335
336     /* Listen for messages from the compositor */
337     SEAT_UNITY (seat)->priv->from_compositor_channel = g_io_channel_unix_new (SEAT_UNITY (seat)->priv->from_compositor_pipe[0]);
338     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);
339
340     /* Setup logging */
341     dir = config_get_string (config_get_instance (), "LightDM", "log-directory");
342     SEAT_UNITY (seat)->priv->log_file = g_build_filename (dir, "unity-system-compositor.log", NULL);
343     l_debug (seat, "Logging to %s", SEAT_UNITY (seat)->priv->log_file);
344     g_free (dir);
345
346     /* Setup environment */
347     process_set_clear_environment (SEAT_UNITY (seat)->priv->compositor_process, TRUE);
348     process_set_env (SEAT_UNITY (seat)->priv->compositor_process, "XDG_SEAT", "seat0");
349     value = g_strdup_printf ("%d", SEAT_UNITY (seat)->priv->vt);
350     process_set_env (SEAT_UNITY (seat)->priv->compositor_process, "XDG_VTNR", value);
351     g_free (value);
352     /* Variable required for regression tests */
353     if (g_getenv ("LIGHTDM_TEST_ROOT"))
354     {
355         process_set_env (SEAT_UNITY (seat)->priv->compositor_process, "LIGHTDM_TEST_ROOT", g_getenv ("LIGHTDM_TEST_ROOT"));
356         process_set_env (SEAT_UNITY (seat)->priv->compositor_process, "LD_PRELOAD", g_getenv ("LD_PRELOAD"));
357         process_set_env (SEAT_UNITY (seat)->priv->compositor_process, "LD_LIBRARY_PATH", g_getenv ("LD_LIBRARY_PATH"));
358     }
359
360     SEAT_UNITY (seat)->priv->mir_socket_filename = g_strdup ("/tmp/mir_socket"); // FIXME: Use this socket by default as XMir is hardcoded to this
361     timeout = seat_get_integer_property (seat, "unity-compositor-timeout");
362     compositor_command = seat_get_string_property (seat, "unity-compositor-command");
363     command = g_strdup_printf ("%s --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);
364
365     absolute_command = get_absolute_command (command);
366     g_free (command);
367
368     /* Start the compositor */
369     process_set_command (SEAT_UNITY (seat)->priv->compositor_process, absolute_command);
370     g_free (absolute_command);
371     g_signal_connect (SEAT_UNITY (seat)->priv->compositor_process, "stopped", G_CALLBACK (compositor_stopped_cb), seat);
372     g_signal_connect (SEAT_UNITY (seat)->priv->compositor_process, "run", G_CALLBACK (compositor_run_cb), seat);
373     result = process_start (SEAT_UNITY (seat)->priv->compositor_process, FALSE);
374
375     /* Close compostor ends of the pipes */
376     close (SEAT_UNITY (seat)->priv->to_compositor_pipe[0]);
377     SEAT_UNITY (seat)->priv->to_compositor_pipe[0] = 0;
378     close (SEAT_UNITY (seat)->priv->from_compositor_pipe[1]);
379     SEAT_UNITY (seat)->priv->from_compositor_pipe[1] = 0;
380
381     if (!result)
382         return FALSE;
383
384     /* Connect to the compositor */
385     timeout = seat_get_integer_property (seat, "unity-compositor-timeout");
386     if (timeout <= 0)
387         timeout = 60;
388     l_debug (seat, "Waiting for system compositor for %ds", timeout);
389     SEAT_UNITY (seat)->priv->compositor_timeout = g_timeout_add (timeout * 1000, compositor_timeout_cb, seat);
390
391     return TRUE;
392 }
393
394 static DisplayServer *
395 create_x_server (Seat *seat)
396 {
397     XServerLocal *x_server;
398     const gchar *command = NULL, *layout = NULL, *config_file = NULL, *xdmcp_manager = NULL, *key_name = NULL, *xdg_seat = NULL;
399     gboolean allow_tcp;
400     gint port = 0;
401     gchar *id;
402
403     l_debug (seat, "Starting X server on Unity compositor");
404
405     x_server = x_server_local_new ();
406
407     command = seat_get_string_property (seat, "xserver-command");
408     if (command)
409         x_server_local_set_command (x_server, command);
410
411     id = g_strdup_printf ("x-%d", SEAT_UNITY (seat)->priv->next_x_server_id);
412     SEAT_UNITY (seat)->priv->next_x_server_id++;
413     x_server_local_set_mir_id (x_server, id);
414     x_server_local_set_mir_socket (x_server, SEAT_UNITY (seat)->priv->mir_socket_filename);
415     g_free (id);
416
417     layout = seat_get_string_property (seat, "xserver-layout");
418     if (layout)
419         x_server_local_set_layout (x_server, layout);
420     
421     xdg_seat = seat_get_string_property (seat, "xdg-seat");
422     if (xdg_seat)
423         x_server_local_set_xdg_seat (x_server, xdg_seat);
424
425     config_file = seat_get_string_property (seat, "xserver-config");
426     if (config_file)
427         x_server_local_set_config (x_server, config_file);
428
429     allow_tcp = seat_get_boolean_property (seat, "xserver-allow-tcp");
430     x_server_local_set_allow_tcp (x_server, allow_tcp);
431
432     xdmcp_manager = seat_get_string_property (seat, "xdmcp-manager");
433     if (xdmcp_manager)
434         x_server_local_set_xdmcp_server (x_server, xdmcp_manager);
435
436     port = seat_get_integer_property (seat, "xdmcp-port");
437     if (port > 0)
438         x_server_local_set_xdmcp_port (x_server, port);
439
440     key_name = seat_get_string_property (seat, "xdmcp-key");
441     if (key_name)
442     {
443         gchar *dir, *path;
444         GKeyFile *keys;
445         gboolean result;
446         GError *error = NULL;
447
448         dir = config_get_string (config_get_instance (), "LightDM", "config-directory");
449         path = g_build_filename (dir, "keys.conf", NULL);
450         g_free (dir);
451
452         keys = g_key_file_new ();
453         result = g_key_file_load_from_file (keys, path, G_KEY_FILE_NONE, &error);
454         if (error)
455             l_debug (seat, "Error getting key %s", error->message);
456         g_clear_error (&error);
457
458         if (result)
459         {
460             gchar *key = NULL;
461
462             if (g_key_file_has_key (keys, "keyring", key_name, NULL))
463                 key = g_key_file_get_string (keys, "keyring", key_name, NULL);
464             else
465                 l_debug (seat, "Key %s not defined", key_name);
466
467             if (key)
468                 x_server_local_set_xdmcp_key (x_server, key);
469             g_free (key);
470         }
471
472         g_free (path);
473         g_key_file_free (keys);
474     }
475
476     return DISPLAY_SERVER (x_server);
477 }
478
479 static DisplayServer *
480 create_mir_server (Seat *seat)
481 {
482     MirServer *mir_server;
483
484     mir_server = mir_server_new ();
485     mir_server_set_parent_socket (mir_server, SEAT_UNITY (seat)->priv->mir_socket_filename);
486
487     return DISPLAY_SERVER (mir_server);
488 }
489
490 static DisplayServer *
491 seat_unity_create_display_server (Seat *seat, const gchar *session_type)
492 {  
493     if (strcmp (session_type, "x") == 0)
494         return create_x_server (seat);
495     else if (strcmp (session_type, "mir") == 0)
496         return create_mir_server (seat);
497     else
498     {
499         l_warning (seat, "Can't create unsupported display server '%s'", session_type);
500         return NULL;
501     }
502 }
503
504 static Greeter *
505 seat_unity_create_greeter_session (Seat *seat)
506 {
507     Greeter *greeter_session;
508     const gchar *xdg_seat;
509     gchar *id;
510     gint vt;
511
512     greeter_session = SEAT_CLASS (seat_unity_parent_class)->create_greeter_session (seat);
513     xdg_seat = seat_get_string_property (seat, "xdg-seat");
514     if (!xdg_seat)
515         xdg_seat = "seat0";
516     l_debug (seat, "Setting XDG_SEAT=%s", xdg_seat);
517     session_set_env (SESSION (greeter_session), "XDG_SEAT", xdg_seat);
518
519     id = g_strdup_printf ("greeter-%d", SEAT_UNITY (seat)->priv->next_greeter_id);
520     SEAT_UNITY (seat)->priv->next_greeter_id++;
521     session_set_env (SESSION (greeter_session), "MIR_SERVER_NAME", id);
522     g_free (id);
523
524     vt = SEAT_UNITY (seat)->priv->vt;
525     if (vt >= 0)
526     {
527         gchar *value = g_strdup_printf ("%d", vt);
528         l_debug (seat, "Setting XDG_VTNR=%s", value);
529         session_set_env (SESSION (greeter_session), "XDG_VTNR", value);
530         g_free (value);
531     }
532     else
533         l_debug (seat, "Not setting XDG_VTNR");
534
535     return greeter_session;
536 }
537
538 static Session *
539 seat_unity_create_session (Seat *seat)
540 {
541     Session *session;
542     const gchar *xdg_seat;
543     gchar *id;
544     gint vt;
545
546     session = SEAT_CLASS (seat_unity_parent_class)->create_session (seat);
547     xdg_seat = seat_get_string_property (seat, "xdg-seat");
548     if (!xdg_seat)
549         xdg_seat = "seat0";
550     l_debug (seat, "Setting XDG_SEAT=%s", xdg_seat);
551     session_set_env (session, "XDG_SEAT", xdg_seat);
552
553     id = g_strdup_printf ("session-%d", SEAT_UNITY (seat)->priv->next_session_id);
554     SEAT_UNITY (seat)->priv->next_session_id++;
555     session_set_env (session, "MIR_SERVER_NAME", id);
556     g_free (id);
557
558     vt = SEAT_UNITY (seat)->priv->vt;
559     if (vt >= 0)
560     {
561         gchar *value = g_strdup_printf ("%d", vt);
562         l_debug (seat, "Setting XDG_VTNR=%s", value);
563         session_set_env (SESSION (session), "XDG_VTNR", value);
564         g_free (value);
565     }
566     else
567         l_debug (seat, "Not setting XDG_VTNR");
568
569     return session;
570 }
571
572 static void
573 seat_unity_set_active_session (Seat *seat, Session *session)
574 {
575     DisplayServer *display_server;
576
577     if (session == SEAT_UNITY (seat)->priv->active_session)
578         return;
579     SEAT_UNITY (seat)->priv->active_session = g_object_ref (session);
580
581     display_server = session_get_display_server (session);
582     if (SEAT_UNITY (seat)->priv->active_display_server != display_server)
583     {
584         const gchar *id = NULL;
585
586         SEAT_UNITY (seat)->priv->active_display_server = g_object_ref (display_server);
587
588         if (IS_X_SERVER_LOCAL (display_server))
589             id = x_server_local_get_mir_id (X_SERVER_LOCAL (display_server));
590         else
591             id = session_get_env (session, "MIR_SERVER_NAME");
592
593         if (id)
594         {
595             l_debug (seat, "Switching to Mir session %s", id);
596             write_message (SEAT_UNITY (seat), USC_MESSAGE_SET_ACTIVE_SESSION, (const guint8 *) id, strlen (id));
597         }
598         else
599             l_warning (seat, "Failed to work out session ID");
600     }
601
602     SEAT_CLASS (seat_unity_parent_class)->set_active_session (seat, session);
603 }
604
605 static Session *
606 seat_unity_get_active_session (Seat *seat)
607 {
608     return SEAT_UNITY (seat)->priv->active_session;
609 }
610
611 static void
612 seat_unity_set_next_session (Seat *seat, Session *session)
613 {
614     DisplayServer *display_server;
615     const gchar *id = NULL;
616
617     if (!session)
618         return;
619
620     display_server = session_get_display_server (session);
621
622     if (IS_X_SERVER_LOCAL (display_server))
623         id = x_server_local_get_mir_id (X_SERVER_LOCAL (display_server));
624     else
625         id = session_get_env (session, "MIR_SERVER_NAME");
626
627     if (id)
628     {
629         l_debug (seat, "Marking Mir session %s as the next session", id);
630         write_message (SEAT_UNITY (seat), USC_MESSAGE_SET_NEXT_SESSION, (const guint8 *) id, strlen (id));
631     }
632     else
633     {
634         l_debug (seat, "Failed to work out session ID to mark");
635     }
636
637     SEAT_CLASS (seat_unity_parent_class)->set_next_session (seat, session);
638 }
639
640 static void
641 seat_unity_run_script (Seat *seat, DisplayServer *display_server, Process *script)
642 {
643     const gchar *path;
644     XServerLocal *x_server;
645
646     x_server = X_SERVER_LOCAL (display_server);
647     path = x_server_local_get_authority_file_path (x_server);
648     process_set_env (script, "DISPLAY", x_server_get_address (X_SERVER (x_server)));
649     process_set_env (script, "XAUTHORITY", path);
650
651     SEAT_CLASS (seat_unity_parent_class)->run_script (seat, display_server, script);
652 }
653
654 static void
655 seat_unity_stop (Seat *seat)
656 {
657     /* Stop the compositor first */
658     if (process_get_is_running (SEAT_UNITY (seat)->priv->compositor_process))
659     {
660         process_stop (SEAT_UNITY (seat)->priv->compositor_process);
661         return;
662     }
663
664     SEAT_CLASS (seat_unity_parent_class)->stop (seat);
665 }
666
667 static void
668 seat_unity_init (SeatUnity *seat)
669 {
670     seat->priv = G_TYPE_INSTANCE_GET_PRIVATE (seat, SEAT_UNITY_TYPE, SeatUnityPrivate);
671     seat->priv->vt = -1;
672     seat->priv->compositor_process = process_new ();
673 }
674
675 static void
676 seat_unity_finalize (GObject *object)
677 {
678     SeatUnity *seat = SEAT_UNITY (object);
679
680     if (seat->priv->vt >= 0)
681         vt_unref (seat->priv->vt);
682     g_free (seat->priv->log_file);
683     g_free (seat->priv->mir_socket_filename);
684     close (seat->priv->to_compositor_pipe[0]);
685     close (seat->priv->to_compositor_pipe[1]);
686     close (seat->priv->from_compositor_pipe[0]);
687     close (seat->priv->from_compositor_pipe[1]);
688     g_io_channel_unref (seat->priv->from_compositor_channel);
689     g_source_remove (seat->priv->from_compositor_watch);
690     g_free (seat->priv->read_buffer);
691     g_object_unref (seat->priv->compositor_process);
692     if (seat->priv->active_session)
693         g_object_unref (seat->priv->active_session);
694     if (seat->priv->active_display_server)
695         g_object_unref (seat->priv->active_display_server);
696
697     G_OBJECT_CLASS (seat_unity_parent_class)->finalize (object);
698 }
699
700 static void
701 seat_unity_class_init (SeatUnityClass *klass)
702 {
703     GObjectClass *object_class = G_OBJECT_CLASS (klass);
704     SeatClass *seat_class = SEAT_CLASS (klass);
705
706     object_class->finalize = seat_unity_finalize;
707     seat_class->get_start_local_sessions = seat_unity_get_start_local_sessions;
708     seat_class->setup = seat_unity_setup;
709     seat_class->start = seat_unity_start;
710     seat_class->create_display_server = seat_unity_create_display_server;
711     seat_class->create_greeter_session = seat_unity_create_greeter_session;
712     seat_class->create_session = seat_unity_create_session;
713     seat_class->set_active_session = seat_unity_set_active_session;
714     seat_class->get_active_session = seat_unity_get_active_session;
715     seat_class->set_next_session = seat_unity_set_next_session;
716     seat_class->run_script = seat_unity_run_script;
717     seat_class->stop = seat_unity_stop;
718
719     g_type_class_add_private (klass, sizeof (SeatUnityPrivate));
720 }