source: proiecte/PPPP/gdm/daemon/factory-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: 6.9 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-factory-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                /* FIXME:
120                 * Play with log levels or something
121                 */
122                ret = TRUE;
123
124                gdm_log_toggle_debug ();
125
126                break;
127
128        default:
129                g_debug ("Caught unhandled signal %d", signo);
130                ret = TRUE;
131
132                break;
133        }
134
135        return ret;
136}
137
138static void
139on_slave_stopped (GdmSlave   *slave,
140                  GMainLoop  *main_loop)
141{
142        g_debug ("slave finished");
143        gdm_return_code = 0;
144        g_main_loop_quit (main_loop);
145}
146
147static gboolean
148is_debug_set (gboolean arg)
149{
150        /* enable debugging for unstable builds */
151        if (gdm_is_version_unstable ()) {
152                return TRUE;
153        }
154
155        return arg;
156}
157
158int
159main (int    argc,
160      char **argv)
161{
162        GMainLoop        *main_loop;
163        GOptionContext   *context;
164        DBusGConnection  *connection;
165        GdmSlave         *slave;
166        static char      *display_id = NULL;
167        static gboolean   debug      = FALSE;
168        GdmSignalHandler *signal_handler;
169        static GOptionEntry entries []   = {
170                { "debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Enable debugging code"), NULL },
171                { "display-id", 0, 0, G_OPTION_ARG_STRING, &display_id, N_("Display ID"), N_("id") },
172                { NULL }
173        };
174
175        bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
176        textdomain (GETTEXT_PACKAGE);
177        setlocale (LC_ALL, "");
178
179        gdm_set_fatal_warnings_if_unstable ();
180
181        g_type_init ();
182
183        context = g_option_context_new (_("GNOME Display Manager Slave"));
184        g_option_context_add_main_entries (context, entries, NULL);
185
186        g_option_context_parse (context, &argc, &argv, NULL);
187        g_option_context_free (context);
188
189        connection = get_system_bus ();
190        if (connection == NULL) {
191                goto out;
192        }
193
194        gdm_log_init ();
195
196        gdm_log_set_debug (is_debug_set (debug));
197
198        if (display_id == NULL) {
199                g_critical ("No display ID set");
200                exit (1);
201        }
202
203        main_loop = g_main_loop_new (NULL, FALSE);
204
205        signal_handler = gdm_signal_handler_new ();
206        gdm_signal_handler_set_fatal_func (signal_handler,
207                                           (GDestroyNotify)g_main_loop_quit,
208                                           main_loop);
209        gdm_signal_handler_add (signal_handler, SIGTERM, signal_cb, NULL);
210        gdm_signal_handler_add (signal_handler, SIGINT, signal_cb, NULL);
211        gdm_signal_handler_add (signal_handler, SIGILL, signal_cb, NULL);
212        gdm_signal_handler_add (signal_handler, SIGBUS, signal_cb, NULL);
213        gdm_signal_handler_add (signal_handler, SIGFPE, signal_cb, NULL);
214        gdm_signal_handler_add (signal_handler, SIGHUP, signal_cb, NULL);
215        gdm_signal_handler_add (signal_handler, SIGSEGV, signal_cb, NULL);
216        gdm_signal_handler_add (signal_handler, SIGABRT, signal_cb, NULL);
217        gdm_signal_handler_add (signal_handler, SIGUSR1, signal_cb, NULL);
218        gdm_signal_handler_add (signal_handler, SIGUSR2, signal_cb, NULL);
219
220        slave = gdm_factory_slave_new (display_id);
221        if (slave == NULL) {
222                goto out;
223        }
224        g_signal_connect (slave,
225                          "stopped",
226                          G_CALLBACK (on_slave_stopped),
227                          main_loop);
228        gdm_slave_start (slave);
229
230        g_main_loop_run (main_loop);
231
232        if (slave != NULL) {
233                g_object_unref (slave);
234        }
235
236        if (signal_handler != NULL) {
237                g_object_unref (signal_handler);
238        }
239
240        if (main_loop != NULL) {
241                g_main_loop_unref (main_loop);
242        }
243
244 out:
245
246        g_debug ("Slave finished");
247
248        return gdm_return_code;
249}
Note: See TracBrowser for help on using the repository browser.