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)
203 g_debug ("Caught %s signal, shutting down", g_strsignal (signum));
204 display_manager_stop (display_manager);
205 // FIXME: Stop XDMCP server
215 display_manager_stopped_cb (DisplayManager *display_manager)
217 g_debug ("Stopping daemon");
218 g_main_loop_quit (loop);
222 display_manager_seat_removed_cb (DisplayManager *display_manager, Seat *seat)
226 Seat *next_seat = NULL;
229 /* If we have fallback types registered for the seat, let's try them
231 types = seat_get_string_list_property (seat, "type");
232 next_types = g_string_new ("");
233 for (iter = types; iter && *iter; iter++)
236 continue; // skip first one, that is our current seat type
240 next_seat = seat_new (*iter, seat_get_name (seat));
241 g_string_assign (next_types, *iter);
245 // Build up list of types to try next time
246 g_string_append_c (next_types, ';');
247 g_string_append (next_types, *iter);
254 set_seat_properties (next_seat, seat_get_name (seat));
256 // We set this manually on default seat. Let's port it over if needed.
257 if (seat_get_boolean_property (seat, "exit-on-failure"))
258 seat_set_property (next_seat, "exit-on-failure", "true");
260 seat_set_property (next_seat, "type", next_types->str);
262 display_manager_add_seat (display_manager, next_seat);
263 g_object_unref (next_seat);
265 else if (seat_get_boolean_property (seat, "exit-on-failure"))
267 g_debug ("Required seat has stopped");
268 exit_code = EXIT_FAILURE;
269 display_manager_stop (display_manager);
272 g_string_free (next_types, TRUE);
278 GVariantBuilder builder;
282 g_variant_builder_init (&builder, G_VARIANT_TYPE ("ao"));
283 g_hash_table_iter_init (&iter, seat_bus_entries);
284 while (g_hash_table_iter_next (&iter, NULL, &value))
286 SeatBusEntry *entry = value;
287 g_variant_builder_add_value (&builder, g_variant_new_object_path (entry->path));
290 return g_variant_builder_end (&builder);
294 get_session_list (const gchar *seat_path)
296 GVariantBuilder builder;
300 g_variant_builder_init (&builder, G_VARIANT_TYPE ("ao"));
302 g_hash_table_iter_init (&iter, session_bus_entries);
303 while (g_hash_table_iter_next (&iter, NULL, &value))
305 SessionBusEntry *entry = value;
306 if (seat_path == NULL || strcmp (entry->seat_path, seat_path) == 0)
307 g_variant_builder_add_value (&builder, g_variant_new_object_path (entry->path));
310 return g_variant_builder_end (&builder);
314 handle_display_manager_get_property (GDBusConnection *connection,
316 const gchar *object_path,
317 const gchar *interface_name,
318 const gchar *property_name,
322 if (g_strcmp0 (property_name, "Seats") == 0)
323 return get_seat_list ();
324 else if (g_strcmp0 (property_name, "Sessions") == 0)
325 return get_session_list (NULL);
331 handle_display_manager_call (GDBusConnection *connection,
333 const gchar *object_path,
334 const gchar *interface_name,
335 const gchar *method_name,
336 GVariant *parameters,
337 GDBusMethodInvocation *invocation,
340 if (g_strcmp0 (method_name, "AddSeat") == 0)
341 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "AddSeat is deprecated");
342 else if (g_strcmp0 (method_name, "AddLocalXSeat") == 0)
347 if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(i)")))
349 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid arguments");
353 g_variant_get (parameters, "(i)", &display_number);
355 g_debug ("Adding local X seat :%d", display_number);
357 seat = seat_new ("xremote", "xremote0"); // FIXME: What to use for a name?
360 gchar *display_number_string;
362 set_seat_properties (seat, NULL);
363 display_number_string = g_strdup_printf ("%d", display_number);
364 seat_set_property (seat, "xserver-display-number", display_number_string);
365 g_free (display_number_string);
370 // FIXME: Need to make proper error
371 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Unable to create local X seat");
375 if (display_manager_add_seat (display_manager, seat))
379 entry = g_hash_table_lookup (seat_bus_entries, seat);
380 g_dbus_method_invocation_return_value (invocation, g_variant_new ("(o)", entry->path));
382 else// FIXME: Need to make proper error
383 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Failed to start seat");
384 g_object_unref (seat);
387 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD, "Unknown method");
391 handle_seat_get_property (GDBusConnection *connection,
393 const gchar *object_path,
394 const gchar *interface_name,
395 const gchar *property_name,
399 Seat *seat = user_data;
401 if (g_strcmp0 (property_name, "CanSwitch") == 0)
402 return g_variant_new_boolean (seat_get_can_switch (seat));
403 if (g_strcmp0 (property_name, "HasGuestAccount") == 0)
404 return g_variant_new_boolean (seat_get_allow_guest (seat));
405 else if (g_strcmp0 (property_name, "Sessions") == 0)
409 entry = g_hash_table_lookup (seat_bus_entries, seat);
410 return get_session_list (entry->path);
417 handle_seat_call (GDBusConnection *connection,
419 const gchar *object_path,
420 const gchar *interface_name,
421 const gchar *method_name,
422 GVariant *parameters,
423 GDBusMethodInvocation *invocation,
426 Seat *seat = user_data;
428 if (g_strcmp0 (method_name, "SwitchToGreeter") == 0)
430 if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("()")))
431 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid arguments");
433 if (seat_switch_to_greeter (seat))
434 g_dbus_method_invocation_return_value (invocation, NULL);
435 else// FIXME: Need to make proper error
436 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Failed to switch to greeter");
438 else if (g_strcmp0 (method_name, "SwitchToUser") == 0)
440 const gchar *username, *session_name;
442 if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(ss)")))
443 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid arguments");
445 g_variant_get (parameters, "(&s&s)", &username, &session_name);
446 if (strcmp (session_name, "") == 0)
449 if (seat_switch_to_user (seat, username, session_name))
450 g_dbus_method_invocation_return_value (invocation, NULL);
451 else// FIXME: Need to make proper error
452 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Failed to switch to user");
454 else if (g_strcmp0 (method_name, "SwitchToGuest") == 0)
456 const gchar *session_name;
458 if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(s)")))
459 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid arguments");
461 g_variant_get (parameters, "(&s)", &session_name);
462 if (strcmp (session_name, "") == 0)
465 if (seat_switch_to_guest (seat, session_name))
466 g_dbus_method_invocation_return_value (invocation, NULL);
467 else// FIXME: Need to make proper error
468 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Failed to switch to guest");
470 else if (g_strcmp0 (method_name, "Lock") == 0)
472 if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("()")))
473 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid arguments");
475 /* FIXME: Should only allow locks if have a session on this seat */
476 if (seat_lock (seat, NULL))
477 g_dbus_method_invocation_return_value (invocation, NULL);
478 else// FIXME: Need to make proper error
479 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Failed to lock seat");
482 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD, "Unknown method");
486 get_seat_for_session (Session *session)
490 for (seat_link = display_manager_get_seats (display_manager); seat_link; seat_link = seat_link->next)
492 Seat *seat = seat_link->data;
495 for (session_link = seat_get_sessions (seat); session_link; session_link = session_link->next)
497 Session *s = session_link->data;
508 handle_session_get_property (GDBusConnection *connection,
510 const gchar *object_path,
511 const gchar *interface_name,
512 const gchar *property_name,
516 Session *session = user_data;
517 SessionBusEntry *entry;
519 entry = g_hash_table_lookup (session_bus_entries, session);
520 if (g_strcmp0 (property_name, "Seat") == 0)
521 return g_variant_new_object_path (entry ? entry->seat_path : "");
522 else if (g_strcmp0 (property_name, "UserName") == 0)
523 return g_variant_new_string (session_get_username (session));
529 handle_session_call (GDBusConnection *connection,
531 const gchar *object_path,
532 const gchar *interface_name,
533 const gchar *method_name,
534 GVariant *parameters,
535 GDBusMethodInvocation *invocation,
538 Session *session = user_data;
540 if (g_strcmp0 (method_name, "Lock") == 0)
544 if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("()")))
545 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid arguments");
547 seat = get_seat_for_session (session);
548 /* FIXME: Should only allow locks if have a session on this seat */
549 seat_lock (seat, session_get_username (session));
550 g_dbus_method_invocation_return_value (invocation, NULL);
553 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD, "Unknown method");
556 static SeatBusEntry *
557 seat_bus_entry_new (const gchar *path)
561 entry = g_malloc0 (sizeof (SeatBusEntry));
562 entry->path = g_strdup (path);
567 static SessionBusEntry *
568 session_bus_entry_new (const gchar *path, const gchar *seat_path)
570 SessionBusEntry *entry;
572 entry = g_malloc0 (sizeof (SessionBusEntry));
573 entry->path = g_strdup (path);
574 entry->seat_path = g_strdup (seat_path);
580 emit_object_value_changed (GDBusConnection *bus, const gchar *path, const gchar *interface_name, const gchar *property_name, GVariant *property_value)
582 GVariantBuilder builder;
583 GError *error = NULL;
585 g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
586 g_variant_builder_add (&builder, "{sv}", property_name, property_value);
588 if (!g_dbus_connection_emit_signal (bus,
591 "org.freedesktop.DBus.Properties",
593 g_variant_new ("(sa{sv}as)", interface_name, &builder, NULL),
595 g_warning ("Failed to emit PropertiesChanged signal: %s", error->message);
596 g_clear_error (&error);
600 emit_object_signal (GDBusConnection *bus, const gchar *path, const gchar *signal_name, const gchar *object_path)
602 GError *error = NULL;
604 if (!g_dbus_connection_emit_signal (bus,
607 "org.freedesktop.DisplayManager",
609 g_variant_new ("(o)", object_path),
611 g_warning ("Failed to emit %s signal on %s: %s", signal_name, path, error->message);
612 g_clear_error (&error);
616 seat_bus_entry_free (gpointer data)
618 SeatBusEntry *entry = data;
620 g_free (entry->path);
625 session_bus_entry_free (gpointer data)
627 SessionBusEntry *entry = data;
629 g_free (entry->path);
630 g_free (entry->seat_path);
635 running_user_session_cb (Seat *seat, Session *session)
637 static const GDBusInterfaceVTable session_vtable =
640 handle_session_get_property
642 SeatBusEntry *seat_entry;
643 SessionBusEntry *session_entry;
645 GError *error = NULL;
647 /* Set environment variables when session runs */
648 seat_entry = g_hash_table_lookup (seat_bus_entries, seat);
649 session_set_env (session, "XDG_SEAT_PATH", seat_entry->path);
650 path = g_strdup_printf ("/org/freedesktop/DisplayManager/Session%d", session_index);
652 session_set_env (session, "XDG_SESSION_PATH", path);
653 g_object_set_data_full (G_OBJECT (session), "XDG_SESSION_PATH", path, g_free);
655 session_entry = session_bus_entry_new (g_object_get_data (G_OBJECT (session), "XDG_SESSION_PATH"), seat_entry ? seat_entry->path : NULL);
656 g_hash_table_insert (session_bus_entries, g_object_ref (session), session_entry);
658 g_debug ("Registering session with bus path %s", session_entry->path);
660 session_entry->bus_id = g_dbus_connection_register_object (bus,
662 session_info->interfaces[0],
664 g_object_ref (session), g_object_unref,
666 if (session_entry->bus_id == 0)
667 g_warning ("Failed to register user session: %s", error->message);
668 g_clear_error (&error);
670 emit_object_value_changed (bus, "/org/freedesktop/DisplayManager", "org.freedesktop.DisplayManager", "Sessions", get_session_list (NULL));
671 emit_object_signal (bus, "/org/freedesktop/DisplayManager", "SessionAdded", session_entry->path);
673 emit_object_value_changed (bus, seat_entry->path, "org.freedesktop.DisplayManager.Seat", "Sessions", get_session_list (session_entry->seat_path));
674 emit_object_signal (bus, seat_entry->path, "SessionAdded", session_entry->path);
678 session_removed_cb (Seat *seat, Session *session)
680 SessionBusEntry *entry;
681 gchar *seat_path = NULL;
683 g_signal_handlers_disconnect_matched (session, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, seat);
685 entry = g_hash_table_lookup (session_bus_entries, session);
688 g_dbus_connection_unregister_object (bus, entry->bus_id);
689 emit_object_signal (bus, "/org/freedesktop/DisplayManager", "SessionRemoved", entry->path);
690 emit_object_signal (bus, entry->seat_path, "SessionRemoved", entry->path);
691 seat_path = g_strdup (entry->seat_path);
694 g_hash_table_remove (session_bus_entries, session);
698 emit_object_value_changed (bus, "/org/freedesktop/DisplayManager", "org.freedesktop.DisplayManager", "Sessions", get_session_list (NULL));
699 emit_object_value_changed (bus, seat_path, "org.freedesktop.DisplayManager.Seat", "Sessions", get_session_list (seat_path));
705 seat_added_cb (DisplayManager *display_manager, Seat *seat)
707 static const GDBusInterfaceVTable seat_vtable =
710 handle_seat_get_property
714 GError *error = NULL;
716 path = g_strdup_printf ("/org/freedesktop/DisplayManager/Seat%d", seat_index);
719 entry = seat_bus_entry_new (path);
721 g_hash_table_insert (seat_bus_entries, g_object_ref (seat), entry);
723 g_debug ("Registering seat with bus path %s", entry->path);
725 entry->bus_id = g_dbus_connection_register_object (bus,
727 seat_info->interfaces[0],
729 g_object_ref (seat), g_object_unref,
731 if (entry->bus_id == 0)
732 g_warning ("Failed to register seat: %s", error->message);
733 g_clear_error (&error);
735 emit_object_value_changed (bus, "/org/freedesktop/DisplayManager", "org.freedesktop.DisplayManager", "Seats", get_seat_list ());
736 emit_object_signal (bus, "/org/freedesktop/DisplayManager", "SeatAdded", entry->path);
738 g_signal_connect (seat, SEAT_SIGNAL_RUNNING_USER_SESSION, G_CALLBACK (running_user_session_cb), NULL);
739 g_signal_connect (seat, SEAT_SIGNAL_SESSION_REMOVED, G_CALLBACK (session_removed_cb), NULL);
743 seat_removed_cb (DisplayManager *display_manager, Seat *seat)
747 entry = g_hash_table_lookup (seat_bus_entries, seat);
750 g_dbus_connection_unregister_object (bus, entry->bus_id);
751 emit_object_signal (bus, "/org/freedesktop/DisplayManager", "SeatRemoved", entry->path);
754 g_hash_table_remove (seat_bus_entries, seat);
756 emit_object_value_changed (bus, "/org/freedesktop/DisplayManager", "org.freedesktop.DisplayManager", "Seats", get_seat_list ());
760 xdmcp_session_cb (XDMCPServer *server, XDMCPSession *session)
762 SeatXDMCPSession *seat;
765 seat = seat_xdmcp_session_new (session);
766 set_seat_properties (SEAT (seat), NULL);
767 result = display_manager_add_seat (display_manager, SEAT (seat));
768 g_object_unref (seat);
774 vnc_connection_cb (VNCServer *server, GSocket *connection)
778 seat = seat_xvnc_new (connection);
779 set_seat_properties (SEAT (seat), NULL);
780 display_manager_add_seat (display_manager, SEAT (seat));
781 g_object_unref (seat);
785 bus_acquired_cb (GDBusConnection *connection,
789 const gchar *display_manager_interface =
791 " <interface name='org.freedesktop.DisplayManager'>"
792 " <property name='Seats' type='ao' access='read'/>"
793 " <property name='Sessions' type='ao' access='read'/>"
794 " <method name='AddSeat'>"
795 " <arg name='type' direction='in' type='s'/>"
796 " <arg name='properties' direction='in' type='a(ss)'/>"
797 " <arg name='seat' direction='out' type='o'/>"
799 " <method name='AddLocalXSeat'>"
800 " <arg name='display-number' direction='in' type='i'/>"
801 " <arg name='seat' direction='out' type='o'/>"
803 " <signal name='SeatAdded'>"
804 " <arg name='seat' type='o'/>"
806 " <signal name='SeatRemoved'>"
807 " <arg name='seat' type='o'/>"
809 " <signal name='SessionAdded'>"
810 " <arg name='session' type='o'/>"
812 " <signal name='SessionRemoved'>"
813 " <arg name='session' type='o'/>"
817 static const GDBusInterfaceVTable display_manager_vtable =
819 handle_display_manager_call,
820 handle_display_manager_get_property
822 const gchar *seat_interface =
824 " <interface name='org.freedesktop.DisplayManager.Seat'>"
825 " <property name='CanSwitch' type='b' access='read'/>"
826 " <property name='HasGuestAccount' type='b' access='read'/>"
827 " <property name='Sessions' type='ao' access='read'/>"
828 " <method name='SwitchToGreeter'/>"
829 " <method name='SwitchToUser'>"
830 " <arg name='username' direction='in' type='s'/>"
831 " <arg name='session-name' direction='in' type='s'/>"
833 " <method name='SwitchToGuest'>"
834 " <arg name='session-name' direction='in' type='s'/>"
836 " <method name='Lock'/>"
837 " <signal name='SessionAdded'>"
838 " <arg name='session' type='o'/>"
840 " <signal name='SessionRemoved'>"
841 " <arg name='session' type='o'/>"
845 const gchar *session_interface =
847 " <interface name='org.freedesktop.DisplayManager.Session'>"
848 " <property name='Seat' type='o' access='read'/>"
849 " <property name='UserName' type='s' access='read'/>"
850 " <method name='Lock'/>"
853 GDBusNodeInfo *display_manager_info;
855 GError *error = NULL;
857 g_debug ("Acquired bus name %s", name);
861 display_manager_info = g_dbus_node_info_new_for_xml (display_manager_interface, NULL);
862 g_assert (display_manager_info != NULL);
863 seat_info = g_dbus_node_info_new_for_xml (seat_interface, NULL);
864 g_assert (seat_info != NULL);
865 session_info = g_dbus_node_info_new_for_xml (session_interface, NULL);
866 g_assert (session_info != NULL);
868 reg_id = g_dbus_connection_register_object (connection,
869 "/org/freedesktop/DisplayManager",
870 display_manager_info->interfaces[0],
871 &display_manager_vtable,
875 g_warning ("Failed to register display manager: %s", error->message);
876 g_clear_error (&error);
877 g_dbus_node_info_unref (display_manager_info);
879 seat_bus_entries = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, seat_bus_entry_free);
880 session_bus_entries = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, session_bus_entry_free);
882 g_signal_connect (display_manager, DISPLAY_MANAGER_SIGNAL_SEAT_ADDED, G_CALLBACK (seat_added_cb), NULL);
883 g_signal_connect (display_manager, DISPLAY_MANAGER_SIGNAL_SEAT_REMOVED, G_CALLBACK (seat_removed_cb), NULL);
884 for (link = display_manager_get_seats (display_manager); link; link = link->next)
885 seat_added_cb (display_manager, (Seat *) link->data);
887 display_manager_start (display_manager);
889 /* Start the XDMCP server */
890 if (config_get_boolean (config_get_instance (), "XDMCPServer", "enabled"))
892 gchar *key_name, *key = NULL, *listen_address, *hostname;
894 xdmcp_server = xdmcp_server_new ();
895 if (config_has_key (config_get_instance (), "XDMCPServer", "port"))
898 port = config_get_integer (config_get_instance (), "XDMCPServer", "port");
900 xdmcp_server_set_port (xdmcp_server, port);
902 listen_address = config_get_string (config_get_instance (), "XDMCPServer", "listen-address");
903 xdmcp_server_set_listen_address (xdmcp_server, listen_address);
904 g_free (listen_address);
905 hostname = config_get_string (config_get_instance (), "XDMCPServer", "hostname");
906 xdmcp_server_set_hostname (xdmcp_server, hostname);
908 g_signal_connect (xdmcp_server, XDMCP_SERVER_SIGNAL_NEW_SESSION, G_CALLBACK (xdmcp_session_cb), NULL);
910 key_name = config_get_string (config_get_instance (), "XDMCPServer", "key");
916 GError *error = NULL;
918 path = g_build_filename (config_get_directory (config_get_instance ()), "keys.conf", NULL);
920 keys = g_key_file_new ();
921 result = g_key_file_load_from_file (keys, path, G_KEY_FILE_NONE, &error);
923 g_warning ("Unable to load keys from %s: %s", path, error->message);
924 g_clear_error (&error);
928 if (g_key_file_has_key (keys, "keyring", key_name, NULL))
929 key = g_key_file_get_string (keys, "keyring", key_name, NULL);
931 g_warning ("Key %s not defined", key_name);
934 g_key_file_free (keys);
937 xdmcp_server_set_key (xdmcp_server, key);
941 if (key_name && !key)
943 exit_code = EXIT_FAILURE;
944 display_manager_stop (display_manager);
949 g_debug ("Starting XDMCP server on UDP/IP port %d", xdmcp_server_get_port (xdmcp_server));
950 xdmcp_server_start (xdmcp_server);
954 /* Start the VNC server */
955 if (config_get_boolean (config_get_instance (), "VNCServer", "enabled"))
959 path = g_find_program_in_path ("Xvnc");
962 gchar *listen_address;
964 vnc_server = vnc_server_new ();
965 if (config_has_key (config_get_instance (), "VNCServer", "port"))
968 port = config_get_integer (config_get_instance (), "VNCServer", "port");
970 vnc_server_set_port (vnc_server, port);
972 listen_address = config_get_string (config_get_instance (), "VNCServer", "listen-address");
973 vnc_server_set_listen_address (vnc_server, listen_address);
974 g_free (listen_address);
975 g_signal_connect (vnc_server, VNC_SERVER_SIGNAL_NEW_CONNECTION, G_CALLBACK (vnc_connection_cb), NULL);
977 g_debug ("Starting VNC server on TCP/IP port %d", vnc_server_get_port (vnc_server));
978 vnc_server_start (vnc_server);
983 g_warning ("Can't start VNC server, Xvnc is not in the path");
988 name_lost_cb (GDBusConnection *connection,
993 g_printerr ("Failed to use bus name " LIGHTDM_BUS_NAME ", do you have appropriate permissions?\n");
995 g_printerr ("Failed to get D-Bus connection\n");
1001 add_login1_seat (Login1Seat *login1_seat)
1003 const gchar *seat_name = login1_seat_get_id (login1_seat);
1004 gchar **types = NULL, **type;
1005 GList *config_sections = NULL, *link;
1007 gboolean is_seat0, started = FALSE;
1009 g_debug ("New seat added from logind: %s", seat_name);
1010 is_seat0 = strcmp (seat_name, "seat0") == 0;
1012 config_sections = get_config_sections (seat_name);
1013 for (link = g_list_last (config_sections); link; link = link->prev)
1015 gchar *config_section = link->data;
1016 types = config_get_string_list (config_get_instance (), config_section, "type");
1020 g_list_free_full (config_sections, g_free);
1022 for (type = types; !seat && type && *type; type++)
1023 seat = seat_new (*type, seat_name);
1028 set_seat_properties (seat, seat_name);
1030 if (!login1_seat_get_can_multi_session (login1_seat))
1032 g_debug ("Seat %s has property CanMultiSession=no", seat_name);
1033 /* XXX: uncomment this line after bug #1371250 is closed.
1034 seat_set_property (seat, "allow-user-switching", "false"); */
1038 seat_set_property (seat, "exit-on-failure", "true");
1041 g_debug ("Unable to create seat: %s", seat_name);
1045 started = display_manager_add_seat (display_manager, seat);
1047 g_debug ("Failed to start seat: %s", seat_name);
1050 g_object_unref (seat);
1056 remove_login1_seat (Login1Seat *login1_seat)
1060 seat = display_manager_get_seat (display_manager, login1_seat_get_id (login1_seat));
1066 seat_stopped_cb (Seat *seat, Login1Seat *login1_seat)
1068 update_login1_seat (login1_seat);
1069 g_signal_handlers_disconnect_matched (seat, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, login1_seat);
1073 update_login1_seat (Login1Seat *login1_seat)
1075 if (!config_get_boolean (config_get_instance (), "LightDM", "logind-check-graphical") ||
1076 login1_seat_get_can_graphical (login1_seat))
1080 /* Wait for existing seat to stop or ignore if we already have a valid seat */
1081 seat = display_manager_get_seat (display_manager, login1_seat_get_id (login1_seat));
1084 if (seat_get_is_stopping (seat))
1085 g_signal_connect (seat, SEAT_SIGNAL_STOPPED, G_CALLBACK (seat_stopped_cb), login1_seat);
1089 return add_login1_seat (login1_seat);
1093 remove_login1_seat (login1_seat);
1099 login1_can_graphical_changed_cb (Login1Seat *login1_seat)
1101 g_debug ("Seat %s changes graphical state to %s", login1_seat_get_id (login1_seat), login1_seat_get_can_graphical (login1_seat) ? "true" : "false");
1102 update_login1_seat (login1_seat);
1106 login1_active_session_changed_cb (Login1Seat *login1_seat, const gchar *login1_session_id)
1108 g_debug ("Seat %s changes active session to %s", login1_seat_get_id (login1_seat), login1_session_id);
1111 seat = display_manager_get_seat (display_manager, login1_seat_get_id (login1_seat));
1115 Session *active_session;
1116 active_session = seat_get_expected_active_session (seat);
1118 if (g_strcmp0 (login1_session_id, session_get_login1_session_id (active_session)) == 0)
1120 // Session is already active
1121 g_debug ("Session %s is already active", login1_session_id);
1125 active_session = seat_find_session_by_login1_id (seat, login1_session_id);
1126 if (active_session != NULL)
1128 g_debug ("Activating session %s", login1_session_id);
1129 seat_set_externally_activated_session (seat, active_session);
1137 login1_add_seat (Login1Seat *login1_seat)
1139 if (config_get_boolean (config_get_instance (), "LightDM", "logind-check-graphical"))
1140 g_signal_connect (login1_seat, "can-graphical-changed", G_CALLBACK (login1_can_graphical_changed_cb), NULL);
1142 g_signal_connect (login1_seat, LOGIN1_SIGNAL_ACTIVE_SESION_CHANGED, G_CALLBACK (login1_active_session_changed_cb), NULL);
1144 return update_login1_seat (login1_seat);
1148 login1_service_seat_added_cb (Login1Service *service, Login1Seat *login1_seat)
1150 if (login1_seat_get_can_graphical (login1_seat))
1151 g_debug ("Seat %s added from logind", login1_seat_get_id (login1_seat));
1153 g_debug ("Seat %s added from logind without graphical output", login1_seat_get_id (login1_seat));
1155 login1_add_seat (login1_seat);
1159 login1_service_seat_removed_cb (Login1Service *service, Login1Seat *login1_seat)
1161 g_debug ("Seat %s removed from logind", login1_seat_get_id (login1_seat));
1162 g_signal_handlers_disconnect_matched (login1_seat, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, login1_can_graphical_changed_cb, NULL);
1163 g_signal_handlers_disconnect_matched (login1_seat, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, login1_active_session_changed_cb, NULL);
1164 remove_login1_seat (login1_seat);
1168 main (int argc, char **argv)
1171 GOptionContext *option_context;
1174 gboolean test_mode = FALSE;
1175 gchar *pid_path = "/var/run/lightdm.pid";
1176 gchar *log_dir = NULL;
1177 gchar *run_dir = NULL;
1178 gchar *cache_dir = NULL;
1179 gchar *default_log_dir = g_strdup (LOG_DIR);
1180 gchar *default_run_dir = g_strdup (RUN_DIR);
1181 gchar *default_cache_dir = g_strdup (CACHE_DIR);
1182 gboolean show_config = FALSE, show_version = FALSE;
1183 GList *link, *messages = NULL;
1184 GOptionEntry options[] =
1186 { "config", 'c', 0, G_OPTION_ARG_STRING, &config_path,
1187 /* Help string for command line --config flag */
1188 N_("Use configuration file"), "FILE" },
1189 { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug,
1190 /* Help string for command line --debug flag */
1191 N_("Print debugging messages"), NULL },
1192 { "test-mode", 0, 0, G_OPTION_ARG_NONE, &test_mode,
1193 /* Help string for command line --test-mode flag */
1194 N_("Run as unprivileged user, skipping things that require root access"), NULL },
1195 { "pid-file", 0, 0, G_OPTION_ARG_STRING, &pid_path,
1196 /* Help string for command line --pid-file flag */
1197 N_("File to write PID into"), "FILE" },
1198 { "log-dir", 0, 0, G_OPTION_ARG_STRING, &log_dir,
1199 /* Help string for command line --log-dir flag */
1200 N_("Directory to write logs to"), "DIRECTORY" },
1201 { "run-dir", 0, 0, G_OPTION_ARG_STRING, &run_dir,
1202 /* Help string for command line --run-dir flag */
1203 N_("Directory to store running state"), "DIRECTORY" },
1204 { "cache-dir", 0, 0, G_OPTION_ARG_STRING, &cache_dir,
1205 /* Help string for command line --cache-dir flag */
1206 N_("Directory to cache information"), "DIRECTORY" },
1207 { "show-config", 0, 0, G_OPTION_ARG_NONE, &show_config,
1208 /* Help string for command line --show-config flag */
1209 N_("Show combined configuration"), NULL },
1210 { "version", 'v', 0, G_OPTION_ARG_NONE, &show_version,
1211 /* Help string for command line --version flag */
1212 N_("Show release version"), NULL },
1215 GError *error = NULL;
1217 /* When lightdm starts sessions it needs to run itself in a new mode */
1218 if (argc >= 2 && strcmp (argv[1], "--session-child") == 0)
1219 return session_child_run (argc, argv);
1221 #if !defined(GLIB_VERSION_2_36)
1224 loop = g_main_loop_new (NULL, FALSE);
1226 messages = g_list_append (messages, g_strdup_printf ("Starting Light Display Manager %s, UID=%i PID=%i", VERSION, getuid (), getpid ()));
1228 g_signal_connect (process_get_current (), PROCESS_SIGNAL_GOT_SIGNAL, G_CALLBACK (signal_cb), NULL);
1230 option_context = g_option_context_new (/* Arguments and description for --help test */
1231 _("- Display Manager"));
1232 g_option_context_add_main_entries (option_context, options, GETTEXT_PACKAGE);
1233 result = g_option_context_parse (option_context, &argc, &argv, &error);
1235 g_printerr ("%s\n", error->message);
1236 g_clear_error (&error);
1237 g_option_context_free (option_context);
1240 g_printerr (/* Text printed out when an unknown command-line argument provided */
1241 _("Run '%s --help' to see a full list of available command line options."), argv[0]);
1243 return EXIT_FAILURE;
1246 /* Show combined configuration if user requested it */
1249 GList *sources, *link;
1250 gchar **groups, *last_source, *empty_source;
1251 GHashTable *source_ids;
1254 if (!config_load_from_standard_locations (config_get_instance (), config_path, NULL))
1255 return EXIT_FAILURE;
1257 /* Number sources */
1258 sources = config_get_sources (config_get_instance ());
1259 source_ids = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
1261 for (i = 0, link = sources; link; i++, link = link->next)
1267 id = g_strdup_printf ("%c", 'A' + i);
1269 id = g_strdup_printf ("%d", i);
1270 g_hash_table_insert (source_ids, g_strdup (path), id);
1273 empty_source = g_strdup (last_source);
1274 for (i = 0; empty_source[i] != '\0'; i++)
1275 empty_source[i] = ' ';
1277 /* Print out keys */
1278 groups = config_get_groups (config_get_instance ());
1279 for (i = 0; groups[i]; i++)
1286 g_printerr ("%s [%s]\n", empty_source, groups[i]);
1288 keys = config_get_keys (config_get_instance (), groups[i]);
1289 for (j = 0; keys && keys[j]; j++)
1291 const gchar *source, *id;
1294 source = config_get_source (config_get_instance (), groups[i], keys[j]);
1295 id = source ? g_hash_table_lookup (source_ids, source) : empty_source;
1296 value = config_get_string (config_get_instance (), groups[i], keys[j]);
1297 g_printerr ("%s %s=%s\n", id, keys[j], value);
1303 g_strfreev (groups);
1305 /* Show mapping from source number to path */
1307 g_printerr ("Sources:\n");
1308 for (link = sources; link; link = link->next)
1310 const gchar *path = link->data;
1311 const gchar *source;
1313 source = g_hash_table_lookup (source_ids, path);
1314 g_printerr ("%s %s\n", source, path);
1317 g_hash_table_destroy (source_ids);
1319 return EXIT_SUCCESS;
1324 /* NOTE: Is not translated so can be easily parsed */
1325 g_printerr ("lightdm %s\n", VERSION);
1326 return EXIT_SUCCESS;
1329 if (!test_mode && getuid () != 0)
1331 g_printerr ("Only root can run Light Display Manager. To run as a regular user for testing run with the --test-mode flag.\n");
1332 return EXIT_FAILURE;
1335 /* If running inside an X server use Xephyr for display */
1336 if (getenv ("DISPLAY") && getuid () != 0)
1338 gchar *x_server_path;
1340 x_server_path = g_find_program_in_path ("Xephyr");
1343 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");
1344 return EXIT_FAILURE;
1346 g_free (x_server_path);
1349 /* Make sure the system binary directory (where the greeters are installed) is in the path */
1352 const gchar *path = g_getenv ("PATH");
1356 new_path = g_strdup_printf ("%s:%s", path, SBIN_DIR);
1358 new_path = g_strdup (SBIN_DIR);
1359 g_setenv ("PATH", new_path, TRUE);
1363 /* Write PID file */
1364 pid_file = fopen (pid_path, "w");
1367 fprintf (pid_file, "%d\n", getpid ());
1371 /* If not running as root write output to directories we control */
1374 g_free (default_log_dir);
1375 default_log_dir = g_build_filename (g_get_user_cache_dir (), "lightdm", "log", NULL);
1376 g_free (default_run_dir);
1377 default_run_dir = g_build_filename (g_get_user_cache_dir (), "lightdm", "run", NULL);
1378 g_free (default_cache_dir);
1379 default_cache_dir = g_build_filename (g_get_user_cache_dir (), "lightdm", "cache", NULL);
1382 /* Load config file(s) */
1383 if (!config_load_from_standard_locations (config_get_instance (), config_path, &messages))
1384 exit (EXIT_FAILURE);
1385 g_free (config_path);
1387 /* Set default values */
1388 if (!config_has_key (config_get_instance (), "LightDM", "start-default-seat"))
1389 config_set_boolean (config_get_instance (), "LightDM", "start-default-seat", TRUE);
1390 if (!config_has_key (config_get_instance (), "LightDM", "minimum-vt"))
1391 config_set_integer (config_get_instance (), "LightDM", "minimum-vt", 7);
1392 if (!config_has_key (config_get_instance (), "LightDM", "guest-account-script"))
1393 config_set_string (config_get_instance (), "LightDM", "guest-account-script", "guest-account");
1394 if (!config_has_key (config_get_instance (), "LightDM", "greeter-user"))
1395 config_set_string (config_get_instance (), "LightDM", "greeter-user", GREETER_USER);
1396 if (!config_has_key (config_get_instance (), "LightDM", "lock-memory"))
1397 config_set_boolean (config_get_instance (), "LightDM", "lock-memory", TRUE);
1398 if (!config_has_key (config_get_instance (), "LightDM", "backup-logs"))
1399 config_set_boolean (config_get_instance (), "LightDM", "backup-logs", TRUE);
1400 if (!config_has_key (config_get_instance (), "Seat:*", "type"))
1401 config_set_string (config_get_instance (), "Seat:*", "type", "xlocal");
1402 if (!config_has_key (config_get_instance (), "Seat:*", "pam-service"))
1403 config_set_string (config_get_instance (), "Seat:*", "pam-service", "lightdm");
1404 if (!config_has_key (config_get_instance (), "Seat:*", "pam-autologin-service"))
1405 config_set_string (config_get_instance (), "Seat:*", "pam-autologin-service", "lightdm-autologin");
1406 if (!config_has_key (config_get_instance (), "Seat:*", "pam-greeter-service"))
1407 config_set_string (config_get_instance (), "Seat:*", "pam-greeter-service", "lightdm-greeter");
1408 if (!config_has_key (config_get_instance (), "Seat:*", "xserver-command"))
1409 config_set_string (config_get_instance (), "Seat:*", "xserver-command", "X");
1410 if (!config_has_key (config_get_instance (), "Seat:*", "xmir-command"))
1411 config_set_string (config_get_instance (), "Seat:*", "xmir-command", "Xmir");
1412 if (!config_has_key (config_get_instance (), "Seat:*", "xserver-share"))
1413 config_set_boolean (config_get_instance (), "Seat:*", "xserver-share", TRUE);
1414 if (!config_has_key (config_get_instance (), "Seat:*", "unity-compositor-command"))
1415 config_set_string (config_get_instance (), "Seat:*", "unity-compositor-command", "unity-system-compositor");
1416 if (!config_has_key (config_get_instance (), "Seat:*", "start-session"))
1417 config_set_boolean (config_get_instance (), "Seat:*", "start-session", TRUE);
1418 if (!config_has_key (config_get_instance (), "Seat:*", "allow-user-switching"))
1419 config_set_boolean (config_get_instance (), "Seat:*", "allow-user-switching", TRUE);
1420 if (!config_has_key (config_get_instance (), "Seat:*", "allow-guest"))
1421 config_set_boolean (config_get_instance (), "Seat:*", "allow-guest", TRUE);
1422 if (!config_has_key (config_get_instance (), "Seat:*", "greeter-allow-guest"))
1423 config_set_boolean (config_get_instance (), "Seat:*", "greeter-allow-guest", TRUE);
1424 if (!config_has_key (config_get_instance (), "Seat:*", "greeter-show-remote-login"))
1425 config_set_boolean (config_get_instance (), "Seat:*", "greeter-show-remote-login", TRUE);
1426 if (!config_has_key (config_get_instance (), "Seat:*", "greeter-session"))
1427 config_set_string (config_get_instance (), "Seat:*", "greeter-session", GREETER_SESSION);
1428 if (!config_has_key (config_get_instance (), "Seat:*", "user-session"))
1429 config_set_string (config_get_instance (), "Seat:*", "user-session", USER_SESSION);
1430 if (!config_has_key (config_get_instance (), "Seat:*", "session-wrapper"))
1431 config_set_string (config_get_instance (), "Seat:*", "session-wrapper", "lightdm-session");
1432 if (!config_has_key (config_get_instance (), "LightDM", "log-directory"))
1433 config_set_string (config_get_instance (), "LightDM", "log-directory", default_log_dir);
1434 g_free (default_log_dir);
1435 if (!config_has_key (config_get_instance (), "LightDM", "run-directory"))
1436 config_set_string (config_get_instance (), "LightDM", "run-directory", default_run_dir);
1437 g_free (default_run_dir);
1438 if (!config_has_key (config_get_instance (), "LightDM", "cache-directory"))
1439 config_set_string (config_get_instance (), "LightDM", "cache-directory", default_cache_dir);
1440 g_free (default_cache_dir);
1441 if (!config_has_key (config_get_instance (), "LightDM", "sessions-directory"))
1442 config_set_string (config_get_instance (), "LightDM", "sessions-directory", SESSIONS_DIR);
1443 if (!config_has_key (config_get_instance (), "LightDM", "remote-sessions-directory"))
1444 config_set_string (config_get_instance (), "LightDM", "remote-sessions-directory", REMOTE_SESSIONS_DIR);
1445 if (!config_has_key (config_get_instance (), "LightDM", "greeters-directory"))
1446 config_set_string (config_get_instance (), "LightDM", "greeters-directory", GREETERS_DIR);
1447 if (!config_has_key (config_get_instance (), "XDMCPServer", "hostname"))
1448 config_set_string (config_get_instance (), "XDMCPServer", "hostname", g_get_host_name ());
1450 /* Override defaults */
1452 config_set_string (config_get_instance (), "LightDM", "log-directory", log_dir);
1455 config_set_string (config_get_instance (), "LightDM", "run-directory", run_dir);
1458 config_set_string (config_get_instance (), "LightDM", "cache-directory", cache_dir);
1461 /* Create run and cache directories */
1462 dir = config_get_string (config_get_instance (), "LightDM", "log-directory");
1463 if (g_mkdir_with_parents (dir, S_IRWXU | S_IXGRP | S_IXOTH) < 0)
1464 g_warning ("Failed to make log directory %s: %s", dir, strerror (errno));
1466 dir = config_get_string (config_get_instance (), "LightDM", "run-directory");
1467 if (g_mkdir_with_parents (dir, S_IRWXU | S_IXGRP | S_IXOTH) < 0)
1468 g_warning ("Failed to make run directory %s: %s", dir, strerror (errno));
1470 dir = config_get_string (config_get_instance (), "LightDM", "cache-directory");
1471 if (g_mkdir_with_parents (dir, S_IRWXU | S_IXGRP | S_IXOTH) < 0)
1472 g_warning ("Failed to make cache directory %s: %s", dir, strerror (errno));
1477 /* Show queued messages once logging is complete */
1478 for (link = messages; link; link = link->next)
1479 g_debug ("%s", (gchar *)link->data);
1480 g_list_free_full (messages, g_free);
1482 g_debug ("Using D-Bus name %s", LIGHTDM_BUS_NAME);
1483 bus_id = g_bus_own_name (getuid () == 0 ? G_BUS_TYPE_SYSTEM : G_BUS_TYPE_SESSION,
1485 G_BUS_NAME_OWNER_FLAGS_NONE,
1493 g_debug ("Running in user mode");
1494 if (getenv ("DISPLAY"))
1495 g_debug ("Using Xephyr for X servers");
1497 display_manager = display_manager_new ();
1498 g_signal_connect (display_manager, DISPLAY_MANAGER_SIGNAL_STOPPED, G_CALLBACK (display_manager_stopped_cb), NULL);
1499 g_signal_connect (display_manager, DISPLAY_MANAGER_SIGNAL_SEAT_REMOVED, G_CALLBACK (display_manager_seat_removed_cb), NULL);
1501 shared_data_manager_start (shared_data_manager_get_instance ());
1503 /* Connect to logind */
1504 if (login1_service_connect (login1_service_get_instance ()))
1506 /* Load dynamic seats from logind */
1507 g_debug ("Monitoring logind for seats");
1509 if (config_get_boolean (config_get_instance (), "LightDM", "start-default-seat"))
1511 g_signal_connect (login1_service_get_instance (), LOGIN1_SERVICE_SIGNAL_SEAT_ADDED, G_CALLBACK (login1_service_seat_added_cb), NULL);
1512 g_signal_connect (login1_service_get_instance (), LOGIN1_SERVICE_SIGNAL_SEAT_REMOVED, G_CALLBACK (login1_service_seat_removed_cb), NULL);
1514 for (link = login1_service_get_seats (login1_service_get_instance ()); link; link = link->next)
1516 Login1Seat *login1_seat = link->data;
1517 if (!login1_add_seat (login1_seat))
1518 return EXIT_FAILURE;
1524 if (config_get_boolean (config_get_instance (), "LightDM", "start-default-seat"))
1530 g_debug ("Adding default seat");
1532 types = config_get_string_list (config_get_instance (), "Seat:*", "type");
1533 for (type = types; type && *type; type++)
1535 seat = seat_new (*type, "seat0");
1542 set_seat_properties (seat, NULL);
1543 seat_set_property (seat, "exit-on-failure", "true");
1544 if (!display_manager_add_seat (display_manager, seat))
1545 return EXIT_FAILURE;
1546 g_object_unref (seat);
1550 g_warning ("Failed to create default seat");
1551 return EXIT_FAILURE;
1556 g_main_loop_run (loop);
1558 /* Clean up shared data manager */
1559 shared_data_manager_cleanup ();
1561 /* Clean up user list */
1562 common_user_list_cleanup ();
1564 /* Clean up display manager */
1565 g_clear_object (&display_manager);
1567 /* Remove D-Bus interface */
1568 g_dbus_connection_unregister_object (bus, reg_id);
1569 g_bus_unown_name (bus_id);
1570 if (seat_bus_entries)
1571 g_hash_table_unref (seat_bus_entries);
1572 if (session_bus_entries)
1573 g_hash_table_unref (session_bus_entries);
1575 g_debug ("Exiting with return value %d", exit_code);