[134] | 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-common.h" |
---|
| 44 | #include "gdm-log.h" |
---|
| 45 | #include "gdm-session-worker.h" |
---|
| 46 | |
---|
| 47 | #define SERVER_DBUS_PATH "/org/gnome/DisplayManager/SessionServer" |
---|
| 48 | #define SERVER_DBUS_INTERFACE "org.gnome.DisplayManager.SessionServer" |
---|
| 49 | |
---|
| 50 | static gboolean |
---|
| 51 | signal_cb (int signo, |
---|
| 52 | gpointer data) |
---|
| 53 | { |
---|
| 54 | int ret; |
---|
| 55 | |
---|
| 56 | g_debug ("Got callback for signal %d", signo); |
---|
| 57 | |
---|
| 58 | ret = TRUE; |
---|
| 59 | |
---|
| 60 | switch (signo) { |
---|
| 61 | case SIGSEGV: |
---|
| 62 | case SIGBUS: |
---|
| 63 | case SIGILL: |
---|
| 64 | case SIGABRT: |
---|
| 65 | g_debug ("Caught signal %d.", signo); |
---|
| 66 | |
---|
| 67 | ret = FALSE; |
---|
| 68 | break; |
---|
| 69 | |
---|
| 70 | case SIGFPE: |
---|
| 71 | case SIGPIPE: |
---|
| 72 | /* let the fatal signals interrupt us */ |
---|
| 73 | g_debug ("Caught signal %d, shutting down abnormally.", signo); |
---|
| 74 | ret = FALSE; |
---|
| 75 | |
---|
| 76 | break; |
---|
| 77 | |
---|
| 78 | case SIGINT: |
---|
| 79 | case SIGTERM: |
---|
| 80 | /* let the fatal signals interrupt us */ |
---|
| 81 | g_debug ("Caught signal %d, shutting down normally.", signo); |
---|
| 82 | ret = FALSE; |
---|
| 83 | break; |
---|
| 84 | |
---|
| 85 | case SIGHUP: |
---|
| 86 | g_debug ("Got HUP signal"); |
---|
| 87 | /* FIXME: |
---|
| 88 | * Reread config stuff like system config files, VPN service files, etc |
---|
| 89 | */ |
---|
| 90 | ret = TRUE; |
---|
| 91 | |
---|
| 92 | break; |
---|
| 93 | |
---|
| 94 | case SIGUSR1: |
---|
| 95 | g_debug ("Got USR1 signal"); |
---|
| 96 | /* FIXME: |
---|
| 97 | * Play with log levels or something |
---|
| 98 | */ |
---|
| 99 | ret = TRUE; |
---|
| 100 | |
---|
| 101 | gdm_log_toggle_debug (); |
---|
| 102 | |
---|
| 103 | break; |
---|
| 104 | |
---|
| 105 | default: |
---|
| 106 | g_debug ("Caught unhandled signal %d", signo); |
---|
| 107 | ret = TRUE; |
---|
| 108 | |
---|
| 109 | break; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | return ret; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | static gboolean |
---|
| 116 | is_debug_set (gboolean arg) |
---|
| 117 | { |
---|
| 118 | /* enable debugging for unstable builds */ |
---|
| 119 | if (gdm_is_version_unstable ()) { |
---|
| 120 | return TRUE; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | return arg; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | int |
---|
| 127 | main (int argc, |
---|
| 128 | char **argv) |
---|
| 129 | { |
---|
| 130 | GMainLoop *main_loop; |
---|
| 131 | GOptionContext *context; |
---|
| 132 | GdmSessionWorker *worker; |
---|
| 133 | GdmSignalHandler *signal_handler; |
---|
| 134 | const char *address; |
---|
| 135 | static gboolean debug = FALSE; |
---|
| 136 | static GOptionEntry entries [] = { |
---|
| 137 | { "debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Enable debugging code"), NULL }, |
---|
| 138 | { NULL } |
---|
| 139 | }; |
---|
| 140 | |
---|
| 141 | bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); |
---|
| 142 | textdomain (GETTEXT_PACKAGE); |
---|
| 143 | setlocale (LC_ALL, ""); |
---|
| 144 | |
---|
| 145 | g_type_init (); |
---|
| 146 | |
---|
| 147 | gdm_set_fatal_warnings_if_unstable (); |
---|
| 148 | |
---|
| 149 | context = g_option_context_new (_("GNOME Display Manager Session Worker")); |
---|
| 150 | g_option_context_add_main_entries (context, entries, NULL); |
---|
| 151 | |
---|
| 152 | g_option_context_parse (context, &argc, &argv, NULL); |
---|
| 153 | g_option_context_free (context); |
---|
| 154 | |
---|
| 155 | gdm_log_init (); |
---|
| 156 | gdm_log_set_debug (is_debug_set (debug)); |
---|
| 157 | |
---|
| 158 | address = g_getenv ("GDM_SESSION_DBUS_ADDRESS"); |
---|
| 159 | if (address == NULL) { |
---|
| 160 | g_warning ("GDM_SESSION_DBUS_ADDRESS not set"); |
---|
| 161 | exit (1); |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | worker = gdm_session_worker_new (address); |
---|
| 165 | |
---|
| 166 | main_loop = g_main_loop_new (NULL, FALSE); |
---|
| 167 | |
---|
| 168 | signal_handler = gdm_signal_handler_new (); |
---|
| 169 | gdm_signal_handler_set_fatal_func (signal_handler, |
---|
| 170 | (GDestroyNotify)g_main_loop_quit, |
---|
| 171 | main_loop); |
---|
| 172 | gdm_signal_handler_add (signal_handler, SIGTERM, signal_cb, NULL); |
---|
| 173 | gdm_signal_handler_add (signal_handler, SIGINT, signal_cb, NULL); |
---|
| 174 | gdm_signal_handler_add (signal_handler, SIGILL, signal_cb, NULL); |
---|
| 175 | gdm_signal_handler_add (signal_handler, SIGBUS, signal_cb, NULL); |
---|
| 176 | gdm_signal_handler_add (signal_handler, SIGFPE, signal_cb, NULL); |
---|
| 177 | gdm_signal_handler_add (signal_handler, SIGHUP, signal_cb, NULL); |
---|
| 178 | gdm_signal_handler_add (signal_handler, SIGSEGV, signal_cb, NULL); |
---|
| 179 | gdm_signal_handler_add (signal_handler, SIGABRT, signal_cb, NULL); |
---|
| 180 | gdm_signal_handler_add (signal_handler, SIGUSR1, signal_cb, NULL); |
---|
| 181 | |
---|
| 182 | g_main_loop_run (main_loop); |
---|
| 183 | |
---|
| 184 | if (worker != NULL) { |
---|
| 185 | g_object_unref (worker); |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | if (signal_handler != NULL) { |
---|
| 189 | g_object_unref (signal_handler); |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | g_main_loop_unref (main_loop); |
---|
| 193 | |
---|
| 194 | |
---|
| 195 | g_debug ("Worker finished"); |
---|
| 196 | |
---|
| 197 | return 0; |
---|
| 198 | } |
---|