]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - src/seat.c
Always create sessions before display servers as some display servers will start...
[sojka/lightdm.git] / src / seat.c
1 /*
2  * Copyright (C) 2010-2011 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 <stdlib.h>
13 #include <string.h>
14 #include <sys/wait.h>
15
16 #include "seat.h"
17 #include "configuration.h"
18 #include "guest-account.h"
19 #include "greeter.h"
20 #include "session-config.h"
21
22 enum {
23     SESSION_ADDED,
24     RUNNING_USER_SESSION,
25     SESSION_REMOVED,
26     STOPPED,
27     LAST_SIGNAL
28 };
29 static guint signals[LAST_SIGNAL] = { 0 };
30
31 struct SeatPrivate
32 {
33     /* Configuration for this seat */
34     GHashTable *properties;
35
36     /* TRUE if able to switch users */
37     gboolean can_switch;
38
39     /* TRUE if display server can be shared for sessions */
40     gboolean share_display_server;
41
42     /* The display servers on this seat */
43     GList *display_servers;
44
45     /* The sessions on this seat */
46     GList *sessions;
47
48     /* The session to set active when it starts */
49     Session *session_to_activate;
50
51     /* TRUE if stopping this seat (waiting for displays to stop) */
52     gboolean stopping;
53
54     /* TRUE if stopped */
55     gboolean stopped;
56 };
57
58 /* PAM services to use */
59 #define GREETER_SERVICE   "lightdm-greeter"
60 #define USER_SERVICE      "lightdm"
61 #define AUTOLOGIN_SERVICE "lightdm-autologin"
62
63 G_DEFINE_TYPE (Seat, seat, G_TYPE_OBJECT);
64
65 typedef struct
66 {
67     const gchar *name;
68     GType type;
69 } SeatModule;
70 static GHashTable *seat_modules = NULL;
71
72 // FIXME: Make a get_display_server() that re-uses display servers if supported
73 static DisplayServer *create_display_server (Seat *seat);
74 static Greeter *create_greeter_session (Seat *seat);
75 static void start_session (Seat *seat, Session *session);
76
77 void
78 seat_register_module (const gchar *name, GType type)
79 {
80     SeatModule *module;
81
82     if (!seat_modules)
83         seat_modules = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
84
85     g_debug ("Registered seat module %s", name);
86
87     module = g_malloc0 (sizeof (SeatModule));
88     module->name = g_strdup (name);
89     module->type = type;
90     g_hash_table_insert (seat_modules, g_strdup (name), module);
91 }
92
93 Seat *
94 seat_new (const gchar *module_name)
95 {
96     Seat *seat;
97     SeatModule *m = NULL;
98   
99     g_return_val_if_fail (module_name != NULL, NULL);
100
101     if (seat_modules)
102         m = g_hash_table_lookup (seat_modules, module_name);
103     if (!m)
104         return NULL;
105
106     seat = g_object_new (m->type, NULL);
107
108     return seat;
109 }
110
111 void
112 seat_set_property (Seat *seat, const gchar *name, const gchar *value)
113 {
114     g_return_if_fail (seat != NULL);
115     g_hash_table_insert (seat->priv->properties, g_strdup (name), g_strdup (value));
116 }
117
118 const gchar *
119 seat_get_string_property (Seat *seat, const gchar *name)
120 {
121     g_return_val_if_fail (seat != NULL, NULL);
122     return g_hash_table_lookup (seat->priv->properties, name);
123 }
124
125 gboolean
126 seat_get_boolean_property (Seat *seat, const gchar *name)
127 {
128     return g_strcmp0 (seat_get_string_property (seat, name), "true") == 0;
129 }
130
131 gint
132 seat_get_integer_property (Seat *seat, const gchar *name)
133 {
134     const gchar *value;
135
136     value = seat_get_string_property (seat, name);
137     return value ? atoi (value) : 0;
138 }
139
140 void
141 seat_set_can_switch (Seat *seat, gboolean can_switch)
142 {
143     g_return_if_fail (seat != NULL);
144
145     seat->priv->can_switch = can_switch;
146 }
147
148 void
149 seat_set_share_display_server (Seat *seat, gboolean share_display_server)
150 {
151     g_return_if_fail (seat != NULL);
152
153     seat->priv->share_display_server = share_display_server;
154 }
155
156 gboolean
157 seat_start (Seat *seat)
158 {
159     g_return_val_if_fail (seat != NULL, FALSE);
160   
161     SEAT_GET_CLASS (seat)->setup (seat);
162     return SEAT_GET_CLASS (seat)->start (seat);
163 }
164
165 GList *
166 seat_get_sessions (Seat *seat)
167 {
168     g_return_val_if_fail (seat != NULL, NULL);
169     return seat->priv->sessions;
170 }
171
172 void
173 seat_set_active_session (Seat *seat, Session *session)
174 {
175     GList *link;
176
177     g_return_if_fail (seat != NULL);
178
179     SEAT_GET_CLASS (seat)->set_active_session (seat, session);
180
181     /* Stop any greeters */
182     for (link = seat->priv->sessions; link; link = link->next)
183     {
184         Session *s = link->data;
185
186         if (s == session || session_get_is_stopping (s))
187             continue;
188
189         if (IS_GREETER (s))
190         {
191             g_debug ("Stopping greeter");
192             session_stop (s);
193         }
194     }
195 }
196
197 Session *
198 seat_get_active_session (Seat *seat)
199 {
200     g_return_val_if_fail (seat != NULL, NULL);
201     return SEAT_GET_CLASS (seat)->get_active_session (seat);
202 }
203
204 gboolean
205 seat_get_can_switch (Seat *seat)
206 {
207     g_return_val_if_fail (seat != NULL, FALSE);
208     return seat->priv->can_switch;
209 }
210
211 gboolean
212 seat_get_allow_guest (Seat *seat)
213 {
214     g_return_val_if_fail (seat != NULL, FALSE);
215     return seat_get_boolean_property (seat, "allow-guest") && guest_account_is_installed ();
216 }
217
218 static gboolean
219 run_script (Seat *seat, DisplayServer *display_server, const gchar *script_name, User *user)
220 {
221     Process *script;
222     gboolean result = FALSE;
223   
224     script = process_new ();
225
226     process_set_command (script, script_name);
227
228     /* Set POSIX variables */
229     process_set_clear_environment (script, TRUE);
230     process_set_env (script, "SHELL", "/bin/sh");
231
232     /* Variables required for regression tests */
233     if (g_getenv ("LIGHTDM_TEST_ROOT"))
234     {
235         process_set_env (script, "LIGHTDM_TEST_ROOT", g_getenv ("LIGHTDM_TEST_ROOT"));
236         process_set_env (script, "LD_PRELOAD", g_getenv ("LD_PRELOAD"));
237         process_set_env (script, "LD_LIBRARY_PATH", g_getenv ("LD_LIBRARY_PATH"));
238         process_set_env (script, "PATH", g_getenv ("PATH"));
239     }
240     else
241         process_set_env (script, "PATH", "/usr/local/bin:/usr/bin:/bin");
242
243     if (user)
244     {
245         process_set_env (script, "USER", user_get_name (user));
246         process_set_env (script, "LOGNAME", user_get_name (user));
247         process_set_env (script, "HOME", user_get_home_directory (user));
248     }
249     else
250         process_set_env (script, "HOME", "/");
251
252     SEAT_GET_CLASS (seat)->run_script (seat, display_server, script);
253
254     if (process_start (script, TRUE))
255     {
256         int exit_status;
257
258         exit_status = process_get_exit_status (script);
259         if (WIFEXITED (exit_status))
260         {
261             g_debug ("Exit status of %s: %d", script_name, WEXITSTATUS (exit_status));
262             result = WEXITSTATUS (exit_status) == EXIT_SUCCESS;
263         }
264     }
265
266     g_object_unref (script);
267
268     return result;
269 }
270
271 static void
272 seat_real_run_script (Seat *seat, DisplayServer *display_server, Process *process)
273 {  
274 }
275
276 static void
277 emit_upstart_signal (const gchar *signal)
278 {
279     g_return_if_fail (signal != NULL);
280     g_return_if_fail (signal[0] != 0);
281
282     if (getuid () != 0)
283         return;
284
285     gchar *cmd = g_strdup_printf ("initctl -q emit %s DISPLAY_MANAGER=lightdm", signal);
286     g_spawn_command_line_async (cmd, NULL); /* OK if it fails, probably not installed */
287     g_free (cmd);
288 }
289
290 static void
291 check_stopped (Seat *seat)
292 {
293     if (seat->priv->stopping &&
294         !seat->priv->stopped &&
295         g_list_length (seat->priv->display_servers) == 0 &&
296         g_list_length (seat->priv->sessions) == 0)
297     {
298         seat->priv->stopped = TRUE;
299         g_debug ("Seat stopped");
300         g_signal_emit (seat, signals[STOPPED], 0);
301     }
302 }
303
304 static gboolean
305 get_start_local_sessions (Seat *seat)
306 {
307     return SEAT_GET_CLASS (seat)->get_start_local_sessions (seat);
308 }
309
310 static void
311 display_server_stopped_cb (DisplayServer *display_server, Seat *seat)
312 {
313     GList *list, *link;
314     Session *active_session;
315
316     g_debug ("Display server stopped");
317
318     g_signal_handlers_disconnect_matched (display_server, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, seat);
319     seat->priv->display_servers = g_list_remove (seat->priv->display_servers, display_server);
320
321     if (seat->priv->stopping)
322     {
323         check_stopped (seat);
324         g_object_unref (display_server);
325         return;
326     }
327
328     /* Stop all sessions on this display server */
329     list = g_list_copy (seat->priv->sessions);
330     for (link = list; link; link = link->next)
331         g_object_ref (link->data);
332     for (link = list; link; link = link->next)
333     {
334         Session *session = link->data;
335
336         if (session_get_display_server (session) != display_server || session_get_is_stopping (session))
337             continue;
338
339         /* Stop seat if this is the only display server and it failed to start a greeter */
340         if (IS_GREETER (session) &&
341             !session_get_is_started (session) &&
342             g_list_length (seat->priv->display_servers) == 0)
343         {
344             g_debug ("Stopping seat, greeter display server failed to start");
345             seat_stop (seat);
346         }
347
348         g_debug ("Stopping session");
349         session_stop (session);
350     }
351     g_list_free_full (list, g_object_unref);
352
353     if (!seat->priv->stopping && get_start_local_sessions (seat))
354     {
355         /* If we were the active session, switch to a greeter */
356         active_session = seat_get_active_session (seat);
357         if (!active_session || session_get_display_server (active_session) == display_server)
358         {
359             g_debug ("Active display server stopped, starting greeter");
360             seat_switch_to_greeter (seat);
361         }
362     }
363
364     g_object_unref (display_server);
365 }
366
367 static gboolean
368 can_share_display_server (Seat *seat, DisplayServer *display_server)
369 {
370     return seat->priv->share_display_server && display_server_get_can_share (display_server);
371 }
372
373 static void
374 switch_to_greeter_from_failed_session (Seat *seat, Session *session)
375 {
376     Greeter *greeter_session;
377
378     greeter_session = create_greeter_session (seat);
379     if (session_get_is_guest (session))
380         greeter_set_hint (greeter_session, "select-guest", "true");
381     else
382         greeter_set_hint (greeter_session, "select-user", session_get_username (session));
383     if (seat->priv->session_to_activate)
384         g_object_unref (seat->priv->session_to_activate);
385     seat->priv->session_to_activate = g_object_ref (greeter_session);
386
387     if (can_share_display_server (seat, session_get_display_server (session)))
388         session_set_display_server (SESSION (greeter_session), session_get_display_server (session));
389     else
390     {
391         DisplayServer *display_server;
392
393         display_server = create_display_server (seat);
394         if (!display_server_start (display_server))
395         {
396             g_debug ("Failed to start display server for greeter");
397             seat_stop (seat);
398         }
399
400         session_set_display_server (session, display_server);
401     }
402
403     start_session (seat, SESSION (greeter_session));
404
405     /* Stop failed session */
406     session_stop (session);
407 }
408
409 static void
410 start_session (Seat *seat, Session *session)
411 {
412     /* Use system location for greeter log file */
413     if (IS_GREETER (session))
414     {
415         gchar *log_dir, *filename, *log_filename;
416
417         log_dir = config_get_string (config_get_instance (), "LightDM", "log-directory");
418         filename = g_strdup_printf ("%s-greeter.log", display_server_get_name (session_get_display_server (session)));
419         log_filename = g_build_filename (log_dir, filename, NULL);
420         g_free (log_dir);
421         g_free (filename);
422         session_set_log_file (session, log_filename);
423         g_free (log_filename);
424     }
425
426     if (session_start (session))
427         return;
428
429     if (IS_GREETER (session))
430     {
431         g_debug ("Failed to start greeter");
432         display_server_stop (session_get_display_server (session));
433         return;
434     }
435
436     g_debug ("Failed to start session, starting greeter");
437     switch_to_greeter_from_failed_session (seat, session);
438 }
439
440 static void
441 run_session (Seat *seat, Session *session)
442 {
443     const gchar *script;
444
445     if (IS_GREETER (session))
446         script = seat_get_string_property (seat, "greeter-setup-script");
447     else
448         script = seat_get_string_property (seat, "session-setup-script");
449     if (script && !run_script (seat, session_get_display_server (session), script, NULL))
450     {
451         g_debug ("Switching to greeter due to failed setup script");
452         switch_to_greeter_from_failed_session (seat, session);
453         return;
454     }
455
456     if (!IS_GREETER (session))
457         g_signal_emit (seat, signals[RUNNING_USER_SESSION], 0, session);
458
459     session_run (session);
460
461     // FIXME: Wait until the session is ready
462
463     if (session == seat->priv->session_to_activate)
464     {
465         seat_set_active_session (seat, session);
466         g_object_unref (seat->priv->session_to_activate);
467         seat->priv->session_to_activate = NULL;
468     }
469 }
470
471 static void
472 session_authentication_complete_cb (Session *session, Seat *seat)
473 {
474     if (session_get_is_authenticated (session))
475     {
476         g_debug ("Session authenticated, running command");
477         run_session (seat, session);
478     }
479     else if (!IS_GREETER (session))
480     {
481         g_debug ("Switching to greeter due to failed authentication");
482         switch_to_greeter_from_failed_session (seat, session);
483     }
484     else
485     {
486         g_debug ("Stopping session that failed authentication");
487         session_stop (session);
488     }
489 }
490
491 static void
492 session_stopped_cb (Session *session, Seat *seat)
493 {
494     DisplayServer *display_server;
495
496     g_debug ("Session stopped");
497
498     display_server = session_get_display_server (session);
499
500     /* Cleanup */
501     if (!IS_GREETER (session))
502     {
503         const gchar *script;
504         script = seat_get_string_property (seat, "session-cleanup-script");
505         if (script)
506             run_script (seat, display_server, script, session_get_user (session));
507     }
508
509     g_signal_handlers_disconnect_matched (session, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, seat);
510     seat->priv->sessions = g_list_remove (seat->priv->sessions, session);
511
512     /* We were waiting for this session, but it didn't start :( */
513     // FIXME: Start a greeter on this?
514     if (session == seat->priv->session_to_activate)
515     {
516         g_object_unref (seat->priv->session_to_activate);
517         seat->priv->session_to_activate = NULL;
518     }
519
520     if (seat->priv->stopping)
521     {
522         check_stopped (seat);
523         g_object_unref (session);
524         return;
525     }
526
527     /* If this is the greeter session then re-use this display server */
528     if (IS_GREETER (session) &&
529         can_share_display_server (seat, display_server) &&
530         greeter_get_start_session (GREETER (session)))
531     {
532         GList *link;
533
534         for (link = seat->priv->sessions; link; link = link->next)
535         {
536             Session *s = link->data;
537
538             /* Skip this session and sessions on other display servers */
539             if (s == session || session_get_display_server (s) != display_server || session_get_is_stopping (s))
540                 continue;
541
542             if (session_get_is_authenticated (s))
543             {
544                 g_debug ("Greeter stopped, running session");
545                 run_session (seat, s);
546             }
547             else
548             {
549                 g_debug ("Greeter stopped, starting session authentication");
550                 start_session (seat, s);
551             }
552             break;
553         }
554     }
555     /* If this is the greeter and nothing else is running then stop the seat */
556     else if (IS_GREETER (session) &&
557         !greeter_get_start_session (GREETER (session)) &&
558         g_list_length (seat->priv->display_servers) == 1 &&
559         g_list_nth_data (seat->priv->display_servers, 0) == display_server)
560     {
561         g_debug ("Stopping seat, failed to start a greeter");
562         seat_stop (seat);
563     }
564     /* If we were the active session, switch to a greeter */
565     else if (!IS_GREETER (session) && session == seat_get_active_session (seat))
566     {
567         g_debug ("Active session stopped, starting greeter");
568         seat_switch_to_greeter (seat);
569     }
570
571     /* Stop the display server if no-longer required */
572     if (display_server && !display_server_get_is_stopping (display_server))
573     {
574         GList *link;
575         int n_sessions = 0;
576
577         for (link = seat->priv->sessions; link; link = link->next)
578         {
579             Session *s = link->data;
580             if (s == session)
581                 continue;
582             if (session_get_display_server (s) == display_server)
583                 n_sessions++;
584         }
585         if (n_sessions == 0)
586         {
587             g_debug ("Stopping display server, no sessions require it");
588             display_server_stop (display_server);
589         }
590     }
591
592     g_signal_emit (seat, signals[SESSION_REMOVED], 0, session);
593     g_object_unref (session);
594 }
595
596 static void
597 set_session_env (Session *session)
598 {
599     /* Connect using the session bus */
600     if (getuid () != 0)
601     {
602         if (g_getenv ("DBUS_SESSION_BUS_ADDRESS"))
603             session_set_env (session, "DBUS_SESSION_BUS_ADDRESS", g_getenv ("DBUS_SESSION_BUS_ADDRESS"));
604         session_set_env (session, "LDM_BUS", "SESSION");
605         if (g_getenv ("LD_PRELOAD"))
606             session_set_env (session, "LD_PRELOAD", g_getenv ("LD_PRELOAD"));
607         if (g_getenv ("LD_LIBRARY_PATH"))
608             session_set_env (session, "LD_LIBRARY_PATH", g_getenv ("LD_LIBRARY_PATH"));
609         if (g_getenv ("PATH"))
610             session_set_env (session, "PATH", g_getenv ("PATH"));
611     }
612
613     /* Variables required for regression tests */
614     if (g_getenv ("LIGHTDM_TEST_ROOT"))
615     {
616         session_set_env (session, "LIGHTDM_TEST_ROOT", g_getenv ("LIGHTDM_TEST_ROOT"));
617         session_set_env (session, "DBUS_SYSTEM_BUS_ADDRESS", g_getenv ("DBUS_SYSTEM_BUS_ADDRESS"));
618         session_set_env (session, "DBUS_SESSION_BUS_ADDRESS", g_getenv ("DBUS_SESSION_BUS_ADDRESS"));
619         session_set_env (session, "LD_PRELOAD", g_getenv ("LD_PRELOAD"));
620         session_set_env (session, "LD_LIBRARY_PATH", g_getenv ("LD_LIBRARY_PATH"));
621         session_set_env (session, "GI_TYPELIB_PATH", g_getenv ("GI_TYPELIB_PATH"));
622     }
623 }
624
625 static Session *
626 create_session (Seat *seat, gboolean autostart)
627 {
628     Session *session;
629
630     session = SEAT_GET_CLASS (seat)->create_session (seat);
631     seat->priv->sessions = g_list_append (seat->priv->sessions, session);
632     if (autostart)
633         g_signal_connect (session, "authentication-complete", G_CALLBACK (session_authentication_complete_cb), seat);
634     g_signal_connect (session, "stopped", G_CALLBACK (session_stopped_cb), seat);
635
636     set_session_env (session);
637
638     g_signal_emit (seat, signals[SESSION_ADDED], 0, session);
639
640     return session;
641 }
642
643 static gchar **
644 get_session_argv (SessionConfig *session_config, const gchar *session_wrapper)
645 {
646     gboolean result;
647     int argc;
648     gchar **argv, *path;
649     GError *error = NULL;
650
651     /* If configured, run sessions through a wrapper */
652     if (session_wrapper)
653     {
654         argv = g_malloc (sizeof (gchar *) * 3);
655         path = g_find_program_in_path (session_wrapper);
656         argv[0] = path ? path : g_strdup (session_wrapper);
657         argv[1] = g_strdup (session_config_get_command (session_config));
658         argv[2] = NULL;
659         return argv;
660     }
661
662     /* Split command into an array listing and make command absolute */
663     result = g_shell_parse_argv (session_config_get_command (session_config), &argc, &argv, &error);
664     if (error)
665         g_debug ("Invalid session command '%s': %s", session_config_get_command (session_config), error->message);
666     g_clear_error (&error);
667     if (!result)
668         return NULL;
669     path = g_find_program_in_path (argv[0]);
670     if (path)
671     {
672         g_free (argv[0]);
673         argv[0] = path;
674     }
675   
676     return argv;
677 }
678
679 static SessionConfig *
680 find_session_config (const gchar *sessions_dir, const gchar *session_name)
681 {
682     gchar **dirs;
683     SessionConfig *session_config = NULL;
684     int i;
685     GError *error = NULL;
686
687     g_return_val_if_fail (sessions_dir != NULL, NULL);
688     g_return_val_if_fail (session_name != NULL, NULL);
689
690     dirs = g_strsplit (sessions_dir, ":", -1);
691     for (i = 0; dirs[i]; i++)
692     {
693         gchar *filename, *path;
694
695         filename = g_strdup_printf ("%s.desktop", session_name);
696         path = g_build_filename (dirs[i], filename, NULL);
697         g_free (filename);
698         session_config = session_config_new_from_file (path, &error);
699         g_free (path);
700         if (session_config)
701             break;
702
703         if (dirs[i+1] == NULL)
704             g_debug ("Failed to find session configuration %s", session_name);
705         g_clear_error (&error);
706     }
707     g_strfreev (dirs);
708
709     return session_config;
710 }
711
712 static Session *
713 create_user_session (Seat *seat, const gchar *username)
714 {
715     User *user;
716     gchar *sessions_dir;
717     const gchar *session_name, *language;
718     SessionConfig *session_config;
719     Session *session = NULL;
720
721     g_debug ("Creating user session");
722
723     /* Load user preferences */
724     user = accounts_get_user_by_name (username);
725     if (!user)
726     {
727         g_debug ("Can't login unknown user '%s'", username);
728         return NULL;
729     }
730     session_name = user_get_xsession (user);
731     language = user_get_language (user);
732
733     if (!session_name)
734         session_name = seat_get_string_property (seat, "user-session");
735     sessions_dir = config_get_string (config_get_instance (), "LightDM", "sessions-directory");
736     session_config = find_session_config (sessions_dir, session_name);
737     g_free (sessions_dir);
738     if (session_config)
739     {
740         gchar **argv;
741
742         session = create_session (seat, TRUE);
743         session_set_env (session, "DESKTOP_SESSION", session_name);
744         session_set_env (session, "GDMSESSION", session_name);
745         if (language && language[0] != '\0')
746         {
747             session_set_env (session, "LANG", language);
748             session_set_env (session, "GDM_LANG", language);
749         }
750         session_set_pam_service (session, AUTOLOGIN_SERVICE);
751         session_set_username (session, username);
752         session_set_do_authenticate (session, TRUE);
753         argv = get_session_argv (session_config, seat_get_string_property (seat, "session-wrapper"));
754         session_set_argv (session, argv);
755         g_strfreev (argv);
756
757         g_object_unref (session_config);
758     }
759     else
760         g_debug ("Can't find session '%s'", seat_get_string_property (seat, "user-session"));
761
762
763     g_object_unref (user);
764
765     return session;
766 }
767
768 static Session *
769 create_guest_session (Seat *seat)
770 {
771     gchar *sessions_dir, **argv;
772     SessionConfig *session_config;
773     Session *session;
774
775     sessions_dir = config_get_string (config_get_instance (), "LightDM", "sessions-directory");
776     session_config = find_session_config (sessions_dir, seat_get_string_property (seat, "user-session"));
777     g_free (sessions_dir);
778     if (!session_config)
779     {
780         g_debug ("Can't find session '%s'", seat_get_string_property (seat, "user-session"));
781         return NULL;
782     }
783
784     session = create_session (seat, TRUE);
785     session_set_do_authenticate (session, TRUE);
786     session_set_is_guest (session, TRUE);
787     argv = get_session_argv (session_config, seat_get_string_property (seat, "session-wrapper"));
788     g_object_unref (session_config);
789     session_set_argv (session, argv);
790     g_strfreev (argv);
791   
792     return session;
793 }
794
795 static Session *
796 greeter_create_session_cb (Greeter *greeter, Seat *seat)
797 {
798     Session *session;
799
800     session = create_session (seat, FALSE);
801     session_set_display_server (session, session_get_display_server (SESSION (greeter)));
802
803     return g_object_ref (session);
804 }
805
806 static void
807 prepend_argv (gchar ***argv, const gchar *value)
808 {
809     gchar **old_argv, **new_argv;
810     gint i;
811
812     old_argv = *argv;
813     new_argv = g_malloc (sizeof (gchar *) * (g_strv_length (*argv) + 2));
814     new_argv[0] = g_strdup (value);
815     for (i = 0; old_argv[i]; i++)
816         new_argv[i + 1] = old_argv[i];
817     new_argv[i + 1] = NULL;
818
819     g_free (*argv);
820     *argv = new_argv;
821 }
822
823 static Session *
824 find_user_session (Seat *seat, const gchar *username)
825 {
826     GList *link;
827
828     if (!username)
829         return NULL;
830
831     for (link = seat->priv->sessions; link; link = link->next)
832     {
833         Session *session = link->data;
834
835         if (!session_get_is_stopping (session) && strcmp (session_get_username (session), username) == 0)
836             return session;
837     }
838
839     return NULL;
840 }
841
842 static gboolean
843 greeter_start_session_cb (Greeter *greeter, SessionType type, const gchar *session_name, Seat *seat)
844 {
845     Session *session, *existing_session;
846     const gchar *username, *language = NULL;
847     SessionConfig *session_config;
848     User *user;
849     gchar *sessions_dir = NULL;
850     gchar **argv;
851     DisplayServer *display_server;
852
853     /* Get the session to use */
854     if (greeter_get_guest_authenticated (greeter))
855     {
856         session = create_guest_session (seat);
857         if (!session)
858             return FALSE;
859         session_set_pam_service (session, AUTOLOGIN_SERVICE);
860     }
861     else
862         session = greeter_get_authentication_session (greeter);
863
864     /* Switch to this session when it is ready */
865     if (seat->priv->session_to_activate)
866         g_object_unref (seat->priv->session_to_activate);
867     seat->priv->session_to_activate = g_object_ref (session);
868
869     /* Return to existing session if it is open */
870     username = session_get_username (session);
871     existing_session = find_user_session (seat, username);
872     if (existing_session && session != existing_session)
873     {
874         g_debug ("Returning to existing user session %s", username);
875         session_stop (session);
876         seat_set_active_session (seat, existing_session);
877         return TRUE;
878     }
879
880     /* Get session command to run */
881     switch (type)
882     {
883     case SESSION_TYPE_LOCAL:
884         sessions_dir = config_get_string (config_get_instance (), "LightDM", "sessions-directory");
885         break;
886     case SESSION_TYPE_REMOTE:
887         sessions_dir = config_get_string (config_get_instance (), "LightDM", "remote-sessions-directory");
888         break;
889     }
890
891     /* Load user preferences */
892     user = session_get_user (session);
893     if (user)
894     {
895         if (!session_name)
896             session_name = user_get_xsession (user);
897         language = user_get_language (user);
898     }
899
900     if (!session_name)
901         session_name = seat_get_string_property (seat, "user-session");
902     if (user)
903         user_set_xsession (session_get_user (session), session_name);
904
905     session_config = find_session_config (sessions_dir, session_name);
906     g_free (sessions_dir);
907     if (!session_config)
908     {
909         g_debug ("Can't find session '%s'", seat_get_string_property (seat, "user-session"));
910         return FALSE;
911     }
912
913     argv = get_session_argv (session_config, seat_get_string_property (seat, "session-wrapper"));
914     session_set_argv (session, argv);
915     g_strfreev (argv);
916     session_set_env (session, "DESKTOP_SESSION", session_name);
917     session_set_env (session, "GDMSESSION", session_name);
918     if (language && language[0] != '\0')
919     {
920         session_set_env (session, "LANG", language);
921         session_set_env (session, "GDM_LANG", language);
922     }
923
924     g_object_unref (session_config);
925
926     /* If can re-use the display server, stop the greeter first */
927     display_server = session_get_display_server (SESSION (greeter));
928     if (can_share_display_server (seat, display_server))
929     {
930         g_debug ("Stopping greeter; display server will be re-used for user session");
931
932         /* Run on the same display server after the greeter has stopped */
933         session_set_display_server (session, display_server);
934
935         /* Stop the greeter */
936         session_stop (SESSION (greeter));
937
938         return TRUE;
939     }
940     /* Otherwise start a new display server for this session */
941     else
942     {
943         display_server = create_display_server (seat);
944         session_set_display_server (session, display_server);
945         if (!display_server_start (display_server))
946         {
947             g_debug ("Failed to start display server for new session");
948             return FALSE;
949         }
950
951         return TRUE;
952     }
953 }
954
955 static Greeter *
956 create_greeter_session (Seat *seat)
957 {
958     gchar *sessions_dir, **argv;
959     SessionConfig *session_config;
960     Greeter *greeter_session;
961     gchar *greeter_user;
962     const gchar *greeter_wrapper;
963
964     g_debug ("Creating greeter session");
965
966     sessions_dir = config_get_string (config_get_instance (), "LightDM", "greeters-directory");
967     session_config = find_session_config (sessions_dir, seat_get_string_property (seat, "greeter-session"));
968     g_free (sessions_dir);
969     if (!session_config)
970         return NULL;
971
972     argv = get_session_argv (session_config, NULL);
973     greeter_wrapper = seat_get_string_property (seat, "greeter-wrapper");
974     if (greeter_wrapper)
975     {
976         gchar *path;
977         path = g_find_program_in_path (greeter_wrapper);
978         prepend_argv (&argv, path ? path : greeter_wrapper);
979         g_free (path);
980     }
981
982     greeter_session = SEAT_GET_CLASS (seat)->create_greeter_session (seat);
983     seat->priv->sessions = g_list_append (seat->priv->sessions, SESSION (greeter_session));
984     g_signal_connect (greeter_session, "authentication-complete", G_CALLBACK (session_authentication_complete_cb), seat);
985     g_signal_connect (greeter_session, "stopped", G_CALLBACK (session_stopped_cb), seat);
986   
987     set_session_env (SESSION (greeter_session));
988
989     session_set_pam_service (SESSION (greeter_session), GREETER_SERVICE);
990     greeter_user = config_get_string (config_get_instance (), "LightDM", "greeter-user");
991     session_set_username (SESSION (greeter_session), greeter_user);
992     g_free (greeter_user);
993     session_set_argv (SESSION (greeter_session), argv);
994     g_strfreev (argv);
995
996     greeter_set_pam_services (greeter_session, USER_SERVICE, AUTOLOGIN_SERVICE);
997     g_signal_connect (greeter_session, "create-session", G_CALLBACK (greeter_create_session_cb), seat);
998     g_signal_connect (greeter_session, "start-session", G_CALLBACK (greeter_start_session_cb), seat);
999
1000     /* Set hints to greeter */
1001     greeter_set_hint (greeter_session, "default-session", seat_get_string_property (seat, "user-session"));
1002     greeter_set_allow_guest (greeter_session, seat_get_allow_guest (seat));
1003     greeter_set_hint (greeter_session, "hide-users", seat_get_boolean_property (seat, "greeter-hide-users") ? "true" : "false");
1004     greeter_set_hint (greeter_session, "show-manual-login", seat_get_boolean_property (seat, "greeter-show-manual-login") ? "true" : "false");
1005     greeter_set_hint (greeter_session, "show-remote-login", seat_get_boolean_property (seat, "greeter-show-remote-login") ? "true" : "false");
1006     greeter_set_hint (greeter_session, "has-guest-account", seat_get_allow_guest (seat) && seat_get_boolean_property (seat, "greeter-allow-guest") ? "true" : "false");
1007
1008     g_object_unref (session_config);
1009
1010     return greeter_session;
1011 }
1012
1013 static Session *
1014 find_session_for_display_server (Seat *seat, DisplayServer *display_server)
1015 {
1016     GList *link;
1017
1018     for (link = seat->priv->sessions; link; link = link->next)
1019     {
1020         Session *session = link->data;
1021         if (session_get_display_server (session) == display_server && !session_get_is_stopping (session))
1022             return session;
1023     }
1024
1025     return NULL;
1026 }
1027
1028 static void
1029 display_server_ready_cb (DisplayServer *display_server, Seat *seat)
1030 {
1031     const gchar *script;
1032     Session *session;
1033
1034     /* Run setup script */
1035     script = seat_get_string_property (seat, "display-setup-script");
1036     if (script && !run_script (seat, display_server, script, NULL))
1037     {
1038         g_debug ("Stopping display server due to failed setup script");
1039         display_server_stop (display_server);
1040         return;
1041     }
1042
1043     /* Stop if don't need to run a session */
1044     if (!get_start_local_sessions (seat))
1045         return;
1046
1047     emit_upstart_signal ("login-session-start");
1048
1049     /* Start the session waiting for this display server */
1050     session = find_session_for_display_server (seat, display_server);
1051     if (session)
1052     {
1053         if (session_get_is_authenticated (session))
1054         {
1055             g_debug ("Display server ready, running session");
1056             run_session (seat, session);
1057         }
1058         else
1059         {
1060             g_debug ("Display server ready, starting session authentication");
1061             start_session (seat, session);
1062         }
1063     }
1064     else
1065     {
1066         g_debug ("Stopping not required display server");
1067         display_server_stop (display_server);
1068     }
1069 }
1070
1071 static DisplayServer *
1072 create_display_server (Seat *seat)
1073 {
1074     DisplayServer *display_server;
1075
1076     g_debug ("Creating display server");
1077
1078     display_server = SEAT_GET_CLASS (seat)->create_display_server (seat);
1079     seat->priv->display_servers = g_list_append (seat->priv->display_servers, display_server);
1080     g_signal_connect (display_server, "ready", G_CALLBACK (display_server_ready_cb), seat);
1081     g_signal_connect (display_server, "stopped", G_CALLBACK (display_server_stopped_cb), seat);
1082
1083     return display_server;
1084 }
1085
1086 static Greeter *
1087 find_greeter_session (Seat *seat)
1088 {
1089     GList *link;
1090
1091     for (link = seat->priv->sessions; link; link = link->next)
1092     {
1093         Session *session = link->data;
1094         if (!session_get_is_stopping (session) && IS_GREETER (session))
1095             return GREETER (session);
1096     }
1097
1098     return NULL;
1099 }
1100
1101 gboolean
1102 seat_switch_to_greeter (Seat *seat)
1103 {
1104     Greeter *greeter_session;
1105     DisplayServer *display_server;
1106
1107     g_return_val_if_fail (seat != NULL, FALSE);
1108
1109     if (!seat->priv->can_switch)
1110         return FALSE;
1111
1112     /* Switch to greeter if one open (shouldn't be though) */
1113     greeter_session = find_greeter_session (seat);
1114     if (greeter_session)
1115     {
1116         g_debug ("Switching to existing greeter");
1117         seat_set_active_session (seat, SESSION (greeter_session));
1118         return TRUE;
1119     }
1120
1121     greeter_session = create_greeter_session (seat);
1122     if (seat->priv->session_to_activate)
1123         g_object_unref (seat->priv->session_to_activate);
1124     seat->priv->session_to_activate = g_object_ref (greeter_session);
1125
1126     display_server = create_display_server (seat);
1127     session_set_display_server (SESSION (greeter_session), display_server);
1128     if (!display_server_start (display_server))
1129         return FALSE;
1130
1131     return TRUE;
1132 }
1133
1134 gboolean
1135 seat_switch_to_user (Seat *seat, const gchar *username, const gchar *session_name)
1136 {
1137     Session *session;
1138     DisplayServer *display_server;
1139
1140     g_return_val_if_fail (seat != NULL, FALSE);
1141     g_return_val_if_fail (username != NULL, FALSE);
1142
1143     if (!seat->priv->can_switch)
1144         return FALSE;
1145
1146     g_debug ("Switching to user %s", username);
1147
1148     session = find_user_session (seat, username);
1149     if (session)
1150     {
1151         g_debug ("Switching to existing user session %s", username);
1152         seat_set_active_session (seat, session);
1153         return TRUE;
1154     }
1155
1156     session = create_user_session (seat, username);
1157     if (!session)
1158         return FALSE;
1159     if (seat->priv->session_to_activate)
1160         g_object_unref (seat->priv->session_to_activate);
1161     seat->priv->session_to_activate = g_object_ref (session);
1162     session_set_pam_service (session, USER_SERVICE);
1163
1164     display_server = create_display_server (seat);
1165     session_set_display_server (session, display_server);
1166     if (!display_server_start (display_server))
1167         return FALSE;
1168
1169     return FALSE;
1170 }
1171
1172 static Session *
1173 find_guest_session (Seat *seat)
1174 {
1175     GList *link;
1176
1177     for (link = seat->priv->sessions; link; link = link->next)
1178     {
1179         Session *session = link->data;
1180         if (!session_get_is_stopping (session) && session_get_is_guest (session))
1181             return session;
1182     }
1183
1184     return NULL;
1185 }
1186
1187 gboolean
1188 seat_switch_to_guest (Seat *seat, const gchar *session_name)
1189 {
1190     Session *session;
1191     DisplayServer *display_server;
1192
1193     g_return_val_if_fail (seat != NULL, FALSE);
1194
1195     if (!seat->priv->can_switch || !seat_get_allow_guest (seat))
1196         return FALSE;
1197
1198     /* Switch to session if one open */
1199     session = find_guest_session (seat);
1200     if (session)
1201     {
1202         g_debug ("Switching to existing guest account %s", session_get_username (session));
1203         seat_set_active_session (seat, session);
1204         return TRUE;
1205     }
1206
1207     session = create_guest_session (seat);
1208     if (!session)
1209         return FALSE;
1210
1211     display_server = create_display_server (seat);
1212     if (!display_server_start (display_server))
1213         return FALSE;
1214
1215     if (seat->priv->session_to_activate)
1216         g_object_unref (seat->priv->session_to_activate);
1217     seat->priv->session_to_activate = g_object_ref (session);
1218     session_set_pam_service (session, AUTOLOGIN_SERVICE);
1219     session_set_display_server (session, display_server);
1220
1221     return TRUE;
1222 }
1223
1224 gboolean
1225 seat_lock (Seat *seat, const gchar *username)
1226 {
1227     Greeter *greeter_session;
1228     DisplayServer *display_server;
1229
1230     g_return_val_if_fail (seat != NULL, FALSE);
1231
1232     if (!seat->priv->can_switch)
1233         return FALSE;
1234
1235     g_debug ("Locking seat");
1236
1237     /* Switch to greeter if one open (shouldn't be though) */
1238     greeter_session = find_greeter_session (seat);
1239     if (greeter_session)
1240     {
1241         g_debug ("Switching to existing greeter");
1242         seat_set_active_session (seat, SESSION (greeter_session));
1243         return TRUE;
1244     }
1245
1246     greeter_session = create_greeter_session (seat);
1247     if (!greeter_session)
1248         return FALSE;
1249
1250     display_server = create_display_server (seat);
1251     if (!display_server_start (display_server))
1252         return FALSE;
1253
1254     if (seat->priv->session_to_activate)
1255         g_object_unref (seat->priv->session_to_activate);
1256     seat->priv->session_to_activate = g_object_ref (greeter_session);
1257     greeter_set_hint (greeter_session, "lock-screen", "true");
1258     if (username)
1259         greeter_set_hint (greeter_session, "select-user", username);
1260     session_set_display_server (SESSION (greeter_session), display_server);
1261
1262     return TRUE;
1263 }
1264
1265 void
1266 seat_stop (Seat *seat)
1267 {
1268     g_return_if_fail (seat != NULL);
1269
1270     if (seat->priv->stopping)
1271         return;
1272
1273     g_debug ("Stopping seat");
1274     seat->priv->stopping = TRUE;
1275     SEAT_GET_CLASS (seat)->stop (seat);
1276 }
1277
1278 gboolean
1279 seat_get_is_stopping (Seat *seat)
1280 {
1281     g_return_val_if_fail (seat != NULL, FALSE);
1282     return seat->priv->stopping;
1283 }
1284
1285 static gboolean
1286 seat_real_get_start_local_sessions (Seat *seat)
1287 {
1288     return TRUE;
1289 }
1290
1291 static void
1292 seat_real_setup (Seat *seat)
1293 {
1294 }
1295
1296 static gboolean
1297 seat_real_start (Seat *seat)
1298 {
1299     const gchar *autologin_username;
1300     int autologin_timeout;
1301     gboolean autologin_guest;
1302     gboolean autologin_in_background;
1303     Session *session = NULL, *background_session = NULL;
1304     DisplayServer *display_server;
1305
1306     g_debug ("Starting seat");
1307
1308     /* If this display server doesn't have a session running on it, just start it */
1309     if (!get_start_local_sessions (seat))
1310     {
1311         display_server = create_display_server (seat);
1312         return display_server_start (display_server);
1313     }
1314
1315     /* Get autologin settings */
1316     autologin_username = seat_get_string_property (seat, "autologin-user");
1317     if (g_strcmp0 (autologin_username, "") == 0)
1318         autologin_username = NULL;
1319     autologin_timeout = seat_get_integer_property (seat, "autologin-user-timeout");
1320     autologin_guest = seat_get_boolean_property (seat, "autologin-guest");
1321     autologin_in_background = seat_get_boolean_property (seat, "autologin-in-background");
1322
1323     /* Autologin if configured */
1324     if (autologin_timeout == 0 || autologin_in_background)
1325     {
1326         if (autologin_guest)
1327             session = create_guest_session (seat);
1328         else if (autologin_username != NULL)
1329             session = create_user_session (seat, autologin_username);
1330       
1331         if (session)
1332         {
1333             if (seat->priv->session_to_activate)
1334                 g_object_unref (seat->priv->session_to_activate);
1335             seat->priv->session_to_activate = g_object_ref (session);
1336             session_set_pam_service (session, AUTOLOGIN_SERVICE);
1337         }
1338
1339         /* Load in background if required */
1340         if (autologin_in_background && session)
1341         {
1342             background_session = session;
1343             session = NULL;
1344         }
1345     }
1346
1347     /* Fallback to a greeter */
1348     if (!session)
1349     {
1350         Greeter *greeter_session;
1351
1352         greeter_session = create_greeter_session (seat);
1353         if (seat->priv->session_to_activate)
1354             g_object_unref (seat->priv->session_to_activate);
1355         seat->priv->session_to_activate = g_object_ref (greeter_session);
1356         session = SESSION (greeter_session);
1357
1358         if (autologin_timeout)
1359         {
1360             gchar *value;
1361
1362             value = g_strdup_printf ("%d", autologin_timeout);
1363             greeter_set_hint (greeter_session, "autologin-timeout", value);
1364             g_free (value);
1365             if (autologin_username)
1366                 greeter_set_hint (greeter_session, "autologin-user", autologin_username);
1367             if (autologin_guest)
1368                 greeter_set_hint (greeter_session, "autologin-guest", "true");
1369         }
1370     }
1371
1372     /* Fail if can't start a session */
1373     if (!session)
1374     {
1375         seat_stop (seat);
1376         return FALSE;
1377     }
1378
1379     display_server = create_display_server (seat);
1380     if (!display_server)
1381         return FALSE;
1382
1383     /* Start display server to show session on */
1384     session_set_display_server (session, display_server);
1385     if (!display_server_start (display_server))
1386         return FALSE;
1387
1388     /* Start background session */
1389     if (background_session)
1390     {
1391         DisplayServer *background_display_server;
1392
1393         background_display_server = create_display_server (seat);
1394         session_set_display_server (background_session, background_display_server);
1395         if (!display_server_start (background_display_server))
1396             g_warning ("Failed to start display server for background session");
1397     }
1398
1399     return TRUE;
1400 }
1401
1402 static Greeter *
1403 seat_real_create_greeter_session (Seat *seat)
1404 {
1405     return greeter_new ();
1406 }
1407
1408 static Session *
1409 seat_real_create_session (Seat *seat)
1410 {
1411     return session_new ();
1412 }
1413
1414 static void
1415 seat_real_set_active_session (Seat *seat, Session *session)
1416 {
1417 }
1418
1419 static Session *
1420 seat_real_get_active_session (Seat *seat)
1421 {
1422     return NULL;
1423 }
1424
1425 static void
1426 seat_real_stop (Seat *seat)
1427 {
1428     GList *list, *link;
1429
1430     check_stopped (seat);
1431     if (seat->priv->stopped)
1432         return;
1433
1434     /* Stop all the display servers and sessions on the seat. Copy the list as
1435      * it might be modified if a display server / session stops during this loop */
1436     list = g_list_copy (seat->priv->display_servers);
1437     for (link = list; link; link = link->next)
1438         g_object_ref (link->data);
1439     for (link = list; link; link = link->next)
1440     {
1441         DisplayServer *display_server = link->data;
1442         if (!display_server_get_is_stopping (display_server))
1443         {
1444             g_debug ("Stopping display server");
1445             display_server_stop (display_server);
1446         }
1447     }
1448     g_list_free_full (list, g_object_unref);
1449     list = g_list_copy (seat->priv->sessions);
1450     for (link = list; link; link = link->next)
1451         g_object_ref (link->data);
1452     for (link = list; link; link = link->next)
1453     {
1454         Session *session = link->data;
1455         if (!session_get_is_stopping (session))
1456         {
1457             g_debug ("Stopping session");
1458             session_stop (session);
1459         }
1460     }
1461     g_list_free_full (list, g_object_unref);
1462 }
1463
1464 static void
1465 seat_init (Seat *seat)
1466 {
1467     seat->priv = G_TYPE_INSTANCE_GET_PRIVATE (seat, SEAT_TYPE, SeatPrivate);
1468     seat->priv->properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
1469     seat->priv->share_display_server = TRUE;
1470 }
1471
1472 static void
1473 seat_finalize (GObject *object)
1474 {
1475     Seat *self;
1476     GList *link;
1477
1478     self = SEAT (object);
1479
1480     g_hash_table_unref (self->priv->properties);
1481     for (link = self->priv->display_servers; link; link = link->next)
1482     {
1483         DisplayServer *display_server = link->data;
1484         g_signal_handlers_disconnect_matched (display_server, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, self);
1485     }  
1486     g_list_free_full (self->priv->display_servers, g_object_unref);
1487     for (link = self->priv->sessions; link; link = link->next)
1488     {
1489         Session *session = link->data;
1490         g_signal_handlers_disconnect_matched (session, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, self);
1491     }
1492     g_list_free_full (self->priv->sessions, g_object_unref);
1493     if (self->priv->session_to_activate)
1494         g_object_unref (self->priv->session_to_activate);
1495
1496     G_OBJECT_CLASS (seat_parent_class)->finalize (object);
1497 }
1498
1499 static void
1500 seat_class_init (SeatClass *klass)
1501 {
1502     GObjectClass *object_class = G_OBJECT_CLASS (klass);
1503
1504     klass->get_start_local_sessions = seat_real_get_start_local_sessions;
1505     klass->setup = seat_real_setup;
1506     klass->start = seat_real_start;
1507     klass->create_greeter_session = seat_real_create_greeter_session;
1508     klass->create_session = seat_real_create_session;
1509     klass->set_active_session = seat_real_set_active_session;
1510     klass->get_active_session = seat_real_get_active_session;
1511     klass->run_script = seat_real_run_script;
1512     klass->stop = seat_real_stop;
1513
1514     object_class->finalize = seat_finalize;
1515
1516     g_type_class_add_private (klass, sizeof (SeatPrivate));
1517
1518     signals[SESSION_ADDED] =
1519         g_signal_new ("session-added",
1520                       G_TYPE_FROM_CLASS (klass),
1521                       G_SIGNAL_RUN_LAST,
1522                       G_STRUCT_OFFSET (SeatClass, session_added),
1523                       NULL, NULL,
1524                       NULL,
1525                       G_TYPE_NONE, 1, SESSION_TYPE);
1526     signals[RUNNING_USER_SESSION] =
1527         g_signal_new ("running-user-session",
1528                       G_TYPE_FROM_CLASS (klass),
1529                       G_SIGNAL_RUN_LAST,
1530                       G_STRUCT_OFFSET (SeatClass, running_user_session),
1531                       NULL, NULL,
1532                       NULL,
1533                       G_TYPE_NONE, 1, SESSION_TYPE);
1534     signals[SESSION_REMOVED] =
1535         g_signal_new ("session-removed",
1536                       G_TYPE_FROM_CLASS (klass),
1537                       G_SIGNAL_RUN_LAST,
1538                       G_STRUCT_OFFSET (SeatClass, session_removed),
1539                       NULL, NULL,
1540                       NULL,
1541                       G_TYPE_NONE, 1, SESSION_TYPE);
1542     signals[STOPPED] =
1543         g_signal_new ("stopped",
1544                       G_TYPE_FROM_CLASS (klass),
1545                       G_SIGNAL_RUN_LAST,
1546                       G_STRUCT_OFFSET (SeatClass, stopped),
1547                       NULL, NULL,
1548                       NULL,
1549                       G_TYPE_NONE, 0);
1550 }