1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
3
* Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29
#include <glib/gi18n.h>
32
#include <gconf/gconf-client.h>
34
#include <dbus/dbus-glib.h>
37
#include "gdm-common.h"
38
#include "gdm-signal-handler.h"
39
#include "gdm-settings-client.h"
40
#include "gdm-settings-keys.h"
41
#include "gdm-profile.h"
43
#include "gdm-greeter-session.h"
45
#define SM_DBUS_NAME "org.gnome.SessionManager"
46
#define SM_DBUS_PATH "/org/gnome/SessionManager"
47
#define SM_DBUS_INTERFACE "org.gnome.SessionManager"
49
#define SM_CLIENT_DBUS_INTERFACE "org.gnome.SessionManager.ClientPrivate"
51
static DBusGConnection *bus_connection = NULL;
52
static DBusGProxy *sm_proxy = NULL;
53
static char *client_id = NULL;
54
static DBusGProxy *client_proxy = NULL;
59
gboolean debug = FALSE;
61
/* enable debugging for unstable builds */
62
if (gdm_is_version_unstable ()) {
66
gdm_settings_client_get_boolean (GDM_KEY_DEBUG, &debug);
77
g_debug ("Got callback for signal %d", signo);
84
/* let the fatal signals interrupt us */
85
g_debug ("Caught signal %d, shutting down abnormally.", signo);
92
/* let the fatal signals interrupt us */
93
g_debug ("Caught signal %d, shutting down normally.", signo);
99
g_debug ("Got HUP signal");
101
* Reread config stuff like system config files, VPN service files, etc
108
g_debug ("Got USR1 signal");
110
* Play with log levels or something
114
gdm_log_toggle_debug ();
119
g_debug ("Caught unhandled signal %d", signo);
129
session_manager_connect (void)
132
if (bus_connection == NULL) {
136
bus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
137
if (bus_connection == NULL) {
138
g_message ("Failed to connect to the session bus: %s",
140
g_error_free (error);
145
sm_proxy = dbus_g_proxy_new_for_name (bus_connection,
149
return (sm_proxy != NULL);
153
stop_cb (gpointer data)
159
end_session_response (gboolean is_okay, const gchar *reason)
162
GError *error = NULL;
164
ret = dbus_g_proxy_call (client_proxy, "EndSessionResponse",
166
G_TYPE_BOOLEAN, is_okay,
167
G_TYPE_STRING, reason,
172
g_warning ("Failed to send session response %s", error->message);
173
g_error_free (error);
180
query_end_session_cb (guint flags, gpointer data)
182
end_session_response (TRUE, NULL);
186
end_session_cb (guint flags, gpointer data)
188
end_session_response (TRUE, NULL);
193
register_client (void)
197
const char *startup_id;
200
startup_id = g_getenv ("DESKTOP_AUTOSTART_ID");
201
app_id = "gdm-simple-greeter.desktop";
204
res = dbus_g_proxy_call (sm_proxy,
207
G_TYPE_STRING, app_id,
208
G_TYPE_STRING, startup_id,
210
DBUS_TYPE_G_OBJECT_PATH, &client_id,
213
g_warning ("Failed to register client: %s", error->message);
214
g_error_free (error);
218
g_debug ("Client registered with session manager: %s", client_id);
219
client_proxy = dbus_g_proxy_new_for_name (bus_connection,
222
SM_CLIENT_DBUS_INTERFACE);
224
dbus_g_proxy_add_signal (client_proxy, "Stop", G_TYPE_INVALID);
225
dbus_g_proxy_connect_signal (client_proxy, "Stop",
226
G_CALLBACK (stop_cb), NULL, NULL);
228
dbus_g_proxy_add_signal (client_proxy, "QueryEndSession", G_TYPE_UINT, G_TYPE_INVALID);
229
dbus_g_proxy_connect_signal (client_proxy, "QueryEndSession",
230
G_CALLBACK (query_end_session_cb), NULL, NULL);
232
dbus_g_proxy_add_signal (client_proxy, "EndSession", G_TYPE_UINT, G_TYPE_INVALID);
233
dbus_g_proxy_connect_signal (client_proxy, "EndSession",
234
G_CALLBACK (end_session_cb), NULL, NULL);
236
g_unsetenv ("DESKTOP_AUTOSTART_ID");
242
main (int argc, char *argv[])
245
GdmGreeterSession *session;
247
GdmSignalHandler *signal_handler;
249
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
250
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
251
textdomain (GETTEXT_PACKAGE);
253
setlocale (LC_ALL, "");
255
gdm_set_fatal_warnings_if_unstable ();
259
gdm_profile_start ("Initializing settings client");
260
if (! gdm_settings_client_init (GDMCONFDIR "/gdm.schemas", "/")) {
261
g_critical ("Unable to initialize settings client");
264
gdm_profile_end ("Initializing settings client");
266
g_debug ("Greeter session pid=%d display=%s xauthority=%s",
268
g_getenv ("DISPLAY"),
269
g_getenv ("XAUTHORITY"));
271
/* FIXME: For testing to make it easier to attach gdb */
275
gdm_log_set_debug (is_debug_set ());
277
gtk_init (&argc, &argv);
279
signal_handler = gdm_signal_handler_new ();
280
gdm_signal_handler_add_fatal (signal_handler);
281
gdm_signal_handler_add (signal_handler, SIGTERM, signal_cb, NULL);
282
gdm_signal_handler_add (signal_handler, SIGINT, signal_cb, NULL);
283
gdm_signal_handler_add (signal_handler, SIGFPE, signal_cb, NULL);
284
gdm_signal_handler_add (signal_handler, SIGHUP, signal_cb, NULL);
285
gdm_signal_handler_add (signal_handler, SIGUSR1, signal_cb, NULL);
287
gdm_profile_start ("Creating new greeter session");
288
session = gdm_greeter_session_new ();
289
if (session == NULL) {
290
g_critical ("Unable to create greeter session");
293
gdm_profile_end ("Creating new greeter session");
296
res = gdm_greeter_session_start (session, &error);
298
g_warning ("Unable to start greeter session: %s", error->message);
299
g_error_free (error);
303
res = session_manager_connect ();
305
g_warning ("Unable to connect to session manager");
309
res = register_client ();
311
g_warning ("Unable to register client with session manager");
316
if (session != NULL) {
317
g_object_unref (session);