source: proiecte/PPPP/gdm/daemon/xdmcp-chooser-slave-main.c @ 134

Last change on this file since 134 was 134, checked in by (none), 14 years ago

gdm sources with the modifications for webcam

File size: 7.4 KB
Line 
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2008 William Jon McCann <jmccann@redhat.com>
4 *
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.
9 *
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.
14 *
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.
18 *
19 */
20
21#include "config.h"
22
23#include <stdlib.h>
24#include <stdio.h>
25#include <unistd.h>
26#include <errno.h>
27#include <string.h>
28#include <sys/types.h>
29#include <sys/stat.h>
30#include <fcntl.h>
31#include <signal.h>
32#include <locale.h>
33
34#include <glib.h>
35#include <glib/gi18n.h>
36#include <glib-object.h>
37
38#define DBUS_API_SUBJECT_TO_CHANGE
39#include <dbus/dbus-glib.h>
40#include <dbus/dbus-glib-lowlevel.h>
41
42#include "gdm-signal-handler.h"
43#include "gdm-log.h"
44#include "gdm-common.h"
45#include "gdm-xdmcp-chooser-slave.h"
46#include "gdm-settings.h"
47#include "gdm-settings-direct.h"
48
49static GdmSettings     *settings        = NULL;
50static int              gdm_return_code = 0;
51
52static DBusGConnection *
53get_system_bus (void)
54{
55        GError          *error;
56        DBusGConnection *bus;
57        DBusConnection  *connection;
58
59        error = NULL;
60        bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
61        if (bus == NULL) {
62                g_warning ("Couldn't connect to system bus: %s",
63                           error->message);
64                g_error_free (error);
65                goto out;
66        }
67
68        connection = dbus_g_connection_get_connection (bus);
69        dbus_connection_set_exit_on_disconnect (connection, FALSE);
70
71 out:
72        return bus;
73}
74
75static gboolean
76signal_cb (int      signo,
77           gpointer data)
78{
79        int ret;
80
81        g_debug ("Got callback for signal %d", signo);
82
83        ret = TRUE;
84
85        switch (signo) {
86        case SIGSEGV:
87        case SIGBUS:
88        case SIGILL:
89        case SIGABRT:
90                g_debug ("Caught signal %d.", signo);
91
92                ret = FALSE;
93                break;
94
95        case SIGFPE:
96        case SIGPIPE:
97                /* let the fatal signals interrupt us */
98                g_debug ("Caught signal %d, shutting down abnormally.", signo);
99                ret = FALSE;
100
101                break;
102
103        case SIGINT:
104        case SIGTERM:
105                /* let the fatal signals interrupt us */
106                g_debug ("Caught signal %d, shutting down normally.", signo);
107                ret = FALSE;
108
109                break;
110
111        case SIGHUP:
112                g_debug ("Got HUP signal");
113                /* FIXME:
114                 * Reread config stuff like system config files, VPN service files, etc
115                 */
116                ret = TRUE;
117
118                break;
119
120        case SIGUSR1:
121                g_debug ("Got USR1 signal");
122                /* we get this from xorg - can't use for anything else */
123                ret = TRUE;
124
125                gdm_log_toggle_debug ();
126
127                break;
128
129        case SIGUSR2:
130                g_debug ("Got USR2 signal");
131                ret = TRUE;
132
133                gdm_log_toggle_debug ();
134
135                break;
136
137        default:
138                g_debug ("Caught unhandled signal %d", signo);
139                ret = TRUE;
140
141                break;
142        }
143
144        return ret;
145}
146
147static void
148on_slave_stopped (GdmSlave   *slave,
149                  GMainLoop  *main_loop)
150{
151        g_debug ("slave finished");
152        gdm_return_code = 0;
153        g_main_loop_quit (main_loop);
154}
155
156static gboolean
157is_debug_set (gboolean arg)
158{
159        /* enable debugging for unstable builds */
160        if (gdm_is_version_unstable ()) {
161                return TRUE;
162        }
163
164        return arg;
165}
166
167int
168main (int    argc,
169      char **argv)
170{
171        GMainLoop        *main_loop;
172        GOptionContext   *context;
173        DBusGConnection  *connection;
174        GdmSlave         *slave;
175        static char      *display_id = NULL;
176        static gboolean   debug      = FALSE;
177        GdmSignalHandler *signal_handler;
178        static GOptionEntry entries []   = {
179                { "debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Enable debugging code"), NULL },
180                { "display-id", 0, 0, G_OPTION_ARG_STRING, &display_id, N_("Display ID"), N_("id") },
181                { NULL }
182        };
183
184        bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
185        textdomain (GETTEXT_PACKAGE);
186        setlocale (LC_ALL, "");
187
188        gdm_set_fatal_warnings_if_unstable ();
189
190        g_type_init ();
191
192        context = g_option_context_new (_("GNOME Display Manager Slave"));
193        g_option_context_add_main_entries (context, entries, NULL);
194
195        g_option_context_parse (context, &argc, &argv, NULL);
196        g_option_context_free (context);
197
198        connection = get_system_bus ();
199        if (connection == NULL) {
200                goto out;
201        }
202
203        gdm_log_init ();
204
205        settings = gdm_settings_new ();
206        if (settings == NULL) {
207                g_warning ("Unable to initialize settings");
208                goto out;
209        }
210
211        if (! gdm_settings_direct_init (settings, GDMCONFDIR "/gdm.schemas", "/")) {
212                g_warning ("Unable to initialize settings");
213                goto out;
214        }
215
216        gdm_log_set_debug (is_debug_set (debug));
217
218        if (display_id == NULL) {
219                g_critical ("No display ID set");
220                exit (1);
221        }
222
223        main_loop = g_main_loop_new (NULL, FALSE);
224
225        signal_handler = gdm_signal_handler_new ();
226        gdm_signal_handler_set_fatal_func (signal_handler,
227                                           (GDestroyNotify)g_main_loop_quit,
228                                           main_loop);
229        gdm_signal_handler_add (signal_handler, SIGTERM, signal_cb, NULL);
230        gdm_signal_handler_add (signal_handler, SIGINT, signal_cb, NULL);
231        gdm_signal_handler_add (signal_handler, SIGILL, signal_cb, NULL);
232        gdm_signal_handler_add (signal_handler, SIGBUS, signal_cb, NULL);
233        gdm_signal_handler_add (signal_handler, SIGFPE, signal_cb, NULL);
234        gdm_signal_handler_add (signal_handler, SIGHUP, signal_cb, NULL);
235        gdm_signal_handler_add (signal_handler, SIGSEGV, signal_cb, NULL);
236        gdm_signal_handler_add (signal_handler, SIGABRT, signal_cb, NULL);
237        gdm_signal_handler_add (signal_handler, SIGUSR1, signal_cb, NULL);
238        gdm_signal_handler_add (signal_handler, SIGUSR2, signal_cb, NULL);
239
240        slave = gdm_xdmcp_chooser_slave_new (display_id);
241        if (slave == NULL) {
242                goto out;
243        }
244        g_signal_connect (slave,
245                          "stopped",
246                          G_CALLBACK (on_slave_stopped),
247                          main_loop);
248        gdm_slave_start (slave);
249
250        g_main_loop_run (main_loop);
251
252        if (slave != NULL) {
253                g_object_unref (slave);
254        }
255
256        if (signal_handler != NULL) {
257                g_object_unref (signal_handler);
258        }
259
260        g_main_loop_unref (main_loop);
261
262 out:
263
264        g_debug ("Slave finished");
265
266        return gdm_return_code;
267}
Note: See TracBrowser for help on using the repository browser.