]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - src/seat.c
Add better seat logging information
[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 void
368 switch_to_greeter_from_failed_session (Seat *seat, Session *session)
369 {
370     Greeter *greeter_session;
371
372     greeter_session = create_greeter_session (seat);
373     if (session_get_is_guest (session))
374         greeter_set_hint (greeter_session, "select-guest", "true");
375     else
376         greeter_set_hint (greeter_session, "select-user", session_get_username (session));
377     if (seat->priv->session_to_activate)
378         g_object_unref (seat->priv->session_to_activate);
379     seat->priv->session_to_activate = g_object_ref (greeter_session);
380
381     if (seat->priv->share_display_server)
382         session_set_display_server (SESSION (greeter_session), session_get_display_server (session));
383     else
384     {
385         DisplayServer *display_server;
386
387         display_server = create_display_server (seat);
388         if (!display_server_start (display_server))
389         {
390             g_debug ("Failed to start display server for greeter");
391             seat_stop (seat);
392         }
393
394         session_set_display_server (session, display_server);
395     }
396
397     start_session (seat, SESSION (greeter_session));
398
399     /* Stop failed session */
400     session_stop (session);
401 }
402
403 static void
404 start_session (Seat *seat, Session *session)
405 {
406     /* Use system location for greeter log file */
407     if (IS_GREETER (session))
408     {
409         gchar *log_dir, *filename, *log_filename;
410
411         log_dir = config_get_string (config_get_instance (), "LightDM", "log-directory");
412         filename = g_strdup_printf ("%s-greeter.log", display_server_get_name (session_get_display_server (session)));
413         log_filename = g_build_filename (log_dir, filename, NULL);
414         g_free (log_dir);
415         g_free (filename);
416         session_set_log_file (session, log_filename);
417         g_free (log_filename);
418     }
419
420     if (session_start (session))
421         return;
422
423     if (IS_GREETER (session))
424     {
425         g_debug ("Failed to start greeter");
426         display_server_stop (session_get_display_server (session));
427         return;
428     }
429
430     g_debug ("Failed to start session, starting greeter");
431     switch_to_greeter_from_failed_session (seat, session);
432 }
433
434 static void
435 run_session (Seat *seat, Session *session)
436 {
437     const gchar *script;
438
439     if (IS_GREETER (session))
440         script = seat_get_string_property (seat, "greeter-setup-script");
441     else
442         script = seat_get_string_property (seat, "session-setup-script");
443     if (script && !run_script (seat, session_get_display_server (session), script, NULL))
444     {
445         g_debug ("Switching to greeter due to failed setup script");
446         switch_to_greeter_from_failed_session (seat, session);
447         return;
448     }
449
450     if (!IS_GREETER (session))
451         g_signal_emit (seat, signals[RUNNING_USER_SESSION], 0, session);
452
453     session_run (session);
454
455     // FIXME: Wait until the session is ready
456
457     if (session == seat->priv->session_to_activate)
458     {
459         seat_set_active_session (seat, session);
460         g_object_unref (seat->priv->session_to_activate);
461         seat->priv->session_to_activate = NULL;
462     }
463 }
464
465 static void
466 session_authentication_complete_cb (Session *session, Seat *seat)
467 {
468     if (session_get_is_authenticated (session))
469     {
470         g_debug ("Session authenticated, running command");
471         run_session (seat, session);
472     }
473     else if (!IS_GREETER (session))
474     {
475         g_debug ("Switching to greeter due to failed authentication");
476         switch_to_greeter_from_failed_session (seat, session);
477     }
478     else
479     {
480         g_debug ("Stopping session that failed authentication");
481         session_stop (session);
482     }
483 }
484
485 static void
486 session_stopped_cb (Session *session, Seat *seat)
487 {
488     DisplayServer *display_server;
489
490     g_debug ("Session stopped");
491
492     display_server = session_get_display_server (session);
493
494     /* Cleanup */
495     if (!IS_GREETER (session))
496     {
497         const gchar *script;
498         script = seat_get_string_property (seat, "session-cleanup-script");
499         if (script)
500             run_script (seat, display_server, script, session_get_user (session));
501     }
502
503     g_signal_handlers_disconnect_matched (session, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, seat);
504     seat->priv->sessions = g_list_remove (seat->priv->sessions, session);
505
506     /* We were waiting for this session, but it didn't start :( */
507     // FIXME: Start a greeter on this?
508     if (session == seat->priv->session_to_activate)
509     {
510         g_object_unref (seat->priv->session_to_activate);
511         seat->priv->session_to_activate = NULL;
512     }
513
514     if (seat->priv->stopping)
515     {
516         check_stopped (seat);
517         g_object_unref (session);
518         return;
519     }
520
521     /* If this is the greeter session then re-use this display server */
522     if (IS_GREETER (session) && seat->priv->share_display_server &&
523         greeter_get_start_session (GREETER (session)))
524     {
525         GList *link;
526
527         for (link = seat->priv->sessions; link; link = link->next)
528         {
529             Session *s = link->data;
530
531             /* Skip this session and sessions on other display servers */
532             if (s == session || session_get_display_server (s) != display_server || session_get_is_stopping (s))
533                 continue;
534
535             if (session_get_is_authenticated (s))
536             {
537                 g_debug ("Greeter stopped, running session");
538                 run_session (seat, s);
539             }
540             else
541             {
542                 g_debug ("Greeter stopped, starting session authentication");
543                 start_session (seat, s);
544             }
545             break;
546         }
547     }
548     /* If this is the greeter and nothing else is running then stop the seat */
549     else if (IS_GREETER (session) &&
550         !greeter_get_start_session (GREETER (session)) &&
551         g_list_length (seat->priv->display_servers) == 1 &&
552         g_list_nth_data (seat->priv->display_servers, 0) == display_server)
553     {
554         g_debug ("Stopping seat, failed to start a greeter");
555         seat_stop (seat);
556     }
557     /* If we were the active session, switch to a greeter */
558     else if (!IS_GREETER (session) && session == seat_get_active_session (seat))
559     {
560         g_debug ("Active session stopped, starting greeter");
561         seat_switch_to_greeter (seat);
562     }
563
564     /* Stop the display server if no-longer required */
565     if (display_server && !display_server_get_is_stopping (display_server))
566     {
567         GList *link;
568         int n_sessions = 0;
569
570         for (link = seat->priv->sessions; link; link = link->next)
571         {
572             Session *s = link->data;
573             if (s == session)
574                 continue;
575             if (session_get_display_server (s) == display_server)
576                 n_sessions++;
577         }
578         if (n_sessions == 0)
579         {
580             g_debug ("Stopping display server, no sessions require it");
581             display_server_stop (display_server);
582         }
583     }
584
585     g_signal_emit (seat, signals[SESSION_REMOVED], 0, session);
586     g_object_unref (session);
587 }
588
589 static void
590 set_session_env (Session *session)
591 {
592     /* Connect using the session bus */
593     if (getuid () != 0)
594     {
595         if (g_getenv ("DBUS_SESSION_BUS_ADDRESS"))
596             session_set_env (session, "DBUS_SESSION_BUS_ADDRESS", g_getenv ("DBUS_SESSION_BUS_ADDRESS"));
597         session_set_env (session, "LDM_BUS", "SESSION");
598         if (g_getenv ("LD_PRELOAD"))
599             session_set_env (session, "LD_PRELOAD", g_getenv ("LD_PRELOAD"));
600         if (g_getenv ("LD_LIBRARY_PATH"))
601             session_set_env (session, "LD_LIBRARY_PATH", g_getenv ("LD_LIBRARY_PATH"));
602         if (g_getenv ("PATH"))
603             session_set_env (session, "PATH", g_getenv ("PATH"));
604     }
605
606     /* Variables required for regression tests */
607     if (g_getenv ("LIGHTDM_TEST_ROOT"))
608     {
609         session_set_env (session, "LIGHTDM_TEST_ROOT", g_getenv ("LIGHTDM_TEST_ROOT"));
610         session_set_env (session, "DBUS_SYSTEM_BUS_ADDRESS", g_getenv ("DBUS_SYSTEM_BUS_ADDRESS"));
611         session_set_env (session, "DBUS_SESSION_BUS_ADDRESS", g_getenv ("DBUS_SESSION_BUS_ADDRESS"));
612         session_set_env (session, "LD_PRELOAD", g_getenv ("LD_PRELOAD"));
613         session_set_env (session, "LD_LIBRARY_PATH", g_getenv ("LD_LIBRARY_PATH"));
614         session_set_env (session, "GI_TYPELIB_PATH", g_getenv ("GI_TYPELIB_PATH"));
615     }
616 }
617
618 static Session *
619 create_session (Seat *seat, gboolean autostart)
620 {
621     Session *session;
622
623     session = SEAT_GET_CLASS (seat)->create_session (seat);
624     seat->priv->sessions = g_list_append (seat->priv->sessions, session);
625     if (autostart)
626         g_signal_connect (session, "authentication-complete", G_CALLBACK (session_authentication_complete_cb), seat);
627     g_signal_connect (session, "stopped", G_CALLBACK (session_stopped_cb), seat);
628
629     set_session_env (session);
630
631     g_signal_emit (seat, signals[SESSION_ADDED], 0, session);
632
633     return session;
634 }
635
636 static gchar **
637 get_session_argv (SessionConfig *session_config, const gchar *session_wrapper)
638 {
639     gboolean result;
640     int argc;
641     gchar **argv, *path;
642     GError *error = NULL;
643
644     /* If configured, run sessions through a wrapper */
645     if (session_wrapper)
646     {
647         argv = g_malloc (sizeof (gchar *) * 3);
648         path = g_find_program_in_path (session_wrapper);
649         argv[0] = path ? path : g_strdup (session_wrapper);
650         argv[1] = g_strdup (session_config_get_command (session_config));
651         argv[2] = NULL;
652         return argv;
653     }
654
655     /* Split command into an array listing and make command absolute */
656     result = g_shell_parse_argv (session_config_get_command (session_config), &argc, &argv, &error);
657     if (error)
658         g_debug ("Invalid session command '%s': %s", session_config_get_command (session_config), error->message);
659     g_clear_error (&error);
660     if (!result)
661         return NULL;
662     path = g_find_program_in_path (argv[0]);
663     if (path)
664     {
665         g_free (argv[0]);
666         argv[0] = path;
667     }
668   
669     return argv;
670 }
671
672 static SessionConfig *
673 find_session_config (const gchar *sessions_dir, const gchar *session_name)
674 {
675     gchar **dirs;
676     SessionConfig *session_config = NULL;
677     int i;
678     GError *error = NULL;
679
680     g_return_val_if_fail (sessions_dir != NULL, NULL);
681     g_return_val_if_fail (session_name != NULL, NULL);
682
683     dirs = g_strsplit (sessions_dir, ":", -1);
684     for (i = 0; dirs[i]; i++)
685     {
686         gchar *filename, *path;
687
688         filename = g_strdup_printf ("%s.desktop", session_name);
689         path = g_build_filename (dirs[i], filename, NULL);
690         g_free (filename);
691         session_config = session_config_new_from_file (path, &error);
692         g_free (path);
693         if (session_config)
694             break;
695
696         if (dirs[i+1] == NULL)
697             g_debug ("Failed to find session configuration %s", session_name);
698         g_clear_error (&error);
699     }
700     g_strfreev (dirs);
701
702     return session_config;
703 }
704
705 static Session *
706 create_user_session (Seat *seat, const gchar *username)
707 {
708     User *user;
709     gchar *sessions_dir;
710     const gchar *session_name, *language;
711     SessionConfig *session_config;
712     Session *session = NULL;
713
714     g_debug ("Creating user session");
715
716     /* Load user preferences */
717     user = accounts_get_user_by_name (username);
718     if (!user)
719     {
720         g_debug ("Can't login unknown user '%s'", username);
721         return NULL;
722     }
723     session_name = user_get_xsession (user);
724     language = user_get_language (user);
725
726     if (!session_name)
727         session_name = seat_get_string_property (seat, "user-session");
728     sessions_dir = config_get_string (config_get_instance (), "LightDM", "sessions-directory");
729     session_config = find_session_config (sessions_dir, session_name);
730     g_free (sessions_dir);
731     if (session_config)
732     {
733         gchar **argv;
734
735         session = create_session (seat, TRUE);
736         session_set_env (session, "DESKTOP_SESSION", session_name);
737         session_set_env (session, "GDMSESSION", session_name);
738         if (language && language[0] != '\0')
739         {
740             session_set_env (session, "LANG", language);
741             session_set_env (session, "GDM_LANG", language);
742         }
743         session_set_pam_service (session, AUTOLOGIN_SERVICE);
744         session_set_username (session, username);
745         session_set_do_authenticate (session, TRUE);
746         argv = get_session_argv (session_config, seat_get_string_property (seat, "session-wrapper"));
747         session_set_argv (session, argv);
748         g_strfreev (argv);
749
750         g_object_unref (session_config);
751     }
752     else
753         g_debug ("Can't find session '%s'", seat_get_string_property (seat, "user-session"));
754
755
756     g_object_unref (user);
757
758     return session;
759 }
760
761 static Session *
762 create_guest_session (Seat *seat)
763 {
764     gchar *sessions_dir, **argv;
765     SessionConfig *session_config;
766     Session *session;
767
768     sessions_dir = config_get_string (config_get_instance (), "LightDM", "sessions-directory");
769     session_config = find_session_config (sessions_dir, seat_get_string_property (seat, "user-session"));
770     g_free (sessions_dir);
771     if (!session_config)
772     {
773         g_debug ("Can't find session '%s'", seat_get_string_property (seat, "user-session"));
774         return NULL;
775     }
776
777     session = create_session (seat, TRUE);
778     session_set_do_authenticate (session, TRUE);
779     session_set_is_guest (session, TRUE);
780     argv = get_session_argv (session_config, seat_get_string_property (seat, "session-wrapper"));
781     g_object_unref (session_config);
782     session_set_argv (session, argv);
783     g_strfreev (argv);
784   
785     return session;
786 }
787
788 static Session *
789 greeter_create_session_cb (Greeter *greeter, Seat *seat)
790 {
791     Session *session;
792
793     session = create_session (seat, FALSE);
794     session_set_display_server (session, session_get_display_server (SESSION (greeter)));
795
796     return g_object_ref (session);
797 }
798
799 static void
800 prepend_argv (gchar ***argv, const gchar *value)
801 {
802     gchar **old_argv, **new_argv;
803     gint i;
804
805     old_argv = *argv;
806     new_argv = g_malloc (sizeof (gchar *) * (g_strv_length (*argv) + 2));
807     new_argv[0] = g_strdup (value);
808     for (i = 0; old_argv[i]; i++)
809         new_argv[i + 1] = old_argv[i];
810     new_argv[i + 1] = NULL;
811
812     g_free (*argv);
813     *argv = new_argv;
814 }
815
816 static Session *
817 find_user_session (Seat *seat, const gchar *username)
818 {
819     GList *link;
820
821     if (!username)
822         return NULL;
823
824     for (link = seat->priv->sessions; link; link = link->next)
825     {
826         Session *session = link->data;
827
828         if (!session_get_is_stopping (session) && strcmp (session_get_username (session), username) == 0)
829             return session;
830     }
831
832     return NULL;
833 }
834
835 static gboolean
836 greeter_start_session_cb (Greeter *greeter, SessionType type, const gchar *session_name, Seat *seat)
837 {
838     Session *session, *existing_session;
839     const gchar *username, *language = NULL;
840     SessionConfig *session_config;
841     User *user;
842     gchar *sessions_dir = NULL;
843     gchar **argv;
844
845     /* Get the session to use */
846     if (greeter_get_guest_authenticated (greeter))
847     {
848         session = create_guest_session (seat);
849         if (!session)
850             return FALSE;
851         session_set_pam_service (session, AUTOLOGIN_SERVICE);
852     }
853     else
854         session = greeter_get_authentication_session (greeter);
855
856     /* Switch to this session when it is ready */
857     if (seat->priv->session_to_activate)
858         g_object_unref (seat->priv->session_to_activate);
859     seat->priv->session_to_activate = g_object_ref (session);
860
861     /* Return to existing session if it is open */
862     username = session_get_username (session);
863     existing_session = find_user_session (seat, username);
864     if (existing_session && session != existing_session)
865     {
866         g_debug ("Returning to existing user session %s", username);
867         session_stop (session);
868         seat_set_active_session (seat, existing_session);
869         return TRUE;
870     }
871
872     /* Get session command to run */
873     switch (type)
874     {
875     case SESSION_TYPE_LOCAL:
876         sessions_dir = config_get_string (config_get_instance (), "LightDM", "sessions-directory");
877         break;
878     case SESSION_TYPE_REMOTE:
879         sessions_dir = config_get_string (config_get_instance (), "LightDM", "remote-sessions-directory");
880         break;
881     }
882
883     /* Load user preferences */
884     user = session_get_user (session);
885     if (user)
886     {
887         if (!session_name)
888             session_name = user_get_xsession (user);
889         language = user_get_language (user);
890     }
891
892     if (!session_name)
893         session_name = seat_get_string_property (seat, "user-session");
894     if (user)
895         user_set_xsession (session_get_user (session), session_name);
896
897     session_config = find_session_config (sessions_dir, session_name);
898     g_free (sessions_dir);
899     if (!session_config)
900     {
901         g_debug ("Can't find session '%s'", seat_get_string_property (seat, "user-session"));
902         return FALSE;
903     }
904
905     argv = get_session_argv (session_config, seat_get_string_property (seat, "session-wrapper"));
906     g_object_unref (session_config);
907     session_set_argv (session, argv);
908     g_strfreev (argv);
909     session_set_env (session, "DESKTOP_SESSION", session_name);
910     session_set_env (session, "GDMSESSION", session_name);
911     if (language && language[0] != '\0')
912     {
913         session_set_env (session, "LANG", language);
914         session_set_env (session, "GDM_LANG", language);
915     }
916
917     /* If can re-use the display server, stop the greeter first */
918     if (seat->priv->share_display_server)
919     {
920         g_debug ("Stopping greeter; display server will be re-used for user session");
921
922         /* Run on the same display server after the greeter has stopped */
923         session_set_display_server (session, session_get_display_server (SESSION (greeter)));
924
925         /* Stop the greeter */
926         session_stop (SESSION (greeter));
927
928         return TRUE;
929     }
930     /* Otherwise start a new display server for this session */
931     else
932     {
933         DisplayServer *display_server;
934
935         display_server = create_display_server (seat);
936         if (!display_server_start (display_server))
937             return FALSE;
938
939         session_set_display_server (session, display_server);
940
941         return TRUE;
942     }
943 }
944
945 static Greeter *
946 create_greeter_session (Seat *seat)
947 {
948     gchar *sessions_dir, **argv;
949     SessionConfig *session_config;
950     Greeter *greeter_session;
951     gchar *greeter_user;
952     const gchar *greeter_wrapper;
953
954     g_debug ("Creating greeter session");
955
956     sessions_dir = config_get_string (config_get_instance (), "LightDM", "greeters-directory");
957     session_config = find_session_config (sessions_dir, seat_get_string_property (seat, "greeter-session"));
958     g_free (sessions_dir);
959     if (!session_config)
960         return NULL;
961
962     argv = get_session_argv (session_config, NULL);
963     greeter_wrapper = seat_get_string_property (seat, "greeter-wrapper");
964     if (greeter_wrapper)
965     {
966         gchar *path;
967         path = g_find_program_in_path (greeter_wrapper);
968         prepend_argv (&argv, path ? path : greeter_wrapper);
969         g_free (path);
970     }
971
972     greeter_session = SEAT_GET_CLASS (seat)->create_greeter_session (seat);
973     seat->priv->sessions = g_list_append (seat->priv->sessions, SESSION (greeter_session));
974     g_signal_connect (greeter_session, "authentication-complete", G_CALLBACK (session_authentication_complete_cb), seat);
975     g_signal_connect (greeter_session, "stopped", G_CALLBACK (session_stopped_cb), seat);
976   
977     set_session_env (SESSION (greeter_session));
978
979     session_set_pam_service (SESSION (greeter_session), GREETER_SERVICE);
980     greeter_user = config_get_string (config_get_instance (), "LightDM", "greeter-user");
981     session_set_username (SESSION (greeter_session), greeter_user);
982     g_free (greeter_user);
983     session_set_argv (SESSION (greeter_session), argv);
984     g_strfreev (argv);
985
986     greeter_set_pam_services (greeter_session, USER_SERVICE, AUTOLOGIN_SERVICE);
987     g_signal_connect (greeter_session, "create-session", G_CALLBACK (greeter_create_session_cb), seat);
988     g_signal_connect (greeter_session, "start-session", G_CALLBACK (greeter_start_session_cb), seat);
989
990     /* Set hints to greeter */
991     greeter_set_hint (greeter_session, "default-session", seat_get_string_property (seat, "user-session"));
992     greeter_set_allow_guest (greeter_session, seat_get_allow_guest (seat));
993     greeter_set_hint (greeter_session, "hide-users", seat_get_boolean_property (seat, "greeter-hide-users") ? "true" : "false");
994     greeter_set_hint (greeter_session, "show-manual-login", seat_get_boolean_property (seat, "greeter-show-manual-login") ? "true" : "false");
995     greeter_set_hint (greeter_session, "show-remote-login", seat_get_boolean_property (seat, "greeter-show-remote-login") ? "true" : "false");
996     greeter_set_hint (greeter_session, "has-guest-account", seat_get_allow_guest (seat) && seat_get_boolean_property (seat, "greeter-allow-guest") ? "true" : "false");
997
998     g_object_unref (session_config);
999
1000     return greeter_session;
1001 }
1002
1003 static Session *
1004 find_session_for_display_server (Seat *seat, DisplayServer *display_server)
1005 {
1006     GList *link;
1007
1008     for (link = seat->priv->sessions; link; link = link->next)
1009     {
1010         Session *session = link->data;
1011         if (session_get_display_server (session) == display_server && !session_get_is_stopping (session))
1012             return session;
1013     }
1014
1015     return NULL;
1016 }
1017
1018 static void
1019 display_server_ready_cb (DisplayServer *display_server, Seat *seat)
1020 {
1021     const gchar *script;
1022     Session *session;
1023
1024     /* Run setup script */
1025     script = seat_get_string_property (seat, "display-setup-script");
1026     if (script && !run_script (seat, display_server, script, NULL))
1027     {
1028         g_debug ("Stopping display server due to failed setup script");
1029         display_server_stop (display_server);
1030         return;
1031     }
1032
1033     /* Stop if don't need to run a session */
1034     if (!get_start_local_sessions (seat))
1035         return;
1036
1037     emit_upstart_signal ("login-session-start");
1038
1039     /* Start the session waiting for this display server */
1040     session = find_session_for_display_server (seat, display_server);
1041     if (session)
1042     {
1043         if (session_get_is_authenticated (session))
1044         {
1045             g_debug ("Display server ready, running session");
1046             run_session (seat, session);
1047         }
1048         else
1049         {
1050             g_debug ("Display server ready, starting session authentication");
1051             start_session (seat, session);
1052         }
1053     }
1054     else
1055     {
1056         g_debug ("Stopping not required display server");
1057         display_server_stop (display_server);
1058     }
1059 }
1060
1061 static DisplayServer *
1062 create_display_server (Seat *seat)
1063 {
1064     DisplayServer *display_server;
1065
1066     g_debug ("Creating display server");
1067
1068     display_server = SEAT_GET_CLASS (seat)->create_display_server (seat);
1069     seat->priv->display_servers = g_list_append (seat->priv->display_servers, display_server);
1070     g_signal_connect (display_server, "ready", G_CALLBACK (display_server_ready_cb), seat);
1071     g_signal_connect (display_server, "stopped", G_CALLBACK (display_server_stopped_cb), seat);
1072
1073     return display_server;
1074 }
1075
1076 static Greeter *
1077 find_greeter_session (Seat *seat)
1078 {
1079     GList *link;
1080
1081     for (link = seat->priv->sessions; link; link = link->next)
1082     {
1083         Session *session = link->data;
1084         if (!session_get_is_stopping (session) && IS_GREETER (session))
1085             return GREETER (session);
1086     }
1087
1088     return NULL;
1089 }
1090
1091 gboolean
1092 seat_switch_to_greeter (Seat *seat)
1093 {
1094     Greeter *greeter_session;
1095     DisplayServer *display_server;
1096
1097     g_return_val_if_fail (seat != NULL, FALSE);
1098
1099     if (!seat->priv->can_switch)
1100         return FALSE;
1101
1102     /* Switch to greeter if one open (shouldn't be though) */
1103     greeter_session = find_greeter_session (seat);
1104     if (greeter_session)
1105     {
1106         g_debug ("Switching to existing greeter");
1107         seat_set_active_session (seat, SESSION (greeter_session));
1108         return TRUE;
1109     }
1110
1111     greeter_session = create_greeter_session (seat);
1112     if (seat->priv->session_to_activate)
1113         g_object_unref (seat->priv->session_to_activate);
1114     seat->priv->session_to_activate = g_object_ref (greeter_session);
1115
1116     display_server = create_display_server (seat);
1117     session_set_display_server (SESSION (greeter_session), display_server);
1118     if (!display_server_start (display_server))
1119         return FALSE;
1120
1121     return TRUE;
1122 }
1123
1124 gboolean
1125 seat_switch_to_user (Seat *seat, const gchar *username, const gchar *session_name)
1126 {
1127     Session *session;
1128     DisplayServer *display_server;
1129
1130     g_return_val_if_fail (seat != NULL, FALSE);
1131     g_return_val_if_fail (username != NULL, FALSE);
1132
1133     if (!seat->priv->can_switch)
1134         return FALSE;
1135
1136     g_debug ("Switching to user %s", username);
1137
1138     session = find_user_session (seat, username);
1139     if (session)
1140     {
1141         g_debug ("Switching to existing user session %s", username);
1142         seat_set_active_session (seat, session);
1143         return TRUE;
1144     }
1145
1146     session = create_user_session (seat, username);
1147     if (!session)
1148         return FALSE;
1149     if (seat->priv->session_to_activate)
1150         g_object_unref (seat->priv->session_to_activate);
1151     seat->priv->session_to_activate = g_object_ref (session);
1152     session_set_pam_service (session, USER_SERVICE);
1153
1154     display_server = create_display_server (seat);
1155     session_set_display_server (session, display_server);
1156     if (!display_server_start (display_server))
1157         return FALSE;
1158
1159     return FALSE;
1160 }
1161
1162 static Session *
1163 find_guest_session (Seat *seat)
1164 {
1165     GList *link;
1166
1167     for (link = seat->priv->sessions; link; link = link->next)
1168     {
1169         Session *session = link->data;
1170         if (!session_get_is_stopping (session) && session_get_is_guest (session))
1171             return session;
1172     }
1173
1174     return NULL;
1175 }
1176
1177 gboolean
1178 seat_switch_to_guest (Seat *seat, const gchar *session_name)
1179 {
1180     Session *session;
1181     DisplayServer *display_server;
1182
1183     g_return_val_if_fail (seat != NULL, FALSE);
1184
1185     if (!seat->priv->can_switch || !seat_get_allow_guest (seat))
1186         return FALSE;
1187
1188     /* Switch to session if one open */
1189     session = find_guest_session (seat);
1190     if (session)
1191     {
1192         g_debug ("Switching to existing guest account %s", session_get_username (session));
1193         seat_set_active_session (seat, session);
1194         return TRUE;
1195     }
1196
1197     display_server = create_display_server (seat);
1198     if (!display_server_start (display_server))
1199         return FALSE;
1200
1201     session = create_guest_session (seat);
1202     if (!session)
1203         return FALSE;
1204     if (seat->priv->session_to_activate)
1205         g_object_unref (seat->priv->session_to_activate);
1206     seat->priv->session_to_activate = g_object_ref (session);
1207     session_set_pam_service (session, AUTOLOGIN_SERVICE);
1208     session_set_display_server (session, display_server);
1209
1210     return TRUE;
1211 }
1212
1213 gboolean
1214 seat_lock (Seat *seat, const gchar *username)
1215 {
1216     Greeter *greeter_session;
1217     DisplayServer *display_server;
1218
1219     g_return_val_if_fail (seat != NULL, FALSE);
1220
1221     if (!seat->priv->can_switch)
1222         return FALSE;
1223
1224     g_debug ("Locking seat");
1225
1226     /* Switch to greeter if one open (shouldn't be though) */
1227     greeter_session = find_greeter_session (seat);
1228     if (greeter_session)
1229     {
1230         g_debug ("Switching to existing greeter");
1231         seat_set_active_session (seat, SESSION (greeter_session));
1232         return TRUE;
1233     }
1234
1235     display_server = create_display_server (seat);
1236     if (!display_server_start (display_server))
1237         return FALSE;
1238
1239     greeter_session = create_greeter_session (seat);
1240     if (seat->priv->session_to_activate)
1241         g_object_unref (seat->priv->session_to_activate);
1242     seat->priv->session_to_activate = g_object_ref (greeter_session);
1243     greeter_set_hint (greeter_session, "lock-screen", "true");
1244     if (username)
1245         greeter_set_hint (greeter_session, "select-user", username);
1246     session_set_display_server (SESSION (greeter_session), display_server);
1247
1248     return TRUE;
1249 }
1250
1251 void
1252 seat_stop (Seat *seat)
1253 {
1254     g_return_if_fail (seat != NULL);
1255
1256     if (seat->priv->stopping)
1257         return;
1258
1259     g_debug ("Stopping seat");
1260     seat->priv->stopping = TRUE;
1261     SEAT_GET_CLASS (seat)->stop (seat);
1262 }
1263
1264 gboolean
1265 seat_get_is_stopping (Seat *seat)
1266 {
1267     g_return_val_if_fail (seat != NULL, FALSE);
1268     return seat->priv->stopping;
1269 }
1270
1271 static gboolean
1272 seat_real_get_start_local_sessions (Seat *seat)
1273 {
1274     return TRUE;
1275 }
1276
1277 static void
1278 seat_real_setup (Seat *seat)
1279 {
1280 }
1281
1282 static gboolean
1283 seat_real_start (Seat *seat)
1284 {
1285     const gchar *autologin_username;
1286     int autologin_timeout;
1287     gboolean autologin_guest;
1288     gboolean autologin_in_background;
1289     Session *session = NULL;
1290     DisplayServer *display_server;
1291
1292     g_debug ("Starting seat");
1293
1294     display_server = create_display_server (seat);
1295
1296     /* If this display server doesn't have a session running on it, just start it */
1297     if (!get_start_local_sessions (seat))
1298         return display_server_start (display_server);
1299
1300     /* Get autologin settings */
1301     autologin_username = seat_get_string_property (seat, "autologin-user");
1302     if (g_strcmp0 (autologin_username, "") == 0)
1303         autologin_username = NULL;
1304     autologin_timeout = seat_get_integer_property (seat, "autologin-user-timeout");
1305     autologin_guest = seat_get_boolean_property (seat, "autologin-guest");
1306     autologin_in_background = seat_get_boolean_property (seat, "autologin-in-background");
1307
1308     /* Autologin if configured */
1309     if (autologin_timeout == 0 || autologin_in_background)
1310     {
1311         if (autologin_guest)
1312             session = create_guest_session (seat);
1313         else if (autologin_username != NULL)
1314             session = create_user_session (seat, autologin_username);
1315       
1316         if (session)
1317         {
1318             if (seat->priv->session_to_activate)
1319                 g_object_unref (seat->priv->session_to_activate);
1320             seat->priv->session_to_activate = g_object_ref (session);
1321             session_set_pam_service (session, AUTOLOGIN_SERVICE);
1322         }
1323
1324         /* Load in background if required */
1325         if (autologin_in_background && session)
1326         {
1327             DisplayServer *background_display_server;
1328
1329             background_display_server = create_display_server (seat);
1330             session_set_display_server (session, background_display_server);
1331             if (!display_server_start (background_display_server))
1332                 return FALSE;
1333
1334             /* Start a greeter as well */
1335             session = NULL;
1336         }
1337     }
1338
1339     /* Fallback to a greeter */
1340     if (!session)
1341     {
1342         Greeter *greeter_session;
1343
1344         greeter_session = create_greeter_session (seat);
1345         if (seat->priv->session_to_activate)
1346             g_object_unref (seat->priv->session_to_activate);
1347         seat->priv->session_to_activate = g_object_ref (greeter_session);
1348         session = SESSION (greeter_session);
1349
1350         if (autologin_timeout)
1351         {
1352             gchar *value;
1353
1354             value = g_strdup_printf ("%d", autologin_timeout);
1355             greeter_set_hint (greeter_session, "autologin-timeout", value);
1356             g_free (value);
1357             if (autologin_username)
1358                 greeter_set_hint (greeter_session, "autologin-user", autologin_username);
1359             if (autologin_guest)
1360                 greeter_set_hint (greeter_session, "autologin-guest", "true");
1361         }
1362     }
1363
1364     /* Fail if can't start a session */
1365     if (!session)
1366     {
1367         seat_stop (seat);
1368         return FALSE;
1369     }
1370
1371     /* Start display server to show session on */
1372     session_set_display_server (session, display_server);
1373     if (!display_server_start (display_server))
1374         return FALSE;
1375
1376     return TRUE;
1377 }
1378
1379 static Greeter *
1380 seat_real_create_greeter_session (Seat *seat)
1381 {
1382     return greeter_new ();
1383 }
1384
1385 static Session *
1386 seat_real_create_session (Seat *seat)
1387 {
1388     return session_new ();
1389 }
1390
1391 static void
1392 seat_real_set_active_session (Seat *seat, Session *session)
1393 {
1394 }
1395
1396 static Session *
1397 seat_real_get_active_session (Seat *seat)
1398 {
1399     return NULL;
1400 }
1401
1402 static void
1403 seat_real_stop (Seat *seat)
1404 {
1405     GList *list, *link;
1406
1407     check_stopped (seat);
1408     if (seat->priv->stopped)
1409         return;
1410
1411     /* Stop all the display servers and sessions on the seat. Copy the list as
1412      * it might be modified if a display server / session stops during this loop */
1413     list = g_list_copy (seat->priv->display_servers);
1414     for (link = list; link; link = link->next)
1415         g_object_ref (link->data);
1416     for (link = list; link; link = link->next)
1417     {
1418         DisplayServer *display_server = link->data;
1419         if (!display_server_get_is_stopping (display_server))
1420         {
1421             g_debug ("Stopping display server");
1422             display_server_stop (display_server);
1423         }
1424     }
1425     g_list_free_full (list, g_object_unref);
1426     list = g_list_copy (seat->priv->sessions);
1427     for (link = list; link; link = link->next)
1428         g_object_ref (link->data);
1429     for (link = list; link; link = link->next)
1430     {
1431         Session *session = link->data;
1432         if (!session_get_is_stopping (session))
1433         {
1434             g_debug ("Stopping session");
1435             session_stop (session);
1436         }
1437     }
1438     g_list_free_full (list, g_object_unref);
1439 }
1440
1441 static void
1442 seat_init (Seat *seat)
1443 {
1444     seat->priv = G_TYPE_INSTANCE_GET_PRIVATE (seat, SEAT_TYPE, SeatPrivate);
1445     seat->priv->properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
1446     seat->priv->share_display_server = TRUE;
1447 }
1448
1449 static void
1450 seat_finalize (GObject *object)
1451 {
1452     Seat *self;
1453     GList *link;
1454
1455     self = SEAT (object);
1456
1457     g_hash_table_unref (self->priv->properties);
1458     for (link = self->priv->display_servers; link; link = link->next)
1459     {
1460         DisplayServer *display_server = link->data;
1461         g_signal_handlers_disconnect_matched (display_server, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, self);
1462     }  
1463     g_list_free_full (self->priv->display_servers, g_object_unref);
1464     for (link = self->priv->sessions; link; link = link->next)
1465     {
1466         Session *session = link->data;
1467         g_signal_handlers_disconnect_matched (session, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, self);
1468     }
1469     g_list_free_full (self->priv->sessions, g_object_unref);
1470     if (self->priv->session_to_activate)
1471         g_object_unref (self->priv->session_to_activate);
1472
1473     G_OBJECT_CLASS (seat_parent_class)->finalize (object);
1474 }
1475
1476 static void
1477 seat_class_init (SeatClass *klass)
1478 {
1479     GObjectClass *object_class = G_OBJECT_CLASS (klass);
1480
1481     klass->get_start_local_sessions = seat_real_get_start_local_sessions;
1482     klass->setup = seat_real_setup;
1483     klass->start = seat_real_start;
1484     klass->create_greeter_session = seat_real_create_greeter_session;
1485     klass->create_session = seat_real_create_session;
1486     klass->set_active_session = seat_real_set_active_session;
1487     klass->get_active_session = seat_real_get_active_session;
1488     klass->run_script = seat_real_run_script;
1489     klass->stop = seat_real_stop;
1490
1491     object_class->finalize = seat_finalize;
1492
1493     g_type_class_add_private (klass, sizeof (SeatPrivate));
1494
1495     signals[SESSION_ADDED] =
1496         g_signal_new ("session-added",
1497                       G_TYPE_FROM_CLASS (klass),
1498                       G_SIGNAL_RUN_LAST,
1499                       G_STRUCT_OFFSET (SeatClass, session_added),
1500                       NULL, NULL,
1501                       NULL,
1502                       G_TYPE_NONE, 1, SESSION_TYPE);
1503     signals[RUNNING_USER_SESSION] =
1504         g_signal_new ("running-user-session",
1505                       G_TYPE_FROM_CLASS (klass),
1506                       G_SIGNAL_RUN_LAST,
1507                       G_STRUCT_OFFSET (SeatClass, running_user_session),
1508                       NULL, NULL,
1509                       NULL,
1510                       G_TYPE_NONE, 1, SESSION_TYPE);
1511     signals[SESSION_REMOVED] =
1512         g_signal_new ("session-removed",
1513                       G_TYPE_FROM_CLASS (klass),
1514                       G_SIGNAL_RUN_LAST,
1515                       G_STRUCT_OFFSET (SeatClass, session_removed),
1516                       NULL, NULL,
1517                       NULL,
1518                       G_TYPE_NONE, 1, SESSION_TYPE);
1519     signals[STOPPED] =
1520         g_signal_new ("stopped",
1521                       G_TYPE_FROM_CLASS (klass),
1522                       G_SIGNAL_RUN_LAST,
1523                       G_STRUCT_OFFSET (SeatClass, stopped),
1524                       NULL, NULL,
1525                       NULL,
1526                       G_TYPE_NONE, 0);
1527 }