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