2 * Copyright (C) 2010-2011 Robert Ancell.
3 * Author: Robert Ancell <robert.ancell@canonical.com>
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
18 #include <glib/gi18n.h>
24 #include "configuration.h"
25 #include "display-manager.h"
26 #include "xdmcp-server.h"
27 #include "vnc-server.h"
28 #include "seat-xdmcp-session.h"
29 #include "seat-xvnc.h"
32 #include "session-child.h"
33 #include "shared-data-manager.h"
34 #include "user-list.h"
38 static gchar *config_path = NULL;
39 static GMainLoop *loop = NULL;
40 static GTimer *log_timer;
41 static int log_fd = -1;
42 static gboolean debug = FALSE;
44 static DisplayManager *display_manager = NULL;
45 static XDMCPServer *xdmcp_server = NULL;
46 static VNCServer *vnc_server = NULL;
47 static guint bus_id = 0;
48 static GDBusConnection *bus = NULL;
49 static guint reg_id = 0;
50 static GDBusNodeInfo *seat_info;
51 static GHashTable *seat_bus_entries = NULL;
52 static guint seat_index = 0;
53 static GDBusNodeInfo *session_info;
54 static GHashTable *session_bus_entries = NULL;
55 static guint session_index = 0;
56 static gint exit_code = EXIT_SUCCESS;
70 #define LIGHTDM_BUS_NAME "org.freedesktop.DisplayManager"
72 static gboolean update_login1_seat (Login1Seat *login1_seat);
75 log_cb (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer data)
80 switch (log_level & G_LOG_LEVEL_MASK)
82 case G_LOG_LEVEL_ERROR:
85 case G_LOG_LEVEL_CRITICAL:
88 case G_LOG_LEVEL_WARNING:
91 case G_LOG_LEVEL_MESSAGE:
94 case G_LOG_LEVEL_INFO:
97 case G_LOG_LEVEL_DEBUG:
105 text = g_strdup_printf ("[%+.2fs] %s %s\n", g_timer_elapsed (log_timer, NULL), prefix, message);
107 /* Log everything to a file */
111 n_written = write (log_fd, text, strlen (text));
113 ; /* Check result so compiler doesn't warn about it */
116 /* Log to stderr if requested */
118 g_printerr ("%s", text);
120 g_log_default_handler (log_domain, log_level, message, data);
128 gchar *log_dir, *path;
129 gboolean backup_logs;
131 log_timer = g_timer_new ();
134 log_dir = config_get_string (config_get_instance (), "LightDM", "log-directory");
135 path = g_build_filename (log_dir, "lightdm.log", NULL);
138 backup_logs = config_get_boolean (config_get_instance (), "LightDM", "backup-logs");
139 log_fd = log_file_open (path, backup_logs ? LOG_MODE_BACKUP_AND_TRUNCATE : LOG_MODE_APPEND);
140 fcntl (log_fd, F_SETFD, FD_CLOEXEC);
141 g_log_set_default_handler (log_cb, NULL);
143 g_debug ("Logging to %s", path);
148 get_config_sections (const gchar *seat_name)
151 GList *config_sections = NULL;
153 /* Load seat defaults first */
154 config_sections = g_list_append (config_sections, g_strdup ("Seat:*"));
156 groups = config_get_groups (config_get_instance ());
157 for (i = groups; *i; i++)
159 if (g_str_has_prefix (*i, "Seat:") && strcmp (*i, "Seat:*") != 0)
161 const gchar *seat_name_glob = *i + strlen ("Seat:");
162 if (g_pattern_match_simple (seat_name_glob, seat_name ? seat_name : ""))
163 config_sections = g_list_append (config_sections, g_strdup (*i));
168 return config_sections;
172 set_seat_properties (Seat *seat, const gchar *seat_name)
174 GList *sections, *link;
178 sections = get_config_sections (seat_name);
179 for (link = sections; link; link = link->next)
181 const gchar *section = link->data;
182 keys = config_get_keys (config_get_instance (), section);
184 l_debug (seat, "Loading properties from config section %s", section);
185 for (i = 0; keys && keys[i]; i++)
187 gchar *value = config_get_string (config_get_instance (), section, keys[i]);
188 seat_set_property (seat, keys[i], value);
193 g_list_free_full (sections, g_free);
197 signal_cb (Process *process, int signum)
199 g_debug ("Caught %s signal, shutting down", g_strsignal (signum));
200 display_manager_stop (display_manager);
201 // FIXME: Stop XDMCP server
205 display_manager_stopped_cb (DisplayManager *display_manager)
207 g_debug ("Stopping daemon");
208 g_main_loop_quit (loop);
212 display_manager_seat_removed_cb (DisplayManager *display_manager, Seat *seat)
216 Seat *next_seat = NULL;
219 /* If we have fallback types registered for the seat, let's try them
221 types = seat_get_string_list_property (seat, "type");
222 next_types = g_string_new ("");
223 for (iter = types; iter && *iter; iter++)
226 continue; // skip first one, that is our current seat type
230 next_seat = seat_new (*iter, seat_get_name (seat));
231 g_string_assign (next_types, *iter);
235 // Build up list of types to try next time
236 g_string_append_c (next_types, ';');
237 g_string_append (next_types, *iter);
244 set_seat_properties (next_seat, seat_get_name (seat));
246 // We set this manually on default seat. Let's port it over if needed.
247 if (seat_get_boolean_property (seat, "exit-on-failure"))
248 seat_set_property (next_seat, "exit-on-failure", "true");
250 seat_set_property (next_seat, "type", next_types->str);
252 display_manager_add_seat (display_manager, next_seat);
253 g_object_unref (next_seat);
255 else if (seat_get_boolean_property (seat, "exit-on-failure"))
257 g_debug ("Required seat has stopped");
258 exit_code = EXIT_FAILURE;
259 display_manager_stop (display_manager);
262 g_string_free (next_types, TRUE);
268 GVariantBuilder builder;
272 g_variant_builder_init (&builder, G_VARIANT_TYPE ("ao"));
273 g_hash_table_iter_init (&iter, seat_bus_entries);
274 while (g_hash_table_iter_next (&iter, NULL, &value))
276 SeatBusEntry *entry = value;
277 g_variant_builder_add_value (&builder, g_variant_new_object_path (entry->path));
280 return g_variant_builder_end (&builder);
284 get_session_list (const gchar *seat_path)
286 GVariantBuilder builder;
290 g_variant_builder_init (&builder, G_VARIANT_TYPE ("ao"));
292 g_hash_table_iter_init (&iter, session_bus_entries);
293 while (g_hash_table_iter_next (&iter, NULL, &value))
295 SessionBusEntry *entry = value;
296 if (seat_path == NULL || strcmp (entry->seat_path, seat_path) == 0)
297 g_variant_builder_add_value (&builder, g_variant_new_object_path (entry->path));
300 return g_variant_builder_end (&builder);
304 handle_display_manager_get_property (GDBusConnection *connection,
306 const gchar *object_path,
307 const gchar *interface_name,
308 const gchar *property_name,
312 if (g_strcmp0 (property_name, "Seats") == 0)
313 return get_seat_list ();
314 else if (g_strcmp0 (property_name, "Sessions") == 0)
315 return get_session_list (NULL);
321 handle_display_manager_call (GDBusConnection *connection,
323 const gchar *object_path,
324 const gchar *interface_name,
325 const gchar *method_name,
326 GVariant *parameters,
327 GDBusMethodInvocation *invocation,
330 if (g_strcmp0 (method_name, "AddSeat") == 0)
331 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "AddSeat is deprecated");
332 else if (g_strcmp0 (method_name, "AddLocalXSeat") == 0)
337 if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(i)")))
339 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid arguments");
343 g_variant_get (parameters, "(i)", &display_number);
345 g_debug ("Adding local X seat :%d", display_number);
347 seat = seat_new ("xremote", "xremote0"); // FIXME: What to use for a name?
350 gchar *display_number_string;
352 set_seat_properties (seat, NULL);
353 display_number_string = g_strdup_printf ("%d", display_number);
354 seat_set_property (seat, "xserver-display-number", display_number_string);
355 g_free (display_number_string);
360 // FIXME: Need to make proper error
361 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Unable to create local X seat");
365 if (display_manager_add_seat (display_manager, seat))
369 entry = g_hash_table_lookup (seat_bus_entries, seat);
370 g_dbus_method_invocation_return_value (invocation, g_variant_new ("(o)", entry->path));
372 else// FIXME: Need to make proper error
373 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Failed to start seat");
374 g_object_unref (seat);
377 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD, "Unknown method");
381 handle_seat_get_property (GDBusConnection *connection,
383 const gchar *object_path,
384 const gchar *interface_name,
385 const gchar *property_name,
389 Seat *seat = user_data;
391 if (g_strcmp0 (property_name, "CanSwitch") == 0)
392 return g_variant_new_boolean (seat_get_can_switch (seat));
393 if (g_strcmp0 (property_name, "HasGuestAccount") == 0)
394 return g_variant_new_boolean (seat_get_allow_guest (seat));
395 else if (g_strcmp0 (property_name, "Sessions") == 0)
399 entry = g_hash_table_lookup (seat_bus_entries, seat);
400 return get_session_list (entry->path);
407 handle_seat_call (GDBusConnection *connection,
409 const gchar *object_path,
410 const gchar *interface_name,
411 const gchar *method_name,
412 GVariant *parameters,
413 GDBusMethodInvocation *invocation,
416 Seat *seat = user_data;
418 if (g_strcmp0 (method_name, "SwitchToGreeter") == 0)
420 if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("()")))
421 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid arguments");
423 if (seat_switch_to_greeter (seat))
424 g_dbus_method_invocation_return_value (invocation, NULL);
425 else// FIXME: Need to make proper error
426 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Failed to switch to greeter");
428 else if (g_strcmp0 (method_name, "SwitchToUser") == 0)
430 const gchar *username, *session_name;
432 if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(ss)")))
433 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid arguments");
435 g_variant_get (parameters, "(&s&s)", &username, &session_name);
436 if (strcmp (session_name, "") == 0)
439 if (seat_switch_to_user (seat, username, session_name))
440 g_dbus_method_invocation_return_value (invocation, NULL);
441 else// FIXME: Need to make proper error
442 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Failed to switch to user");
444 else if (g_strcmp0 (method_name, "SwitchToGuest") == 0)
446 const gchar *session_name;
448 if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(s)")))
449 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid arguments");
451 g_variant_get (parameters, "(&s)", &session_name);
452 if (strcmp (session_name, "") == 0)
455 if (seat_switch_to_guest (seat, session_name))
456 g_dbus_method_invocation_return_value (invocation, NULL);
457 else// FIXME: Need to make proper error
458 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Failed to switch to guest");
460 else if (g_strcmp0 (method_name, "Lock") == 0)
462 if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("()")))
463 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid arguments");
465 /* FIXME: Should only allow locks if have a session on this seat */
466 if (seat_lock (seat, NULL))
467 g_dbus_method_invocation_return_value (invocation, NULL);
468 else// FIXME: Need to make proper error
469 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Failed to lock seat");
472 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD, "Unknown method");
476 get_seat_for_session (Session *session)
480 for (seat_link = display_manager_get_seats (display_manager); seat_link; seat_link = seat_link->next)
482 Seat *seat = seat_link->data;
485 for (session_link = seat_get_sessions (seat); session_link; session_link = session_link->next)
487 Session *s = session_link->data;
498 handle_session_get_property (GDBusConnection *connection,
500 const gchar *object_path,
501 const gchar *interface_name,
502 const gchar *property_name,
506 Session *session = user_data;
507 SessionBusEntry *entry;
509 entry = g_hash_table_lookup (session_bus_entries, session);
510 if (g_strcmp0 (property_name, "Seat") == 0)
511 return g_variant_new_object_path (entry ? entry->seat_path : "");
512 else if (g_strcmp0 (property_name, "UserName") == 0)
513 return g_variant_new_string (session_get_username (session));
519 handle_session_call (GDBusConnection *connection,
521 const gchar *object_path,
522 const gchar *interface_name,
523 const gchar *method_name,
524 GVariant *parameters,
525 GDBusMethodInvocation *invocation,
528 Session *session = user_data;
530 if (g_strcmp0 (method_name, "Lock") == 0)
534 if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("()")))
535 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid arguments");
537 seat = get_seat_for_session (session);
538 /* FIXME: Should only allow locks if have a session on this seat */
539 seat_lock (seat, session_get_username (session));
540 g_dbus_method_invocation_return_value (invocation, NULL);
543 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD, "Unknown method");
546 static SeatBusEntry *
547 seat_bus_entry_new (const gchar *path)
551 entry = g_malloc0 (sizeof (SeatBusEntry));
552 entry->path = g_strdup (path);
557 static SessionBusEntry *
558 session_bus_entry_new (const gchar *path, const gchar *seat_path)
560 SessionBusEntry *entry;
562 entry = g_malloc0 (sizeof (SessionBusEntry));
563 entry->path = g_strdup (path);
564 entry->seat_path = g_strdup (seat_path);
570 emit_object_value_changed (GDBusConnection *bus, const gchar *path, const gchar *interface_name, const gchar *property_name, GVariant *property_value)
572 GVariantBuilder builder;
573 GError *error = NULL;
575 g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
576 g_variant_builder_add (&builder, "{sv}", property_name, property_value);
578 if (!g_dbus_connection_emit_signal (bus,
581 "org.freedesktop.DBus.Properties",
583 g_variant_new ("(sa{sv}as)", interface_name, &builder, NULL),
585 g_warning ("Failed to emit PropertiesChanged signal: %s", error->message);
586 g_clear_error (&error);
590 emit_object_signal (GDBusConnection *bus, const gchar *path, const gchar *signal_name, const gchar *object_path)
592 GError *error = NULL;
594 if (!g_dbus_connection_emit_signal (bus,
597 "org.freedesktop.DisplayManager",
599 g_variant_new ("(o)", object_path),
601 g_warning ("Failed to emit %s signal on %s: %s", signal_name, path, error->message);
602 g_clear_error (&error);
606 seat_bus_entry_free (gpointer data)
608 SeatBusEntry *entry = data;
610 g_free (entry->path);
615 session_bus_entry_free (gpointer data)
617 SessionBusEntry *entry = data;
619 g_free (entry->path);
620 g_free (entry->seat_path);
625 running_user_session_cb (Seat *seat, Session *session)
627 static const GDBusInterfaceVTable session_vtable =
630 handle_session_get_property
632 SeatBusEntry *seat_entry;
633 SessionBusEntry *session_entry;
635 GError *error = NULL;
637 /* Set environment variables when session runs */
638 seat_entry = g_hash_table_lookup (seat_bus_entries, seat);
639 session_set_env (session, "XDG_SEAT_PATH", seat_entry->path);
640 path = g_strdup_printf ("/org/freedesktop/DisplayManager/Session%d", session_index);
642 session_set_env (session, "XDG_SESSION_PATH", path);
643 g_object_set_data_full (G_OBJECT (session), "XDG_SESSION_PATH", path, g_free);
645 session_entry = session_bus_entry_new (g_object_get_data (G_OBJECT (session), "XDG_SESSION_PATH"), seat_entry ? seat_entry->path : NULL);
646 g_hash_table_insert (session_bus_entries, g_object_ref (session), session_entry);
648 g_debug ("Registering session with bus path %s", session_entry->path);
650 session_entry->bus_id = g_dbus_connection_register_object (bus,
652 session_info->interfaces[0],
654 g_object_ref (session), g_object_unref,
656 if (session_entry->bus_id == 0)
657 g_warning ("Failed to register user session: %s", error->message);
658 g_clear_error (&error);
660 emit_object_value_changed (bus, "/org/freedesktop/DisplayManager", "org.freedesktop.DisplayManager", "Sessions", get_session_list (NULL));
661 emit_object_signal (bus, "/org/freedesktop/DisplayManager", "SessionAdded", session_entry->path);
663 emit_object_value_changed (bus, seat_entry->path, "org.freedesktop.DisplayManager.Seat", "Sessions", get_session_list (session_entry->seat_path));
664 emit_object_signal (bus, seat_entry->path, "SessionAdded", session_entry->path);
668 session_removed_cb (Seat *seat, Session *session)
670 SessionBusEntry *entry;
671 gchar *seat_path = NULL;
673 g_signal_handlers_disconnect_matched (session, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, seat);
675 entry = g_hash_table_lookup (session_bus_entries, session);
678 g_dbus_connection_unregister_object (bus, entry->bus_id);
679 emit_object_signal (bus, "/org/freedesktop/DisplayManager", "SessionRemoved", entry->path);
680 emit_object_signal (bus, entry->seat_path, "SessionRemoved", entry->path);
681 seat_path = g_strdup (entry->seat_path);
684 g_hash_table_remove (session_bus_entries, session);
688 emit_object_value_changed (bus, "/org/freedesktop/DisplayManager", "org.freedesktop.DisplayManager", "Sessions", get_session_list (NULL));
689 emit_object_value_changed (bus, seat_path, "org.freedesktop.DisplayManager.Seat", "Sessions", get_session_list (seat_path));
695 seat_added_cb (DisplayManager *display_manager, Seat *seat)
697 static const GDBusInterfaceVTable seat_vtable =
700 handle_seat_get_property
704 GError *error = NULL;
706 path = g_strdup_printf ("/org/freedesktop/DisplayManager/Seat%d", seat_index);
709 entry = seat_bus_entry_new (path);
711 g_hash_table_insert (seat_bus_entries, g_object_ref (seat), entry);
713 g_debug ("Registering seat with bus path %s", entry->path);
715 entry->bus_id = g_dbus_connection_register_object (bus,
717 seat_info->interfaces[0],
719 g_object_ref (seat), g_object_unref,
721 if (entry->bus_id == 0)
722 g_warning ("Failed to register seat: %s", error->message);
723 g_clear_error (&error);
725 emit_object_value_changed (bus, "/org/freedesktop/DisplayManager", "org.freedesktop.DisplayManager", "Seats", get_seat_list ());
726 emit_object_signal (bus, "/org/freedesktop/DisplayManager", "SeatAdded", entry->path);
728 g_signal_connect (seat, SEAT_SIGNAL_RUNNING_USER_SESSION, G_CALLBACK (running_user_session_cb), NULL);
729 g_signal_connect (seat, SEAT_SIGNAL_SESSION_REMOVED, G_CALLBACK (session_removed_cb), NULL);
733 seat_removed_cb (DisplayManager *display_manager, Seat *seat)
737 entry = g_hash_table_lookup (seat_bus_entries, seat);
740 g_dbus_connection_unregister_object (bus, entry->bus_id);
741 emit_object_signal (bus, "/org/freedesktop/DisplayManager", "SeatRemoved", entry->path);
744 g_hash_table_remove (seat_bus_entries, seat);
746 emit_object_value_changed (bus, "/org/freedesktop/DisplayManager", "org.freedesktop.DisplayManager", "Seats", get_seat_list ());
750 xdmcp_session_cb (XDMCPServer *server, XDMCPSession *session)
752 SeatXDMCPSession *seat;
755 seat = seat_xdmcp_session_new (session);
756 set_seat_properties (SEAT (seat), NULL);
757 result = display_manager_add_seat (display_manager, SEAT (seat));
758 g_object_unref (seat);
764 vnc_connection_cb (VNCServer *server, GSocket *connection)
768 seat = seat_xvnc_new (connection);
769 set_seat_properties (SEAT (seat), NULL);
770 display_manager_add_seat (display_manager, SEAT (seat));
771 g_object_unref (seat);
775 bus_acquired_cb (GDBusConnection *connection,
779 const gchar *display_manager_interface =
781 " <interface name='org.freedesktop.DisplayManager'>"
782 " <property name='Seats' type='ao' access='read'/>"
783 " <property name='Sessions' type='ao' access='read'/>"
784 " <method name='AddSeat'>"
785 " <arg name='type' direction='in' type='s'/>"
786 " <arg name='properties' direction='in' type='a(ss)'/>"
787 " <arg name='seat' direction='out' type='o'/>"
789 " <method name='AddLocalXSeat'>"
790 " <arg name='display-number' direction='in' type='i'/>"
791 " <arg name='seat' direction='out' type='o'/>"
793 " <signal name='SeatAdded'>"
794 " <arg name='seat' type='o'/>"
796 " <signal name='SeatRemoved'>"
797 " <arg name='seat' type='o'/>"
799 " <signal name='SessionAdded'>"
800 " <arg name='session' type='o'/>"
802 " <signal name='SessionRemoved'>"
803 " <arg name='session' type='o'/>"
807 static const GDBusInterfaceVTable display_manager_vtable =
809 handle_display_manager_call,
810 handle_display_manager_get_property
812 const gchar *seat_interface =
814 " <interface name='org.freedesktop.DisplayManager.Seat'>"
815 " <property name='CanSwitch' type='b' access='read'/>"
816 " <property name='HasGuestAccount' type='b' access='read'/>"
817 " <property name='Sessions' type='ao' access='read'/>"
818 " <method name='SwitchToGreeter'/>"
819 " <method name='SwitchToUser'>"
820 " <arg name='username' direction='in' type='s'/>"
821 " <arg name='session-name' direction='in' type='s'/>"
823 " <method name='SwitchToGuest'>"
824 " <arg name='session-name' direction='in' type='s'/>"
826 " <method name='Lock'/>"
827 " <signal name='SessionAdded'>"
828 " <arg name='session' type='o'/>"
830 " <signal name='SessionRemoved'>"
831 " <arg name='session' type='o'/>"
835 const gchar *session_interface =
837 " <interface name='org.freedesktop.DisplayManager.Session'>"
838 " <property name='Seat' type='o' access='read'/>"
839 " <property name='UserName' type='s' access='read'/>"
840 " <method name='Lock'/>"
843 GDBusNodeInfo *display_manager_info;
845 GError *error = NULL;
847 g_debug ("Acquired bus name %s", name);
851 display_manager_info = g_dbus_node_info_new_for_xml (display_manager_interface, NULL);
852 g_assert (display_manager_info != NULL);
853 seat_info = g_dbus_node_info_new_for_xml (seat_interface, NULL);
854 g_assert (seat_info != NULL);
855 session_info = g_dbus_node_info_new_for_xml (session_interface, NULL);
856 g_assert (session_info != NULL);
858 reg_id = g_dbus_connection_register_object (connection,
859 "/org/freedesktop/DisplayManager",
860 display_manager_info->interfaces[0],
861 &display_manager_vtable,
865 g_warning ("Failed to register display manager: %s", error->message);
866 g_clear_error (&error);
867 g_dbus_node_info_unref (display_manager_info);
869 seat_bus_entries = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, seat_bus_entry_free);
870 session_bus_entries = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, session_bus_entry_free);
872 g_signal_connect (display_manager, DISPLAY_MANAGER_SIGNAL_SEAT_ADDED, G_CALLBACK (seat_added_cb), NULL);
873 g_signal_connect (display_manager, DISPLAY_MANAGER_SIGNAL_SEAT_REMOVED, G_CALLBACK (seat_removed_cb), NULL);
874 for (link = display_manager_get_seats (display_manager); link; link = link->next)
875 seat_added_cb (display_manager, (Seat *) link->data);
877 display_manager_start (display_manager);
879 /* Start the XDMCP server */
880 if (config_get_boolean (config_get_instance (), "XDMCPServer", "enabled"))
882 gchar *key_name, *key = NULL, *listen_address;
884 xdmcp_server = xdmcp_server_new ();
885 if (config_has_key (config_get_instance (), "XDMCPServer", "port"))
888 port = config_get_integer (config_get_instance (), "XDMCPServer", "port");
890 xdmcp_server_set_port (xdmcp_server, port);
892 listen_address = config_get_string (config_get_instance (), "XDMCPServer", "listen-address");
893 xdmcp_server_set_listen_address (xdmcp_server, listen_address);
894 g_free (listen_address);
895 g_signal_connect (xdmcp_server, XDMCP_SERVER_SIGNAL_NEW_SESSION, G_CALLBACK (xdmcp_session_cb), NULL);
897 key_name = config_get_string (config_get_instance (), "XDMCPServer", "key");
903 GError *error = NULL;
905 path = g_build_filename (config_get_directory (config_get_instance ()), "keys.conf", NULL);
907 keys = g_key_file_new ();
908 result = g_key_file_load_from_file (keys, path, G_KEY_FILE_NONE, &error);
910 g_debug ("Error getting key %s", error->message);
911 g_clear_error (&error);
915 if (g_key_file_has_key (keys, "keyring", key_name, NULL))
916 key = g_key_file_get_string (keys, "keyring", key_name, NULL);
918 g_debug ("Key %s not defined", key_name);
921 g_key_file_free (keys);
924 xdmcp_server_set_key (xdmcp_server, key);
928 g_debug ("Starting XDMCP server on UDP/IP port %d", xdmcp_server_get_port (xdmcp_server));
929 xdmcp_server_start (xdmcp_server);
932 /* Start the VNC server */
933 if (config_get_boolean (config_get_instance (), "VNCServer", "enabled"))
937 path = g_find_program_in_path ("Xvnc");
940 gchar *listen_address;
942 vnc_server = vnc_server_new ();
943 if (config_has_key (config_get_instance (), "VNCServer", "port"))
946 port = config_get_integer (config_get_instance (), "VNCServer", "port");
948 vnc_server_set_port (vnc_server, port);
950 listen_address = config_get_string (config_get_instance (), "VNCServer", "listen-address");
951 vnc_server_set_listen_address (vnc_server, listen_address);
952 g_free (listen_address);
953 g_signal_connect (vnc_server, VNC_SERVER_SIGNAL_NEW_CONNECTION, G_CALLBACK (vnc_connection_cb), NULL);
955 g_debug ("Starting VNC server on TCP/IP port %d", vnc_server_get_port (vnc_server));
956 vnc_server_start (vnc_server);
961 g_warning ("Can't start VNC server, Xvnc is not in the path");
966 name_lost_cb (GDBusConnection *connection,
971 g_printerr ("Failed to use bus name " LIGHTDM_BUS_NAME ", do you have appropriate permissions?\n");
973 g_printerr ("Failed to get D-Bus connection\n");
979 add_login1_seat (Login1Seat *login1_seat)
981 const gchar *seat_name = login1_seat_get_id (login1_seat);
982 gchar **types = NULL, **type;
983 GList *config_sections = NULL, *link;
985 gboolean is_seat0, started = FALSE;
987 g_debug ("New seat added from logind: %s", seat_name);
988 is_seat0 = strcmp (seat_name, "seat0") == 0;
990 config_sections = get_config_sections (seat_name);
991 for (link = g_list_last (config_sections); link; link = link->prev)
993 gchar *config_section = link->data;
994 types = config_get_string_list (config_get_instance (), config_section, "type");
998 g_list_free_full (config_sections, g_free);
1000 for (type = types; !seat && type && *type; type++)
1001 seat = seat_new (*type, seat_name);
1006 set_seat_properties (seat, seat_name);
1008 if (!login1_seat_get_can_multi_session (login1_seat))
1010 g_debug ("Seat %s has property CanMultiSession=no", seat_name);
1011 /* XXX: uncomment this line after bug #1371250 is closed.
1012 seat_set_property (seat, "allow-user-switching", "false"); */
1016 seat_set_property (seat, "exit-on-failure", "true");
1019 g_debug ("Unable to create seat: %s", seat_name);
1023 started = display_manager_add_seat (display_manager, seat);
1025 g_debug ("Failed to start seat: %s", seat_name);
1028 g_object_unref (seat);
1034 remove_login1_seat (Login1Seat *login1_seat)
1038 seat = display_manager_get_seat (display_manager, login1_seat_get_id (login1_seat));
1044 seat_stopped_cb (Seat *seat, Login1Seat *login1_seat)
1046 update_login1_seat (login1_seat);
1047 g_signal_handlers_disconnect_matched (seat, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, login1_seat);
1051 update_login1_seat (Login1Seat *login1_seat)
1053 if (!config_get_boolean (config_get_instance (), "LightDM", "logind-check-graphical") ||
1054 login1_seat_get_can_graphical (login1_seat))
1058 /* Wait for existing seat to stop or ignore if we already have a valid seat */
1059 seat = display_manager_get_seat (display_manager, login1_seat_get_id (login1_seat));
1062 if (seat_get_is_stopping (seat))
1063 g_signal_connect (seat, SEAT_SIGNAL_STOPPED, G_CALLBACK (seat_stopped_cb), login1_seat);
1067 return add_login1_seat (login1_seat);
1071 remove_login1_seat (login1_seat);
1077 login1_can_graphical_changed_cb (Login1Seat *login1_seat)
1079 g_debug ("Seat %s changes graphical state to %s", login1_seat_get_id (login1_seat), login1_seat_get_can_graphical (login1_seat) ? "true" : "false");
1080 update_login1_seat (login1_seat);
1084 login1_active_session_changed_cb (Login1Seat *login1_seat, const gchar *login1_session_id)
1086 g_debug ("Seat %s changes active session to %s", login1_seat_get_id (login1_seat), login1_session_id);
1089 seat = display_manager_get_seat (display_manager, login1_seat_get_id (login1_seat));
1093 Session *active_session;
1094 active_session = seat_get_expected_active_session (seat);
1096 if (g_strcmp0 (login1_session_id, session_get_login1_session_id (active_session)) == 0)
1098 // Session is already active
1099 g_debug ("Session %s is already active", login1_session_id);
1103 active_session = seat_find_session_by_login1_id (seat, login1_session_id);
1104 if (active_session != NULL)
1106 g_debug ("Activating session %s", login1_session_id);
1107 seat_set_externally_activated_session (seat, active_session);
1115 login1_add_seat (Login1Seat *login1_seat)
1117 if (config_get_boolean (config_get_instance (), "LightDM", "logind-check-graphical"))
1118 g_signal_connect (login1_seat, "can-graphical-changed", G_CALLBACK (login1_can_graphical_changed_cb), NULL);
1120 g_signal_connect (login1_seat, LOGIN1_SIGNAL_ACTIVE_SESION_CHANGED, G_CALLBACK (login1_active_session_changed_cb), NULL);
1122 return update_login1_seat (login1_seat);
1126 login1_service_seat_added_cb (Login1Service *service, Login1Seat *login1_seat)
1128 if (login1_seat_get_can_graphical (login1_seat))
1129 g_debug ("Seat %s added from logind", login1_seat_get_id (login1_seat));
1131 g_debug ("Seat %s added from logind without graphical output", login1_seat_get_id (login1_seat));
1133 login1_add_seat (login1_seat);
1137 login1_service_seat_removed_cb (Login1Service *service, Login1Seat *login1_seat)
1139 g_debug ("Seat %s removed from logind", login1_seat_get_id (login1_seat));
1140 g_signal_handlers_disconnect_matched (login1_seat, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, login1_can_graphical_changed_cb, NULL);
1141 g_signal_handlers_disconnect_matched (login1_seat, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, login1_active_session_changed_cb, NULL);
1142 remove_login1_seat (login1_seat);
1146 main (int argc, char **argv)
1149 GOptionContext *option_context;
1152 gboolean test_mode = FALSE;
1153 gchar *pid_path = "/var/run/lightdm.pid";
1154 gchar *log_dir = NULL;
1155 gchar *run_dir = NULL;
1156 gchar *cache_dir = NULL;
1157 gchar *default_log_dir = g_strdup (LOG_DIR);
1158 gchar *default_run_dir = g_strdup (RUN_DIR);
1159 gchar *default_cache_dir = g_strdup (CACHE_DIR);
1160 gboolean show_config = FALSE, show_version = FALSE;
1161 GList *link, *messages = NULL;
1162 GOptionEntry options[] =
1164 { "config", 'c', 0, G_OPTION_ARG_STRING, &config_path,
1165 /* Help string for command line --config flag */
1166 N_("Use configuration file"), "FILE" },
1167 { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug,
1168 /* Help string for command line --debug flag */
1169 N_("Print debugging messages"), NULL },
1170 { "test-mode", 0, 0, G_OPTION_ARG_NONE, &test_mode,
1171 /* Help string for command line --test-mode flag */
1172 N_("Run as unprivileged user, skipping things that require root access"), NULL },
1173 { "pid-file", 0, 0, G_OPTION_ARG_STRING, &pid_path,
1174 /* Help string for command line --pid-file flag */
1175 N_("File to write PID into"), "FILE" },
1176 { "log-dir", 0, 0, G_OPTION_ARG_STRING, &log_dir,
1177 /* Help string for command line --log-dir flag */
1178 N_("Directory to write logs to"), "DIRECTORY" },
1179 { "run-dir", 0, 0, G_OPTION_ARG_STRING, &run_dir,
1180 /* Help string for command line --run-dir flag */
1181 N_("Directory to store running state"), "DIRECTORY" },
1182 { "cache-dir", 0, 0, G_OPTION_ARG_STRING, &cache_dir,
1183 /* Help string for command line --cache-dir flag */
1184 N_("Directory to cache information"), "DIRECTORY" },
1185 { "show-config", 0, 0, G_OPTION_ARG_NONE, &show_config,
1186 /* Help string for command line --show-config flag */
1187 N_("Show combined configuration"), NULL },
1188 { "version", 'v', 0, G_OPTION_ARG_NONE, &show_version,
1189 /* Help string for command line --version flag */
1190 N_("Show release version"), NULL },
1193 GError *error = NULL;
1195 /* When lightdm starts sessions it needs to run itself in a new mode */
1196 if (argc >= 2 && strcmp (argv[1], "--session-child") == 0)
1197 return session_child_run (argc, argv);
1199 #if !defined(GLIB_VERSION_2_36)
1202 loop = g_main_loop_new (NULL, FALSE);
1204 messages = g_list_append (messages, g_strdup_printf ("Starting Light Display Manager %s, UID=%i PID=%i", VERSION, getuid (), getpid ()));
1206 g_signal_connect (process_get_current (), PROCESS_SIGNAL_GOT_SIGNAL, G_CALLBACK (signal_cb), NULL);
1208 option_context = g_option_context_new (/* Arguments and description for --help test */
1209 _("- Display Manager"));
1210 g_option_context_add_main_entries (option_context, options, GETTEXT_PACKAGE);
1211 result = g_option_context_parse (option_context, &argc, &argv, &error);
1213 g_printerr ("%s\n", error->message);
1214 g_clear_error (&error);
1215 g_option_context_free (option_context);
1218 g_printerr (/* Text printed out when an unknown command-line argument provided */
1219 _("Run '%s --help' to see a full list of available command line options."), argv[0]);
1221 return EXIT_FAILURE;
1224 /* Show combined configuration if user requested it */
1227 GList *sources, *link;
1228 gchar **groups, *last_source, *empty_source;
1229 GHashTable *source_ids;
1232 if (!config_load_from_standard_locations (config_get_instance (), config_path, NULL))
1233 return EXIT_FAILURE;
1235 /* Number sources */
1236 sources = config_get_sources (config_get_instance ());
1237 source_ids = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
1239 for (i = 0, link = sources; link; i++, link = link->next)
1245 id = g_strdup_printf ("%c", 'A' + i);
1247 id = g_strdup_printf ("%d", i);
1248 g_hash_table_insert (source_ids, g_strdup (path), id);
1251 empty_source = g_strdup (last_source);
1252 for (i = 0; empty_source[i] != '\0'; i++)
1253 empty_source[i] = ' ';
1255 /* Print out keys */
1256 groups = config_get_groups (config_get_instance ());
1257 for (i = 0; groups[i]; i++)
1264 g_printerr ("%s [%s]\n", empty_source, groups[i]);
1266 keys = config_get_keys (config_get_instance (), groups[i]);
1267 for (j = 0; keys && keys[j]; j++)
1269 const gchar *source, *id;
1272 source = config_get_source (config_get_instance (), groups[i], keys[j]);
1273 id = source ? g_hash_table_lookup (source_ids, source) : empty_source;
1274 value = config_get_string (config_get_instance (), groups[i], keys[j]);
1275 g_printerr ("%s %s=%s\n", id, keys[j], value);
1281 g_strfreev (groups);
1283 /* Show mapping from source number to path */
1285 g_printerr ("Sources:\n");
1286 for (link = sources; link; link = link->next)
1288 const gchar *path = link->data;
1289 const gchar *source;
1291 source = g_hash_table_lookup (source_ids, path);
1292 g_printerr ("%s %s\n", source, path);
1295 g_hash_table_destroy (source_ids);
1297 return EXIT_SUCCESS;
1302 /* NOTE: Is not translated so can be easily parsed */
1303 g_printerr ("lightdm %s\n", VERSION);
1304 return EXIT_SUCCESS;
1307 if (!test_mode && getuid () != 0)
1309 g_printerr ("Only root can run Light Display Manager. To run as a regular user for testing run with the --test-mode flag.\n");
1310 return EXIT_FAILURE;
1313 /* If running inside an X server use Xephyr for display */
1314 if (getenv ("DISPLAY") && getuid () != 0)
1316 gchar *x_server_path;
1318 x_server_path = g_find_program_in_path ("Xephyr");
1321 g_printerr ("Running inside an X server requires Xephyr to be installed but it cannot be found. Please install it or update your PATH environment variable.\n");
1322 return EXIT_FAILURE;
1324 g_free (x_server_path);
1327 /* Make sure the system binary directory (where the greeters are installed) is in the path */
1330 const gchar *path = g_getenv ("PATH");
1334 new_path = g_strdup_printf ("%s:%s", path, SBIN_DIR);
1336 new_path = g_strdup (SBIN_DIR);
1337 g_setenv ("PATH", new_path, TRUE);
1341 /* Write PID file */
1342 pid_file = fopen (pid_path, "w");
1345 fprintf (pid_file, "%d\n", getpid ());
1349 /* If not running as root write output to directories we control */
1352 g_free (default_log_dir);
1353 default_log_dir = g_build_filename (g_get_user_cache_dir (), "lightdm", "log", NULL);
1354 g_free (default_run_dir);
1355 default_run_dir = g_build_filename (g_get_user_cache_dir (), "lightdm", "run", NULL);
1356 g_free (default_cache_dir);
1357 default_cache_dir = g_build_filename (g_get_user_cache_dir (), "lightdm", "cache", NULL);
1360 /* Load config file(s) */
1361 if (!config_load_from_standard_locations (config_get_instance (), config_path, &messages))
1362 exit (EXIT_FAILURE);
1363 g_free (config_path);
1365 /* Set default values */
1366 if (!config_has_key (config_get_instance (), "LightDM", "start-default-seat"))
1367 config_set_boolean (config_get_instance (), "LightDM", "start-default-seat", TRUE);
1368 if (!config_has_key (config_get_instance (), "LightDM", "minimum-vt"))
1369 config_set_integer (config_get_instance (), "LightDM", "minimum-vt", 7);
1370 if (!config_has_key (config_get_instance (), "LightDM", "guest-account-script"))
1371 config_set_string (config_get_instance (), "LightDM", "guest-account-script", "guest-account");
1372 if (!config_has_key (config_get_instance (), "LightDM", "greeter-user"))
1373 config_set_string (config_get_instance (), "LightDM", "greeter-user", GREETER_USER);
1374 if (!config_has_key (config_get_instance (), "LightDM", "lock-memory"))
1375 config_set_boolean (config_get_instance (), "LightDM", "lock-memory", TRUE);
1376 if (!config_has_key (config_get_instance (), "LightDM", "backup-logs"))
1377 config_set_boolean (config_get_instance (), "LightDM", "backup-logs", TRUE);
1378 if (!config_has_key (config_get_instance (), "Seat:*", "type"))
1379 config_set_string (config_get_instance (), "Seat:*", "type", "xlocal");
1380 if (!config_has_key (config_get_instance (), "Seat:*", "pam-service"))
1381 config_set_string (config_get_instance (), "Seat:*", "pam-service", "lightdm");
1382 if (!config_has_key (config_get_instance (), "Seat:*", "pam-autologin-service"))
1383 config_set_string (config_get_instance (), "Seat:*", "pam-autologin-service", "lightdm-autologin");
1384 if (!config_has_key (config_get_instance (), "Seat:*", "pam-greeter-service"))
1385 config_set_string (config_get_instance (), "Seat:*", "pam-greeter-service", "lightdm-greeter");
1386 if (!config_has_key (config_get_instance (), "Seat:*", "xserver-command"))
1387 config_set_string (config_get_instance (), "Seat:*", "xserver-command", "X");
1388 if (!config_has_key (config_get_instance (), "Seat:*", "xmir-command"))
1389 config_set_string (config_get_instance (), "Seat:*", "xmir-command", "Xmir");
1390 if (!config_has_key (config_get_instance (), "Seat:*", "xserver-share"))
1391 config_set_boolean (config_get_instance (), "Seat:*", "xserver-share", TRUE);
1392 if (!config_has_key (config_get_instance (), "Seat:*", "unity-compositor-command"))
1393 config_set_string (config_get_instance (), "Seat:*", "unity-compositor-command", "unity-system-compositor");
1394 if (!config_has_key (config_get_instance (), "Seat:*", "start-session"))
1395 config_set_boolean (config_get_instance (), "Seat:*", "start-session", TRUE);
1396 if (!config_has_key (config_get_instance (), "Seat:*", "allow-user-switching"))
1397 config_set_boolean (config_get_instance (), "Seat:*", "allow-user-switching", TRUE);
1398 if (!config_has_key (config_get_instance (), "Seat:*", "allow-guest"))
1399 config_set_boolean (config_get_instance (), "Seat:*", "allow-guest", TRUE);
1400 if (!config_has_key (config_get_instance (), "Seat:*", "greeter-allow-guest"))
1401 config_set_boolean (config_get_instance (), "Seat:*", "greeter-allow-guest", TRUE);
1402 if (!config_has_key (config_get_instance (), "Seat:*", "greeter-show-remote-login"))
1403 config_set_boolean (config_get_instance (), "Seat:*", "greeter-show-remote-login", TRUE);
1404 if (!config_has_key (config_get_instance (), "Seat:*", "greeter-session"))
1405 config_set_string (config_get_instance (), "Seat:*", "greeter-session", GREETER_SESSION);
1406 if (!config_has_key (config_get_instance (), "Seat:*", "user-session"))
1407 config_set_string (config_get_instance (), "Seat:*", "user-session", USER_SESSION);
1408 if (!config_has_key (config_get_instance (), "Seat:*", "session-wrapper"))
1409 config_set_string (config_get_instance (), "Seat:*", "session-wrapper", "lightdm-session");
1410 if (!config_has_key (config_get_instance (), "LightDM", "log-directory"))
1411 config_set_string (config_get_instance (), "LightDM", "log-directory", default_log_dir);
1412 g_free (default_log_dir);
1413 if (!config_has_key (config_get_instance (), "LightDM", "run-directory"))
1414 config_set_string (config_get_instance (), "LightDM", "run-directory", default_run_dir);
1415 g_free (default_run_dir);
1416 if (!config_has_key (config_get_instance (), "LightDM", "cache-directory"))
1417 config_set_string (config_get_instance (), "LightDM", "cache-directory", default_cache_dir);
1418 g_free (default_cache_dir);
1419 if (!config_has_key (config_get_instance (), "LightDM", "sessions-directory"))
1420 config_set_string (config_get_instance (), "LightDM", "sessions-directory", SESSIONS_DIR);
1421 if (!config_has_key (config_get_instance (), "LightDM", "remote-sessions-directory"))
1422 config_set_string (config_get_instance (), "LightDM", "remote-sessions-directory", REMOTE_SESSIONS_DIR);
1423 if (!config_has_key (config_get_instance (), "LightDM", "greeters-directory"))
1424 config_set_string (config_get_instance (), "LightDM", "greeters-directory", GREETERS_DIR);
1426 /* Override defaults */
1428 config_set_string (config_get_instance (), "LightDM", "log-directory", log_dir);
1431 config_set_string (config_get_instance (), "LightDM", "run-directory", run_dir);
1434 config_set_string (config_get_instance (), "LightDM", "cache-directory", cache_dir);
1437 /* Create run and cache directories */
1438 dir = config_get_string (config_get_instance (), "LightDM", "log-directory");
1439 if (g_mkdir_with_parents (dir, S_IRWXU | S_IXGRP | S_IXOTH) < 0)
1440 g_warning ("Failed to make log directory %s: %s", dir, strerror (errno));
1442 dir = config_get_string (config_get_instance (), "LightDM", "run-directory");
1443 if (g_mkdir_with_parents (dir, S_IRWXU | S_IXGRP | S_IXOTH) < 0)
1444 g_warning ("Failed to make run directory %s: %s", dir, strerror (errno));
1446 dir = config_get_string (config_get_instance (), "LightDM", "cache-directory");
1447 if (g_mkdir_with_parents (dir, S_IRWXU | S_IXGRP | S_IXOTH) < 0)
1448 g_warning ("Failed to make cache directory %s: %s", dir, strerror (errno));
1453 /* Show queued messages once logging is complete */
1454 for (link = messages; link; link = link->next)
1455 g_debug ("%s", (gchar *)link->data);
1456 g_list_free_full (messages, g_free);
1458 g_debug ("Using D-Bus name %s", LIGHTDM_BUS_NAME);
1459 bus_id = g_bus_own_name (getuid () == 0 ? G_BUS_TYPE_SYSTEM : G_BUS_TYPE_SESSION,
1461 G_BUS_NAME_OWNER_FLAGS_NONE,
1469 g_debug ("Running in user mode");
1470 if (getenv ("DISPLAY"))
1471 g_debug ("Using Xephyr for X servers");
1473 display_manager = display_manager_new ();
1474 g_signal_connect (display_manager, DISPLAY_MANAGER_SIGNAL_STOPPED, G_CALLBACK (display_manager_stopped_cb), NULL);
1475 g_signal_connect (display_manager, DISPLAY_MANAGER_SIGNAL_SEAT_REMOVED, G_CALLBACK (display_manager_seat_removed_cb), NULL);
1477 shared_data_manager_start (shared_data_manager_get_instance ());
1479 /* Connect to logind */
1480 if (login1_service_connect (login1_service_get_instance ()))
1482 /* Load dynamic seats from logind */
1483 g_debug ("Monitoring logind for seats");
1485 if (config_get_boolean (config_get_instance (), "LightDM", "start-default-seat"))
1487 g_signal_connect (login1_service_get_instance (), LOGIN1_SERVICE_SIGNAL_SEAT_ADDED, G_CALLBACK (login1_service_seat_added_cb), NULL);
1488 g_signal_connect (login1_service_get_instance (), LOGIN1_SERVICE_SIGNAL_SEAT_REMOVED, G_CALLBACK (login1_service_seat_removed_cb), NULL);
1490 for (link = login1_service_get_seats (login1_service_get_instance ()); link; link = link->next)
1492 Login1Seat *login1_seat = link->data;
1493 if (!login1_add_seat (login1_seat))
1494 return EXIT_FAILURE;
1500 if (config_get_boolean (config_get_instance (), "LightDM", "start-default-seat"))
1506 g_debug ("Adding default seat");
1508 types = config_get_string_list (config_get_instance (), "Seat:*", "type");
1509 for (type = types; type && *type; type++)
1511 seat = seat_new (*type, "seat0");
1518 set_seat_properties (seat, NULL);
1519 seat_set_property (seat, "exit-on-failure", "true");
1520 if (!display_manager_add_seat (display_manager, seat))
1521 return EXIT_FAILURE;
1522 g_object_unref (seat);
1526 g_warning ("Failed to create default seat");
1527 return EXIT_FAILURE;
1532 g_main_loop_run (loop);
1534 /* Clean up shared data manager */
1535 shared_data_manager_cleanup ();
1537 /* Clean up user list */
1538 common_user_list_cleanup ();
1540 /* Clean up display manager */
1541 g_clear_object (&display_manager);
1543 /* Remove D-Bus interface */
1544 g_dbus_connection_unregister_object (bus, reg_id);
1545 g_bus_unown_name (bus_id);
1546 if (seat_bus_entries)
1547 g_hash_table_unref (seat_bus_entries);
1548 if (session_bus_entries)
1549 g_hash_table_unref (session_bus_entries);
1551 g_debug ("Exiting with return value %d", exit_code);