]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - src/lightdm.c
Merge with trunk
[sojka/lightdm.git] / src / lightdm.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 <config.h>
13
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <sys/stat.h>
17 #include <glib.h>
18 #include <glib/gi18n.h>
19 #include <unistd.h>
20 #include <fcntl.h>
21 #include <sys/stat.h>
22 #include <errno.h>
23
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"
30 #include "xserver.h"
31 #include "process.h"
32 #include "session-child.h"
33
34 static gchar *config_path = NULL;
35 static GMainLoop *loop = NULL;
36 static GTimer *log_timer;
37 static int log_fd = -1;
38 static gboolean debug = FALSE;
39
40 static DisplayManager *display_manager = NULL;
41 static XDMCPServer *xdmcp_server = NULL;
42 static VNCServer *vnc_server = NULL;
43 static guint bus_id = 0;
44 static GDBusConnection *bus = NULL;
45 static guint bus_id;
46 static GDBusNodeInfo *seat_info;
47 static GHashTable *seat_bus_entries = NULL;
48 static guint seat_index = 0;
49 static GDBusNodeInfo *session_info;
50 static GHashTable *session_bus_entries = NULL;
51 static guint session_index = 0;
52 static gint exit_code = EXIT_SUCCESS;
53
54 typedef struct
55 {
56     gchar *path;
57     gchar *parent_path;
58     gchar *removed_signal;
59     guint bus_id;
60 } BusEntry;
61
62 #define LIGHTDM_BUS_NAME "org.freedesktop.DisplayManager"
63
64 static void
65 log_cb (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer data)
66 {
67     const gchar *prefix;
68     gchar *text;
69
70     switch (log_level & G_LOG_LEVEL_MASK)
71     {
72     case G_LOG_LEVEL_ERROR:
73         prefix = "ERROR:";
74         break;
75     case G_LOG_LEVEL_CRITICAL:
76         prefix = "CRITICAL:";
77         break;
78     case G_LOG_LEVEL_WARNING:
79         prefix = "WARNING:";
80         break;
81     case G_LOG_LEVEL_MESSAGE:
82         prefix = "MESSAGE:";
83         break;
84     case G_LOG_LEVEL_INFO:
85         prefix = "INFO:";
86         break;
87     case G_LOG_LEVEL_DEBUG:
88         prefix = "DEBUG:";
89         break;
90     default:
91         prefix = "LOG:";
92         break;
93     }
94
95     text = g_strdup_printf ("[%+.2fs] %s %s\n", g_timer_elapsed (log_timer, NULL), prefix, message);
96
97     /* Log everything to a file */
98     if (log_fd >= 0)
99     {
100         ssize_t n_written;
101         n_written = write (log_fd, text, strlen (text));
102         if (n_written < 0)
103             ; /* Check result so compiler doesn't warn about it */
104     }
105
106     /* Log to stderr if requested */
107     if (debug)
108         g_printerr ("%s", text);
109     else
110         g_log_default_handler (log_domain, log_level, message, data);
111
112     g_free (text);
113 }
114
115 static void
116 log_init (void)
117 {
118     gchar *log_dir, *path;
119
120     log_timer = g_timer_new ();
121
122     /* Log to a file */
123     log_dir = config_get_string (config_get_instance (), "LightDM", "log-directory");
124     path = g_build_filename (log_dir, "lightdm.log", NULL);
125     g_free (log_dir);
126
127     log_fd = open (path, O_WRONLY | O_CREAT | O_TRUNC, 0600);
128     fcntl (log_fd, F_SETFD, FD_CLOEXEC);
129     g_log_set_default_handler (log_cb, NULL);
130
131     g_debug ("Logging to %s", path);
132     g_free (path);
133 }
134
135 static void
136 signal_cb (Process *process, int signum)
137 {
138     g_debug ("Caught %s signal, shutting down", g_strsignal (signum));
139     display_manager_stop (display_manager);
140     // FIXME: Stop XDMCP server
141 }
142
143 static void
144 display_manager_stopped_cb (DisplayManager *display_manager)
145 {
146     g_debug ("Stopping daemon");
147     g_main_loop_quit (loop);
148 }
149
150 static void
151 display_manager_seat_removed_cb (DisplayManager *display_manager, Seat *seat)
152 {
153     if (seat_get_boolean_property (seat, "exit-on-failure"))
154     {
155         g_debug ("Required seat has stopped");
156         exit_code = EXIT_FAILURE;
157         display_manager_stop (display_manager);
158     }
159 }
160
161 static GVariant *
162 handle_display_manager_get_property (GDBusConnection       *connection,
163                                      const gchar           *sender,
164                                      const gchar           *object_path,
165                                      const gchar           *interface_name,
166                                      const gchar           *property_name,
167                                      GError               **error,
168                                      gpointer               user_data)
169 {
170     GVariant *result = NULL;
171
172     if (g_strcmp0 (property_name, "Seats") == 0)
173     {
174         GVariantBuilder *builder;
175         GHashTableIter iter;
176         gpointer value;
177
178         builder = g_variant_builder_new (G_VARIANT_TYPE ("ao"));
179         g_hash_table_iter_init (&iter, seat_bus_entries);
180         while (g_hash_table_iter_next (&iter, NULL, &value))
181         {
182             BusEntry *entry = value;
183             g_variant_builder_add_value (builder, g_variant_new_object_path (entry->path));
184         }
185         result = g_variant_builder_end (builder);
186         g_variant_builder_unref (builder);
187     }
188     else if (g_strcmp0 (property_name, "Sessions") == 0)
189     {
190         GVariantBuilder *builder;
191         GHashTableIter iter;
192         gpointer value;
193
194         builder = g_variant_builder_new (G_VARIANT_TYPE ("ao"));
195         g_hash_table_iter_init (&iter, session_bus_entries);
196         while (g_hash_table_iter_next (&iter, NULL, &value))
197         {
198             BusEntry *entry = value;
199             g_variant_builder_add_value (builder, g_variant_new_object_path (entry->path));
200         }
201         result = g_variant_builder_end (builder);
202         g_variant_builder_unref (builder);
203     }
204
205     return result;
206 }
207
208 static void
209 set_seat_properties (Seat *seat, const gchar *config_section)
210 {
211     gchar **keys;
212     gint i;
213
214     keys = config_get_keys (config_get_instance (), "SeatDefaults");
215     for (i = 0; keys[i]; i++)
216     {
217         gchar *value = config_get_string (config_get_instance (), "SeatDefaults", keys[i]);
218         seat_set_property (seat, keys[i], value);
219         g_free (value);
220     }
221     g_strfreev (keys);
222
223     if (config_section)
224     {
225         keys = config_get_keys (config_get_instance (), config_section);
226         for (i = 0; keys[i]; i++)
227         {
228             gchar *value = config_get_string (config_get_instance (), config_section, keys[i]);
229             seat_set_property (seat, keys[i], value);
230             g_free (value);
231         }
232         g_strfreev (keys);
233     }
234 }
235
236 static void
237 handle_display_manager_call (GDBusConnection       *connection,
238                              const gchar           *sender,
239                              const gchar           *object_path,
240                              const gchar           *interface_name,
241                              const gchar           *method_name,
242                              GVariant              *parameters,
243                              GDBusMethodInvocation *invocation,
244                              gpointer               user_data)
245 {
246     if (g_strcmp0 (method_name, "AddSeat") == 0)
247     {
248         gchar *type;
249         GVariantIter *property_iter;
250         gchar *name, *value;
251         Seat *seat;
252
253         if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(sa(ss))")))
254             return;
255
256         g_variant_get (parameters, "(&sa(ss))", &type, &property_iter);
257
258         g_debug ("Adding seat of type %s", type);
259
260         seat = seat_new (type);
261         if (seat)
262         {
263             set_seat_properties (seat, NULL);
264             while (g_variant_iter_loop (property_iter, "(&s&s)", &name, &value))
265                 seat_set_property (seat, name, value);
266         }
267         g_variant_iter_free (property_iter);
268
269         if (!seat)
270         {
271             // FIXME: Need to make proper error
272             g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Unable to create seat of type %s", type);
273             return;
274         }
275
276         if (display_manager_add_seat (display_manager, seat))
277         {
278             BusEntry *entry;
279
280             entry = g_hash_table_lookup (seat_bus_entries, seat);
281             g_dbus_method_invocation_return_value (invocation, g_variant_new ("(o)", entry->path));
282         }
283         else// FIXME: Need to make proper error
284             g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Failed to start seat");
285         g_object_unref (seat);
286     }
287     else if (g_strcmp0 (method_name, "AddLocalXSeat") == 0)
288     {
289         gint display_number;
290         Seat *seat;
291
292         if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(i)")))
293             return;
294
295         g_variant_get (parameters, "(i)", &display_number);
296
297         g_debug ("Adding local X seat :%d", display_number);
298
299         seat = seat_new ("xremote");
300         if (seat)
301         {
302             gchar *display_number_string;
303
304             set_seat_properties (seat, NULL);
305             display_number_string = g_strdup_printf ("%d", display_number);
306             seat_set_property (seat, "xserver-display-number", display_number_string);
307             g_free (display_number_string);
308         }
309
310         if (!seat)
311         {
312             // FIXME: Need to make proper error
313             g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Unable to create local X seat");
314             return;
315         }
316
317         if (display_manager_add_seat (display_manager, seat))
318         {
319             BusEntry *entry;
320
321             entry = g_hash_table_lookup (seat_bus_entries, seat);
322             g_dbus_method_invocation_return_value (invocation, g_variant_new ("(o)", entry->path));
323         }
324         else// FIXME: Need to make proper error
325             g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Failed to start seat");
326         g_object_unref (seat);
327     }
328 }
329
330 static GVariant *
331 handle_seat_get_property (GDBusConnection       *connection,
332                           const gchar           *sender,
333                           const gchar           *object_path,
334                           const gchar           *interface_name,
335                           const gchar           *property_name,
336                           GError               **error,
337                           gpointer               user_data)
338 {
339     Seat *seat = user_data;
340     GVariant *result = NULL;
341
342     if (g_strcmp0 (property_name, "CanSwitch") == 0)
343         result = g_variant_new_boolean (seat_get_can_switch (seat));
344     if (g_strcmp0 (property_name, "HasGuestAccount") == 0)
345         result = g_variant_new_boolean (seat_get_allow_guest (seat));
346     else if (g_strcmp0 (property_name, "Sessions") == 0)
347     {
348         GVariantBuilder *builder;
349         GList *link;
350
351         builder = g_variant_builder_new (G_VARIANT_TYPE ("ao"));
352         for (link = seat_get_displays (seat); link; link = link->next)
353         {
354             Display *display = link->data;
355             BusEntry *entry;
356             entry = g_hash_table_lookup (session_bus_entries, display_get_session (display));
357             if (entry)
358                 g_variant_builder_add_value (builder, g_variant_new_object_path (entry->path));
359         }
360         result = g_variant_builder_end (builder);
361         g_variant_builder_unref (builder);
362     }
363
364     return result;
365 }
366
367 static void
368 handle_seat_call (GDBusConnection       *connection,
369                   const gchar           *sender,
370                   const gchar           *object_path,
371                   const gchar           *interface_name,
372                   const gchar           *method_name,
373                   GVariant              *parameters,
374                   GDBusMethodInvocation *invocation,
375                   gpointer               user_data)
376 {
377     Seat *seat = user_data;
378
379     if (g_strcmp0 (method_name, "SwitchToGreeter") == 0)
380     {
381         if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("()")))
382             return;
383
384         seat_switch_to_greeter (seat);
385         g_dbus_method_invocation_return_value (invocation, NULL);
386     }
387     else if (g_strcmp0 (method_name, "SwitchToUser") == 0)
388     {
389         const gchar *username, *session_name;
390
391         if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(ss)")))
392             return;
393
394         g_variant_get (parameters, "(&s&s)", &username, &session_name);
395         if (strcmp (session_name, "") == 0)
396             session_name = NULL;
397
398         seat_switch_to_user (seat, username, session_name);
399         g_dbus_method_invocation_return_value (invocation, NULL);
400     }
401     else if (g_strcmp0 (method_name, "SwitchToGuest") == 0)
402     {
403         const gchar *session_name;
404
405         if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(s)")))
406             return;
407
408         g_variant_get (parameters, "(&s)", &session_name);
409         if (strcmp (session_name, "") == 0)
410             session_name = NULL;
411
412         seat_switch_to_guest (seat, session_name);
413         g_dbus_method_invocation_return_value (invocation, NULL);
414     }
415     else if (g_strcmp0 (method_name, "Lock") == 0)
416     {
417         /* FIXME: Should only allow locks if have a session on this seat */
418         seat_lock (seat, NULL);
419         g_dbus_method_invocation_return_value (invocation, NULL);
420     }
421 }
422
423 static Seat *
424 get_seat_for_session (Session *session)
425 {
426     GList *seat_link;
427
428     for (seat_link = display_manager_get_seats (display_manager); seat_link; seat_link = seat_link->next)
429     {
430         Seat *seat = seat_link->data;
431         GList *display_link;
432
433         for (display_link = seat_get_displays (seat); display_link; display_link = display_link->next)
434         {
435             Display *display = display_link->data;
436
437             if (display_get_session (display) == session)
438                 return seat;
439         }
440     }
441
442     return NULL;
443 }
444
445 static GVariant *
446 handle_session_get_property (GDBusConnection       *connection,
447                              const gchar           *sender,
448                              const gchar           *object_path,
449                              const gchar           *interface_name,
450                              const gchar           *property_name,
451                              GError               **error,
452                              gpointer               user_data)
453 {
454     Session *session = user_data;
455     BusEntry *entry;
456
457     entry = g_hash_table_lookup (session_bus_entries, session);
458     if (g_strcmp0 (property_name, "Seat") == 0)
459         return g_variant_new_object_path (entry ? entry->parent_path : "");
460     else if (g_strcmp0 (property_name, "UserName") == 0)
461         return g_variant_new_string (session_get_username (session));
462
463     return NULL;
464 }
465
466 static void
467 handle_session_call (GDBusConnection       *connection,
468                      const gchar           *sender,
469                      const gchar           *object_path,
470                      const gchar           *interface_name,
471                      const gchar           *method_name,
472                      GVariant              *parameters,
473                      GDBusMethodInvocation *invocation,
474                      gpointer               user_data)
475 {
476     Session *session = user_data;
477
478     if (g_strcmp0 (method_name, "Lock") == 0)
479     {
480         Seat *seat;
481
482         seat = get_seat_for_session (session);
483         /* FIXME: Should only allow locks if have a session on this seat */
484         seat_lock (seat, session_get_username (session));
485         g_dbus_method_invocation_return_value (invocation, NULL);
486     }
487 }
488
489 static BusEntry *
490 bus_entry_new (const gchar *path, const gchar *parent_path, const gchar *removed_signal)
491 {
492     BusEntry *entry;
493
494     entry = g_malloc0 (sizeof (BusEntry));
495     entry->path = g_strdup (path);
496     entry->parent_path = g_strdup (parent_path);
497     entry->removed_signal = g_strdup (removed_signal);
498
499     return entry;
500 }
501
502 static void
503 bus_entry_free (gpointer data)
504 {
505     BusEntry *entry = data;
506
507     g_dbus_connection_unregister_object (bus, entry->bus_id);
508
509     g_dbus_connection_emit_signal (bus,
510                                    NULL,
511                                    "/org/freedesktop/DisplayManager",
512                                    "org.freedesktop.DisplayManager",
513                                    entry->removed_signal,
514                                    g_variant_new ("(o)", entry->path),
515                                    NULL);
516
517     g_free (entry->path);
518     g_free (entry->parent_path);
519     g_free (entry->removed_signal);
520     g_free (entry);
521 }
522
523 static gboolean
524 start_session_cb (Display *display, Seat *seat)
525 {
526     Session *session;
527     BusEntry *seat_entry;
528     gchar *path;
529
530     session = display_get_session (display);
531
532     /* Set environment variables when session runs */
533     seat_entry = g_hash_table_lookup (seat_bus_entries, seat);
534     session_set_env (session, "XDG_SEAT_PATH", seat_entry->path);
535     path = g_strdup_printf ("/org/freedesktop/DisplayManager/Session%d", session_index);
536     session_index++;
537     session_set_env (session, "XDG_SESSION_PATH", path);
538     g_object_set_data_full (G_OBJECT (session), "XDG_SESSION_PATH", path, g_free);
539
540     return FALSE;
541 }
542
543 static void
544 session_stopped_cb (Session *session, Seat *seat)
545 {
546     g_signal_handlers_disconnect_matched (session, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, seat);
547     g_hash_table_remove (session_bus_entries, session);
548 }
549
550 static gboolean
551 session_started_cb (Display *display, Seat *seat)
552 {
553     static const GDBusInterfaceVTable session_vtable =
554     {
555         handle_session_call,
556         handle_session_get_property
557     };
558     Session *session;
559     BusEntry *seat_entry, *entry;
560
561     session = display_get_session (display);
562
563     g_signal_connect (session, "stopped", G_CALLBACK (session_stopped_cb), seat);
564
565     seat_entry = g_hash_table_lookup (seat_bus_entries, seat);
566     entry = bus_entry_new (g_object_get_data (G_OBJECT (session), "XDG_SESSION_PATH"), seat_entry ? seat_entry->path : NULL, "SessionRemoved");
567     g_hash_table_insert (session_bus_entries, g_object_ref (session), entry);
568
569     g_debug ("Registering session with bus path %s", entry->path);
570
571     entry->bus_id = g_dbus_connection_register_object (bus,
572                                                        entry->path,
573                                                        session_info->interfaces[0],
574                                                        &session_vtable,
575                                                        g_object_ref (session), g_object_unref,
576                                                        NULL);
577     g_dbus_connection_emit_signal (bus,
578                                    NULL,
579                                    "/org/freedesktop/DisplayManager",
580                                    "org.freedesktop.DisplayManager",
581                                    "SessionAdded",
582                                    g_variant_new ("(o)", entry->path),
583                                    NULL);
584
585     return FALSE;
586 }
587
588 static void
589 display_added_cb (Seat *seat, Display *display)
590 {
591     g_signal_connect (display, "start-session", G_CALLBACK (start_session_cb), seat);
592     g_signal_connect_after (display, "start-session", G_CALLBACK (session_started_cb), seat);
593 }
594
595 static void
596 seat_added_cb (DisplayManager *display_manager, Seat *seat)
597 {
598     static const GDBusInterfaceVTable seat_vtable =
599     {
600         handle_seat_call,
601         handle_seat_get_property
602     };
603     GList *link;
604     gchar *path;
605     BusEntry *entry;
606
607     g_signal_connect (seat, "display-added", G_CALLBACK (display_added_cb), NULL);
608     for (link = seat_get_displays (seat); link; link = link->next)
609         display_added_cb (seat, (Display *) link->data);
610
611     path = g_strdup_printf ("/org/freedesktop/DisplayManager/Seat%d", seat_index);
612     seat_index++;
613
614     entry = bus_entry_new (path, NULL, "SeatRemoved");
615     g_free (path);
616     g_hash_table_insert (seat_bus_entries, g_object_ref (seat), entry);
617
618     g_debug ("Registering seat with bus path %s", entry->path);
619
620     entry->bus_id = g_dbus_connection_register_object (bus,
621                                                        entry->path,
622                                                        seat_info->interfaces[0],
623                                                        &seat_vtable,
624                                                        g_object_ref (seat), g_object_unref,
625                                                        NULL);
626     g_dbus_connection_emit_signal (bus,
627                                    NULL,
628                                    "/org/freedesktop/DisplayManager",
629                                    "org.freedesktop.DisplayManager",
630                                    "SeatAdded",
631                                    g_variant_new ("(o)", entry->path),
632                                    NULL);
633 }
634
635 static void
636 seat_removed_cb (DisplayManager *display_manager, Seat *seat)
637 {
638     g_hash_table_remove (seat_bus_entries, seat);
639 }
640
641 static void
642 bus_acquired_cb (GDBusConnection *connection,
643                  const gchar     *name,
644                  gpointer         user_data)
645 {
646     const gchar *display_manager_interface =
647         "<node>"
648         "  <interface name='org.freedesktop.DisplayManager'>"
649         "    <property name='Seats' type='ao' access='read'/>"
650         "    <property name='Sessions' type='ao' access='read'/>"
651         "    <method name='AddSeat'>"
652         "      <arg name='type' direction='in' type='s'/>"
653         "      <arg name='properties' direction='in' type='a(ss)'/>"
654         "      <arg name='seat' direction='out' type='o'/>"
655         "    </method>"
656         "    <method name='AddLocalXSeat'>"
657         "      <arg name='display-number' direction='in' type='i'/>"
658         "      <arg name='seat' direction='out' type='o'/>"
659         "    </method>"
660         "    <signal name='SeatAdded'>"
661         "      <arg name='seat' type='o'/>"
662         "    </signal>"
663         "    <signal name='SeatRemoved'>"
664         "      <arg name='seat' type='o'/>"
665         "    </signal>"
666         "    <signal name='SessionAdded'>"
667         "      <arg name='session' type='o'/>"
668         "    </signal>"
669         "    <signal name='SessionRemoved'>"
670         "      <arg name='session' type='o'/>"
671         "    </signal>"
672         "  </interface>"
673         "</node>";
674     static const GDBusInterfaceVTable display_manager_vtable =
675     {
676         handle_display_manager_call,
677         handle_display_manager_get_property
678     };
679     const gchar *seat_interface =
680         "<node>"
681         "  <interface name='org.freedesktop.DisplayManager.Seat'>"
682         "    <property name='CanSwitch' type='b' access='read'/>"
683         "    <property name='HasGuestAccount' type='b' access='read'/>"
684         "    <property name='Sessions' type='ao' access='read'/>"
685         "    <method name='SwitchToGreeter'/>"
686         "    <method name='SwitchToUser'>"
687         "      <arg name='username' direction='in' type='s'/>"
688         "      <arg name='session-name' direction='in' type='s'/>"
689         "    </method>"
690         "    <method name='SwitchToGuest'>"
691         "      <arg name='session-name' direction='in' type='s'/>"
692         "    </method>"
693         "    <method name='Lock'/>"
694         "  </interface>"
695         "</node>";
696     const gchar *session_interface =
697         "<node>"
698         "  <interface name='org.freedesktop.DisplayManager.Session'>"
699         "    <property name='Seat' type='o' access='read'/>"
700         "    <property name='UserName' type='s' access='read'/>"
701         "    <method name='Lock'/>"
702         "  </interface>"
703         "</node>";
704     GDBusNodeInfo *display_manager_info;
705     GList *link;
706
707     g_debug ("Acquired bus name %s", name);
708
709     bus = connection;
710
711     display_manager_info = g_dbus_node_info_new_for_xml (display_manager_interface, NULL);
712     g_assert (display_manager_info != NULL);
713     seat_info = g_dbus_node_info_new_for_xml (seat_interface, NULL);
714     g_assert (seat_info != NULL);
715     session_info = g_dbus_node_info_new_for_xml (session_interface, NULL);
716     g_assert (session_info != NULL);
717
718     bus_id = g_dbus_connection_register_object (connection,
719                                                 "/org/freedesktop/DisplayManager",
720                                                 display_manager_info->interfaces[0],
721                                                 &display_manager_vtable,
722                                                 NULL, NULL,
723                                                 NULL);
724     g_dbus_node_info_unref  (display_manager_info);
725
726     seat_bus_entries = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, bus_entry_free);
727     session_bus_entries = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, bus_entry_free);
728
729     g_signal_connect (display_manager, "seat-added", G_CALLBACK (seat_added_cb), NULL);
730     g_signal_connect (display_manager, "seat-removed", G_CALLBACK (seat_removed_cb), NULL);
731     for (link = display_manager_get_seats (display_manager); link; link = link->next)
732         seat_added_cb (display_manager, (Seat *) link->data);
733 }
734
735 static void
736 name_lost_cb (GDBusConnection *connection,
737               const gchar *name,
738               gpointer user_data)
739 {
740     if (connection)
741         g_printerr ("Failed to use bus name " LIGHTDM_BUS_NAME ", do you have appropriate permissions?\n");
742     else
743         g_printerr ("Failed to get D-Bus connection\n");
744
745     exit (EXIT_FAILURE);
746 }
747
748 static gchar *
749 path_make_absolute (gchar *path)
750 {
751     gchar *cwd, *abs_path;
752
753     if (!path)
754         return NULL;
755
756     if (g_path_is_absolute (path))
757         return path;
758
759     cwd = g_get_current_dir ();
760     abs_path = g_build_filename (cwd, path, NULL);
761     g_free (path);
762
763     return abs_path;
764 }
765
766 static gboolean
767 xdmcp_session_cb (XDMCPServer *server, XDMCPSession *session)
768 {
769     SeatXDMCPSession *seat;
770     gboolean result;
771
772     seat = seat_xdmcp_session_new (session);
773     set_seat_properties (SEAT (seat), NULL);
774     result = display_manager_add_seat (display_manager, SEAT (seat));
775     g_object_unref (seat);
776
777     return result;
778 }
779
780 static void
781 vnc_connection_cb (VNCServer *server, GSocket *connection)
782 {
783     SeatXVNC *seat;
784
785     seat = seat_xvnc_new (connection);
786     set_seat_properties (SEAT (seat), NULL);
787     display_manager_add_seat (display_manager, SEAT (seat));
788     g_object_unref (seat);
789 }
790
791 static int
792 compare_strings (gconstpointer a, gconstpointer b)
793 {
794     return strcmp (a, b);
795 }
796
797 int
798 main (int argc, char **argv)
799 {
800     FILE *pid_file;
801     GOptionContext *option_context;
802     gboolean result;
803     gchar **groups, **i, *dir;
804     gint n_seats = 0;
805     gboolean explicit_config = FALSE;
806     gboolean test_mode = FALSE;
807     gchar *pid_path = "/var/run/lightdm.pid";
808     gchar *xsessions_dir = NULL;
809     gchar *remote_sessions_dir = NULL;
810     gchar *xgreeters_dir = NULL;
811     gchar *config_dir, *config_d_dir = NULL;
812     gchar *log_dir = NULL;
813     gchar *run_dir = NULL;
814     gchar *cache_dir = NULL;
815     gchar *default_log_dir = g_strdup (LOG_DIR);
816     gchar *default_run_dir = g_strdup (RUN_DIR);
817     gchar *default_cache_dir = g_strdup (CACHE_DIR);
818     gboolean show_version = FALSE;
819     GList *link, *messages = NULL;
820     GOptionEntry options[] =
821     {
822         { "config", 'c', 0, G_OPTION_ARG_STRING, &config_path,
823           /* Help string for command line --config flag */
824           N_("Use configuration file"), "FILE" },
825         { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug,
826           /* Help string for command line --debug flag */
827           N_("Print debugging messages"), NULL },
828         { "test-mode", 0, 0, G_OPTION_ARG_NONE, &test_mode,
829           /* Help string for command line --test-mode flag */
830           N_("Run as unprivileged user, skipping things that require root access"), NULL },
831         { "pid-file", 0, 0, G_OPTION_ARG_STRING, &pid_path,
832           /* Help string for command line --pid-file flag */
833           N_("File to write PID into"), "FILE" },
834         { "xsessions-dir", 0, 0, G_OPTION_ARG_STRING, &xsessions_dir,
835           /* Help string for command line --xsessions-dir flag */
836           N_("Directory to load X sessions from"), "DIRECTORY" },
837         { "remote-sessions-dir", 0, 0, G_OPTION_ARG_STRING, &remote_sessions_dir,
838           /* Help string for command line --remote-sessions-dir flag */
839           N_("Directory to load remote sessions from"), "DIRECTORY" },
840         { "xgreeters-dir", 0, 0, G_OPTION_ARG_STRING, &xgreeters_dir,
841           /* Help string for command line --xgreeters-dir flag */
842           N_("Directory to load X greeters from"), "DIRECTORY" },
843         { "log-dir", 0, 0, G_OPTION_ARG_STRING, &log_dir,
844           /* Help string for command line --log-dir flag */
845           N_("Directory to write logs to"), "DIRECTORY" },
846         { "run-dir", 0, 0, G_OPTION_ARG_STRING, &run_dir,
847           /* Help string for command line --run-dir flag */
848           N_("Directory to store running state"), "DIRECTORY" },
849         { "cache-dir", 0, 0, G_OPTION_ARG_STRING, &cache_dir,
850           /* Help string for command line --cache-dir flag */
851           N_("Directory to cache information"), "DIRECTORY" },
852         { "version", 'v', 0, G_OPTION_ARG_NONE, &show_version,
853           /* Help string for command line --version flag */
854           N_("Show release version"), NULL },
855         { NULL }
856     };
857     GError *error = NULL;
858
859     /* When lightdm starts sessions it needs to run itself in a new mode */
860     if (argc >= 2 && strcmp (argv[1], "--session-child") == 0)
861         return session_child_run (argc, argv);
862
863 #if !defined(GLIB_VERSION_2_36)
864     g_type_init ();
865 #endif
866     loop = g_main_loop_new (NULL, FALSE);
867
868     messages = g_list_append (messages, g_strdup_printf ("Starting Light Display Manager %s, UID=%i PID=%i", VERSION, getuid (), getpid ()));
869
870     g_signal_connect (process_get_current (), "got-signal", G_CALLBACK (signal_cb), NULL);
871
872     option_context = g_option_context_new (/* Arguments and description for --help test */
873                                            _("- Display Manager"));
874     g_option_context_add_main_entries (option_context, options, GETTEXT_PACKAGE);
875     result = g_option_context_parse (option_context, &argc, &argv, &error);
876     if (error)
877         g_printerr ("%s\n", error->message);
878     g_clear_error (&error);
879     g_option_context_free (option_context);
880     if (!result)
881     {
882         g_printerr (/* Text printed out when an unknown command-line argument provided */
883                     _("Run '%s --help' to see a full list of available command line options."), argv[0]);
884         g_printerr ("\n");
885         return EXIT_FAILURE;
886     }
887
888     if (show_version)
889     {
890         /* NOTE: Is not translated so can be easily parsed */
891         g_printerr ("lightdm %s\n", VERSION);
892         return EXIT_SUCCESS;
893     }
894
895     if (config_path)
896     {
897         config_dir = g_path_get_basename (config_path);
898         config_dir = path_make_absolute (config_dir);
899         explicit_config = TRUE;
900     }
901     else
902     {
903         config_dir = g_strdup (CONFIG_DIR);
904         config_d_dir = g_build_filename (config_dir, "lightdm.conf.d", NULL);
905         config_path = g_build_filename (config_dir, "lightdm.conf", NULL);
906     }
907     config_set_string (config_get_instance (), "LightDM", "config-directory", config_dir);
908     g_free (config_dir);
909
910     if (!test_mode && getuid () != 0)
911     {
912         g_printerr ("Only root can run Light Display Manager.  To run as a regular user for testing run with the --test-mode flag.\n");
913         return EXIT_FAILURE;
914     }
915
916     /* If running inside an X server use Xephyr for display */
917     if (getenv ("DISPLAY") && getuid () != 0)
918     {
919         gchar *xserver_path;
920
921         xserver_path = g_find_program_in_path ("Xephyr");
922         if (!xserver_path)
923         {
924             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");
925             return EXIT_FAILURE;
926         }
927         g_free (xserver_path);
928     }
929
930     /* Make sure the system binary directory (where the greeters are installed) is in the path */
931     if (test_mode)
932     {
933         const gchar *path = g_getenv ("PATH");
934         gchar *new_path;
935
936         if (path)
937             new_path = g_strdup_printf ("%s:%s", path, SBIN_DIR);
938         else
939             new_path = g_strdup (SBIN_DIR);
940         g_setenv ("PATH", new_path, TRUE);
941         g_free (new_path);
942     }
943
944     /* Write PID file */
945     pid_file = fopen (pid_path, "w");
946     if (pid_file)
947     {
948         fprintf (pid_file, "%d\n", getpid ());
949         fclose (pid_file);
950     }
951
952     /* Always use absolute directories as child processes may run from different locations */
953     xsessions_dir = path_make_absolute (xsessions_dir);
954     remote_sessions_dir = path_make_absolute (remote_sessions_dir);
955     xgreeters_dir = path_make_absolute (xgreeters_dir);
956
957     /* If not running as root write output to directories we control */
958     if (getuid () != 0)
959     {
960         g_free (default_log_dir);
961         default_log_dir = g_build_filename (g_get_user_cache_dir (), "lightdm", "log", NULL);
962         g_free (default_run_dir);
963         default_run_dir = g_build_filename (g_get_user_cache_dir (), "lightdm", "run", NULL);
964         g_free (default_cache_dir);
965         default_cache_dir = g_build_filename (g_get_user_cache_dir (), "lightdm", "cache", NULL);
966     }
967
968     /* Load config file(s) */
969     messages = g_list_append (messages, g_strdup_printf ("Loading configuration from %s", config_path));
970     if (!config_load_from_file (config_get_instance (), config_path, &error))
971     {
972         gboolean is_empty;
973
974         is_empty = error && g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT);
975
976         if (explicit_config || !is_empty)
977         {
978             if (error)
979                 g_printerr ("Failed to load configuration from %s: %s\n", config_path, error->message);
980             exit (EXIT_FAILURE);
981         }
982     }
983     g_clear_error (&error);
984     g_free (config_path);
985     if (config_d_dir)
986     {
987         GDir *dir;
988         GList *files, *link;
989         GKeyFile *f;
990
991         /* Find configuration files */
992         dir = g_dir_open (config_d_dir, 0, &error);
993         if (error && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
994             g_printerr ("Failed to open configuration directory %s: %s\n", config_d_dir, error->message);
995         g_clear_error (&error);
996         if (dir)
997         {
998             const gchar *name;
999             while ((name = g_dir_read_name (dir)))
1000                 files = g_list_append (files, g_strdup (name));
1001             g_dir_close (dir);
1002         }
1003
1004         /* Sort alphabetically and load onto existing configuration */
1005         files = g_list_sort (files, compare_strings);
1006         for (link = files; link; link = link->next)
1007         {
1008             gchar *filename = link->data;
1009             gchar *path;
1010
1011             path = g_build_filename (config_d_dir, filename, NULL);
1012             if (g_str_has_suffix (filename, ".conf"))
1013             {
1014                 messages = g_list_append (messages, g_strdup_printf ("Loading configuration from %s", path));
1015                 config_load_from_file (config_get_instance (), path, &error);
1016                 if (error && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
1017                     g_printerr ("Failed to load configuration from %s: %s\n", filename, error->message);
1018                 g_clear_error (&error);
1019             }
1020             else
1021                 g_debug ("Ignoring configuration file %s, it does not have .conf suffix", path);
1022             g_free (path);
1023         }
1024         g_list_free_full (files, g_free);
1025     }
1026     g_free (config_d_dir);
1027
1028     /* Set default values */
1029     if (!config_has_key (config_get_instance (), "LightDM", "start-default-seat"))
1030         config_set_boolean (config_get_instance (), "LightDM", "start-default-seat", TRUE);
1031     if (!config_has_key (config_get_instance (), "LightDM", "minimum-vt"))
1032         config_set_integer (config_get_instance (), "LightDM", "minimum-vt", 7);
1033     if (!config_has_key (config_get_instance (), "LightDM", "guest-account-script"))
1034         config_set_string (config_get_instance (), "LightDM", "guest-account-script", "guest-account");
1035     if (!config_has_key (config_get_instance (), "LightDM", "greeter-user"))
1036         config_set_string (config_get_instance (), "LightDM", "greeter-user", GREETER_USER);
1037     if (!config_has_key (config_get_instance (), "LightDM", "lock-memory"))
1038         config_set_boolean (config_get_instance (), "LightDM", "lock-memory", TRUE);
1039     if (!config_has_key (config_get_instance (), "SeatDefaults", "type"))
1040         config_set_string (config_get_instance (), "SeatDefaults", "type", "xlocal");
1041     if (!config_has_key (config_get_instance (), "SeatDefaults", "xserver-command"))
1042         config_set_string (config_get_instance (), "SeatDefaults", "xserver-command", "X");
1043     if (!config_has_key (config_get_instance (), "SeatDefaults", "xserver-share"))
1044         config_set_boolean (config_get_instance (), "SeatDefaults", "xserver-share", TRUE);
1045     if (!config_has_key (config_get_instance (), "SeatDefaults", "unity-compositor-command"))
1046         config_set_string (config_get_instance (), "SeatDefaults", "unity-compositor-command", "unity-system-compositor");
1047     if (!config_has_key (config_get_instance (), "SeatDefaults", "start-session"))
1048         config_set_boolean (config_get_instance (), "SeatDefaults", "start-session", TRUE);
1049     if (!config_has_key (config_get_instance (), "SeatDefaults", "allow-guest"))
1050         config_set_boolean (config_get_instance (), "SeatDefaults", "allow-guest", TRUE);
1051     if (!config_has_key (config_get_instance (), "SeatDefaults", "greeter-allow-guest"))
1052         config_set_boolean (config_get_instance (), "SeatDefaults", "greeter-allow-guest", TRUE);
1053     if (!config_has_key (config_get_instance (), "SeatDefaults", "greeter-show-remote-login"))
1054         config_set_boolean (config_get_instance (), "SeatDefaults", "greeter-show-remote-login", TRUE);
1055     if (!config_has_key (config_get_instance (), "SeatDefaults", "greeter-session"))
1056         config_set_string (config_get_instance (), "SeatDefaults", "greeter-session", GREETER_SESSION);
1057     if (!config_has_key (config_get_instance (), "SeatDefaults", "user-session"))
1058         config_set_string (config_get_instance (), "SeatDefaults", "user-session", USER_SESSION);
1059     if (!config_has_key (config_get_instance (), "SeatDefaults", "session-wrapper"))
1060         config_set_string (config_get_instance (), "SeatDefaults", "session-wrapper", "lightdm-session");
1061     if (!config_has_key (config_get_instance (), "LightDM", "log-directory"))
1062         config_set_string (config_get_instance (), "LightDM", "log-directory", default_log_dir);
1063     g_free (default_log_dir);
1064     if (!config_has_key (config_get_instance (), "LightDM", "run-directory"))
1065         config_set_string (config_get_instance (), "LightDM", "run-directory", default_run_dir);
1066     g_free (default_run_dir);
1067     if (!config_has_key (config_get_instance (), "LightDM", "cache-directory"))
1068         config_set_string (config_get_instance (), "LightDM", "cache-directory", default_cache_dir);
1069     g_free (default_cache_dir);
1070     if (!config_has_key (config_get_instance (), "LightDM", "xsessions-directory"))
1071         config_set_string (config_get_instance (), "LightDM", "xsessions-directory", XSESSIONS_DIR);
1072     if (!config_has_key (config_get_instance (), "LightDM", "remote-sessions-directory"))
1073         config_set_string (config_get_instance (), "LightDM", "remote-sessions-directory", REMOTE_SESSIONS_DIR);
1074     if (!config_has_key (config_get_instance (), "LightDM", "xgreeters-directory"))
1075         config_set_string (config_get_instance (), "LightDM", "xgreeters-directory", XGREETERS_DIR);
1076
1077     /* Override defaults */
1078     if (log_dir)
1079         config_set_string (config_get_instance (), "LightDM", "log-directory", log_dir);
1080     g_free (log_dir);
1081     if (run_dir)
1082         config_set_string (config_get_instance (), "LightDM", "run-directory", run_dir);
1083     g_free (run_dir);
1084     if (cache_dir)
1085         config_set_string (config_get_instance (), "LightDM", "cache-directory", cache_dir);
1086     g_free (cache_dir);
1087     if (xsessions_dir)
1088         config_set_string (config_get_instance (), "LightDM", "xsessions-directory", xsessions_dir);
1089     g_free (xsessions_dir);
1090     if (remote_sessions_dir)
1091         config_set_string (config_get_instance (), "LightDM", "remote-sessions-directory", remote_sessions_dir);
1092     g_free (remote_sessions_dir);
1093     if (xgreeters_dir)
1094         config_set_string (config_get_instance (), "LightDM", "xgreeters-directory", xgreeters_dir);
1095     g_free (xgreeters_dir);
1096
1097     /* Create run and cache directories */
1098     dir = config_get_string (config_get_instance (), "LightDM", "log-directory");
1099     if (g_mkdir_with_parents (dir, S_IRWXU | S_IXGRP | S_IXOTH) < 0)
1100         g_warning ("Failed to make log directory %s: %s", dir, strerror (errno));
1101     g_free (dir);
1102     dir = config_get_string (config_get_instance (), "LightDM", "run-directory");
1103     if (g_mkdir_with_parents (dir, S_IRWXU | S_IXGRP | S_IXOTH) < 0)
1104         g_warning ("Failed to make run directory %s: %s", dir, strerror (errno));
1105     g_free (dir);
1106     dir = config_get_string (config_get_instance (), "LightDM", "cache-directory");
1107     if (g_mkdir_with_parents (dir, S_IRWXU | S_IXGRP | S_IXOTH) < 0)
1108         g_warning ("Failed to make cache directory %s: %s", dir, strerror (errno));
1109     g_free (dir);
1110
1111     log_init ();
1112
1113     /* Show queued messages once logging is complete */
1114     for (link = messages; link; link = link->next)
1115         g_debug ("%s", link->data);
1116     g_list_free_full (messages, g_free);
1117
1118     g_debug ("Using D-Bus name %s", LIGHTDM_BUS_NAME);
1119     bus_id = g_bus_own_name (getuid () == 0 ? G_BUS_TYPE_SYSTEM : G_BUS_TYPE_SESSION,
1120                              LIGHTDM_BUS_NAME,
1121                              G_BUS_NAME_OWNER_FLAGS_NONE,
1122                              bus_acquired_cb,
1123                              NULL,
1124                              name_lost_cb,
1125                              NULL,
1126                              NULL);
1127
1128     if (getuid () != 0)
1129         g_debug ("Running in user mode");
1130     if (getenv ("DISPLAY"))
1131         g_debug ("Using Xephyr for X servers");
1132
1133     display_manager = display_manager_new ();
1134     g_signal_connect (display_manager, "stopped", G_CALLBACK (display_manager_stopped_cb), NULL);
1135     g_signal_connect (display_manager, "seat-removed", G_CALLBACK (display_manager_seat_removed_cb), NULL);
1136
1137     /* Load the static display entries */
1138     groups = config_get_groups (config_get_instance ());
1139     for (i = groups; *i; i++)
1140     {
1141         gchar *config_section = *i;
1142         gchar *type;
1143         Seat *seat;
1144
1145         if (!g_str_has_prefix (config_section, "Seat:"))
1146             continue;
1147
1148         g_debug ("Loading seat %s", config_section);
1149         type = config_get_string (config_get_instance (), config_section, "type");
1150         if (!type)
1151             type = config_get_string (config_get_instance (), "SeatDefaults", "type");
1152         seat = seat_new (type);
1153         g_free (type);
1154         if (seat)
1155         {
1156             set_seat_properties (seat, config_section);
1157             display_manager_add_seat (display_manager, seat);
1158             g_object_unref (seat);
1159             n_seats++;
1160         }
1161         else
1162             g_warning ("Failed to create seat %s", config_section);
1163     }
1164     g_strfreev (groups);
1165
1166     /* If no seats start a default one */
1167     if (n_seats == 0 && config_get_boolean (config_get_instance (), "LightDM", "start-default-seat"))
1168     {
1169         gchar *type;
1170         Seat *seat;
1171
1172         g_debug ("Adding default seat");
1173
1174         type = config_get_string (config_get_instance (), "SeatDefaults", "type");
1175         seat = seat_new (type);
1176         g_free (type);
1177         if (seat)
1178         {
1179             set_seat_properties (seat, NULL);
1180             seat_set_property (seat, "exit-on-failure", "true");
1181             display_manager_add_seat (display_manager, seat);
1182             g_object_unref (seat);
1183         }
1184         else
1185         {
1186             g_warning ("Failed to create default seat %s", type);
1187             return EXIT_FAILURE;
1188         }
1189     }
1190
1191     display_manager_start (display_manager);
1192
1193     /* Start the XDMCP server */
1194     if (config_get_boolean (config_get_instance (), "XDMCPServer", "enabled"))
1195     {
1196         gchar *key_name, *key = NULL;
1197
1198         xdmcp_server = xdmcp_server_new ();
1199         if (config_has_key (config_get_instance (), "XDMCPServer", "port"))
1200         {
1201             gint port;
1202             port = config_get_integer (config_get_instance (), "XDMCPServer", "port");
1203             if (port > 0)
1204                 xdmcp_server_set_port (xdmcp_server, port);
1205         }
1206         g_signal_connect (xdmcp_server, "new-session", G_CALLBACK (xdmcp_session_cb), NULL);
1207
1208         key_name = config_get_string (config_get_instance (), "XDMCPServer", "key");
1209         if (key_name)
1210         {
1211             gchar *dir, *path;
1212             GKeyFile *keys;
1213             gboolean result;
1214             GError *error = NULL;
1215
1216             dir = config_get_string (config_get_instance (), "LightDM", "config-directory");
1217             path = g_build_filename (dir, "keys.conf", NULL);
1218             g_free (dir);
1219
1220             keys = g_key_file_new ();
1221             result = g_key_file_load_from_file (keys, path, G_KEY_FILE_NONE, &error);
1222             if (error)
1223                 g_debug ("Error getting key %s", error->message);
1224             g_clear_error (&error);
1225
1226             if (result)
1227             {
1228                 if (g_key_file_has_key (keys, "keyring", key_name, NULL))
1229                     key = g_key_file_get_string (keys, "keyring", key_name, NULL);
1230                 else
1231                     g_debug ("Key %s not defined", key_name);
1232             }
1233             g_free (path);
1234             g_key_file_free (keys);
1235         }
1236         if (key)
1237             xdmcp_server_set_key (xdmcp_server, key);
1238         g_free (key_name);
1239         g_free (key);
1240
1241         g_debug ("Starting XDMCP server on UDP/IP port %d", xdmcp_server_get_port (xdmcp_server));
1242         xdmcp_server_start (xdmcp_server);
1243     }
1244
1245     /* Start the VNC server */
1246     if (config_get_boolean (config_get_instance (), "VNCServer", "enabled"))
1247     {
1248         gchar *path;
1249
1250         path = g_find_program_in_path ("Xvnc");
1251         if (path)
1252         {
1253             vnc_server = vnc_server_new ();
1254             if (config_has_key (config_get_instance (), "VNCServer", "port"))
1255             {
1256                 gint port;
1257                 port = config_get_integer (config_get_instance (), "VNCServer", "port");
1258                 if (port > 0)
1259                     vnc_server_set_port (vnc_server, port);
1260             }
1261             g_signal_connect (vnc_server, "new-connection", G_CALLBACK (vnc_connection_cb), NULL);
1262
1263             g_debug ("Starting VNC server on TCP/IP port %d", vnc_server_get_port (vnc_server));
1264             vnc_server_start (vnc_server);
1265
1266             g_free (path);
1267         }
1268         else
1269             g_warning ("Can't start VNC server, Xvn is not in the path");
1270     }
1271
1272     g_main_loop_run (loop);
1273
1274     /* Clean up display manager */
1275     g_object_unref (display_manager);
1276     display_manager = NULL;
1277
1278     /* Remove D-Bus interface */
1279     g_bus_unown_name (bus_id);
1280     if (seat_bus_entries)
1281         g_hash_table_unref (seat_bus_entries);
1282     if (session_bus_entries)
1283         g_hash_table_unref (session_bus_entries);
1284
1285     g_debug ("Exiting with return value %d", exit_code);
1286     return exit_code;
1287 }