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