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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28
#include <sys/types.h>
35
#include <glib/gi18n.h>
36
#include <glib-object.h>
39
#include "gdm-xerrors.h"
40
#include "gdm-signal-handler.h"
42
#include "gdm-common.h"
43
#include "gdm-simple-slave.h"
44
#include "gdm-settings.h"
45
#include "gdm-settings-direct.h"
46
#include "gdm-settings-keys.h"
47
#include "gdm-settings-client.h"
49
static GdmSettings *settings = NULL;
50
static int gdm_return_code = 0;
52
static GDBusConnection *
59
bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
61
g_warning ("Couldn't connect to system bus: %s",
67
g_dbus_connection_set_exit_on_close (bus, FALSE);
79
g_debug ("Got callback for signal %d", signo);
88
g_debug ("Caught signal %d.", signo);
95
/* let the fatal signals interrupt us */
96
g_debug ("Caught signal %d, shutting down abnormally.", signo);
103
/* let the fatal signals interrupt us */
104
g_debug ("Caught signal %d, shutting down normally.", signo);
110
g_debug ("Got HUP signal");
112
* Reread config stuff like system config files, VPN service files, etc
119
g_debug ("Got USR1 signal");
120
/* we get this from xorg - can't use for anything else */
126
g_debug ("Got USR2 signal");
129
gdm_log_toggle_debug ();
134
g_debug ("Caught unhandled signal %d", signo);
144
on_slave_stopped (GdmSlave *slave,
145
GMainLoop *main_loop)
147
g_debug ("slave finished");
149
g_main_loop_quit (main_loop);
155
gboolean debug = FALSE;
157
/* enable debugging for unstable builds */
158
if (gdm_is_version_unstable ()) {
162
gdm_settings_direct_get_boolean (GDM_KEY_DEBUG, &debug);
170
GMainLoop *main_loop;
171
GOptionContext *context;
172
GDBusConnection *connection;
174
static char *display_id = NULL;
175
GdmSignalHandler *signal_handler;
176
static GOptionEntry entries [] = {
177
{ "display-id", 0, 0, G_OPTION_ARG_STRING, &display_id, N_("Display ID"), N_("ID") },
181
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
182
textdomain (GETTEXT_PACKAGE);
183
setlocale (LC_ALL, "");
187
context = g_option_context_new (_("GNOME Display Manager Slave"));
188
g_option_context_add_main_entries (context, entries, NULL);
190
g_option_context_parse (context, &argc, &argv, NULL);
191
g_option_context_free (context);
196
connection = get_system_bus ();
197
if (connection == NULL) {
204
settings = gdm_settings_new ();
205
if (settings == NULL) {
206
g_warning ("Unable to initialize settings");
210
if (! gdm_settings_direct_init (settings, DATADIR "/gdm/gdm.schemas", "/")) {
211
g_warning ("Unable to initialize settings");
215
gdm_log_set_debug (is_debug_set ());
217
if (display_id == NULL) {
218
g_critical ("No display ID set");
222
if (! gdm_settings_client_init (DATADIR "/gdm/gdm.schemas", "/")) {
223
g_critical ("Unable to initialize settings client");
227
main_loop = g_main_loop_new (NULL, FALSE);
229
signal_handler = gdm_signal_handler_new ();
230
gdm_signal_handler_set_fatal_func (signal_handler,
231
(GDestroyNotify)g_main_loop_quit,
233
gdm_signal_handler_add (signal_handler, SIGTERM, signal_cb, NULL);
234
gdm_signal_handler_add (signal_handler, SIGINT, signal_cb, NULL);
235
gdm_signal_handler_add (signal_handler, SIGILL, signal_cb, NULL);
236
gdm_signal_handler_add (signal_handler, SIGBUS, signal_cb, NULL);
237
gdm_signal_handler_add (signal_handler, SIGFPE, signal_cb, NULL);
238
gdm_signal_handler_add (signal_handler, SIGHUP, signal_cb, NULL);
239
gdm_signal_handler_add (signal_handler, SIGSEGV, signal_cb, NULL);
240
gdm_signal_handler_add (signal_handler, SIGABRT, signal_cb, NULL);
241
gdm_signal_handler_add (signal_handler, SIGUSR1, signal_cb, NULL);
242
gdm_signal_handler_add (signal_handler, SIGUSR2, signal_cb, NULL);
244
slave = gdm_simple_slave_new (display_id);
248
g_signal_connect (slave,
250
G_CALLBACK (on_slave_stopped),
252
gdm_slave_start (slave);
254
g_main_loop_run (main_loop);
257
g_object_unref (slave);
260
if (signal_handler != NULL) {
261
g_object_unref (signal_handler);
264
g_main_loop_unref (main_loop);
267
g_debug ("Slave finished");
269
g_object_unref (connection);
271
return gdm_return_code;