summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2012-12-03 13:53:44 -0500
committerColin Walters <walters@verbum.org>2012-12-03 14:24:28 -0500
commitbc10ee71ce68acad963a72307c8f06240a99b2e1 (patch)
tree38b0686216edf0d76ca74530d3a3676f5f9e2ee1
parente6a7263a058c3fa767265524ebb9c920be36722b (diff)
downloadgdm-bc10ee71ce68acad963a72307c8f06240a99b2e1.tar.gz
Port to g_unix_signal_add(), drop GdmSignalHandler
The level of copy/paste going on here before is rather astonishing. For example, in some cases, I dropped spurious handling of SIGHUP, when the code didn't have any settings to reread. Anyways, the code is now clearer, and we get to drop all the bits of gdm-signal-handler.[ch] for the integrated GLib handling.
-rw-r--r--common/Makefile.am2
-rw-r--r--common/gdm-common.h2
-rw-r--r--common/gdm-signal-handler.c549
-rw-r--r--common/gdm-signal-handler.h75
-rw-r--r--daemon/gdm-server.c51
-rw-r--r--daemon/main.c91
-rw-r--r--daemon/session-worker-main.c71
-rw-r--r--daemon/simple-slave-main.c77
-rw-r--r--daemon/xdmcp-chooser-slave-main.c88
-rw-r--r--gui/simple-greeter/greeter-main.c61
-rw-r--r--po/POTFILES.in1
11 files changed, 105 insertions, 963 deletions
diff --git a/common/Makefile.am b/common/Makefile.am
index 001e2824..a93b72c0 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -74,8 +74,6 @@ libgdmcommon_la_SOURCES = \
gdm-log.c \
gdm-md5.h \
gdm-md5.c \
- gdm-signal-handler.h \
- gdm-signal-handler.c \
$(MKDTEMP_FILES) \
$(NULL)
diff --git a/common/gdm-common.h b/common/gdm-common.h
index 1a0c2583..f1e945bf 100644
--- a/common/gdm-common.h
+++ b/common/gdm-common.h
@@ -21,7 +21,7 @@
#ifndef _GDM_COMMON_H
#define _GDM_COMMON_H
-#include <glib.h>
+#include <glib-unix.h>
#include <pwd.h>
#include "gdm-common-unknown-origin.h"
diff --git a/common/gdm-signal-handler.c b/common/gdm-signal-handler.c
deleted file mode 100644
index ca2ef65a..00000000
--- a/common/gdm-signal-handler.c
+++ /dev/null
@@ -1,549 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2006 Red Hat, Inc.
- * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "config.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <string.h>
-#include <signal.h>
-#if HAVE_EXECINFO_H
-#include <execinfo.h>
-#endif
-#include <syslog.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-
-#include <glib.h>
-#include <glib/gi18n.h>
-#include <glib/gstdio.h>
-#include <glib-object.h>
-
-#include "gdm-signal-handler.h"
-
-#define GDM_SIGNAL_HANDLER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_SIGNAL_HANDLER, GdmSignalHandlerPrivate))
-
-typedef struct {
- int signal_number;
- GdmSignalHandlerFunc func;
- gpointer data;
- guint id;
-} CallbackData;
-
-struct GdmSignalHandlerPrivate
-{
- GHashTable *lookup;
- GHashTable *id_lookup;
- GHashTable *action_lookup;
- guint next_id;
- GDestroyNotify fatal_func;
- gpointer fatal_data;
-};
-
-static void gdm_signal_handler_class_init (GdmSignalHandlerClass *klass);
-static void gdm_signal_handler_init (GdmSignalHandler *signal_handler);
-static void gdm_signal_handler_finalize (GObject *object);
-
-static gpointer signal_handler_object = NULL;
-static int signal_pipes[2];
-static int signals_blocked = 0;
-static sigset_t signals_block_mask;
-static sigset_t signals_oldmask;
-
-G_DEFINE_TYPE (GdmSignalHandler, gdm_signal_handler, G_TYPE_OBJECT)
-
-static void
-block_signals_push (void)
-{
- signals_blocked++;
-
- if (signals_blocked == 1) {
- /* Set signal mask */
- sigemptyset (&signals_block_mask);
- sigfillset (&signals_block_mask);
- sigprocmask (SIG_BLOCK, &signals_block_mask, &signals_oldmask);
- }
-}
-
-static void
-block_signals_pop (void)
-{
- signals_blocked--;
-
- if (signals_blocked == 0) {
- /* Set signal mask */
- sigprocmask (SIG_SETMASK, &signals_oldmask, NULL);
- }
-}
-
-static gboolean
-signal_io_watch (GIOChannel *ioc,
- GIOCondition condition,
- GdmSignalHandler *handler)
-{
- char buf[256];
- gboolean is_fatal;
- gsize bytes_read;
- int i;
-
- block_signals_push ();
-
- g_io_channel_read_chars (ioc, buf, sizeof (buf), &bytes_read, NULL);
-
- is_fatal = FALSE;
-
- for (i = 0; i < bytes_read; i++) {
- int signum;
- GSList *handlers;
- GSList *l;
-
- signum = (gint32)buf[i];
-
- g_debug ("GdmSignalHandler: handling signal %d", signum);
- handlers = g_hash_table_lookup (handler->priv->lookup, GINT_TO_POINTER (signum));
-
- g_debug ("GdmSignalHandler: Found %u callbacks", g_slist_length (handlers));
- for (l = handlers; l != NULL; l = l->next) {
- gboolean res;
- CallbackData *data;
-
- data = g_hash_table_lookup (handler->priv->id_lookup, l->data);
- if (data != NULL) {
- if (data->func != NULL) {
- g_debug ("GdmSignalHandler: running %d handler: %p", signum, data->func);
- res = data->func (signum, data->data);
- if (! res) {
- is_fatal = TRUE;
- }
- }
- }
- }
- }
-
- block_signals_pop ();
-
- if (is_fatal) {
- if (handler->priv->fatal_func != NULL) {
- g_debug ("GdmSignalHandler: Caught termination signal - calling fatal func");
- handler->priv->fatal_func (handler->priv->fatal_data);
- } else {
- g_debug ("GdmSignalHandler: Caught termination signal - exiting");
- exit (1);
- }
-
- return FALSE;
- }
-
- g_debug ("GdmSignalHandler: Done handling signals");
-
- return TRUE;
-}
-
-static void
-fallback_get_backtrace (void)
-{
-#ifdef HAVE_EXECINFO_H
- void * frames[64];
- size_t size;
- char ** strings;
- size_t i;
-
- size = backtrace (frames, G_N_ELEMENTS (frames));
- if ((strings = backtrace_symbols (frames, size))) {
- syslog (LOG_CRIT, "******************* START ********************************");
- for (i = 0; i < size; i++) {
- syslog (LOG_CRIT, "Frame %zd: %s", i, strings[i]);
- }
- free (strings);
- syslog (LOG_CRIT, "******************* END **********************************");
- return;
- }
-#endif
- g_warning ("GDM crashed, but symbols couldn't be retrieved.");
-}
-
-
-static gboolean
-crashlogger_get_backtrace (void)
-{
- gboolean success = FALSE;
- int pid;
-
- pid = fork ();
- if (pid > 0) {
- /* Wait for the child to finish */
- int estatus;
- if (waitpid (pid, &estatus, 0) != -1) {
- /* Only succeed if the crashlogger succeeded */
- if (WIFEXITED (estatus) && (WEXITSTATUS (estatus) == 0)) {
- success = TRUE;
- }
- }
- } else if (pid == 0) {
- /* Child process */
- execl (LIBEXECDIR "/gdm-crash-logger",
- LIBEXECDIR "/gdm-crash-logger", NULL);
- }
-
- return success;
-}
-
-
-static void
-gdm_signal_handler_backtrace (void)
-{
- struct stat s;
- gboolean fallback = TRUE;
-
- /* Try to use gdb via gdm-crash-logger if it exists, since
- * we get much better information out of it. Otherwise
- * fall back to execinfo.
- */
- if (g_stat (LIBEXECDIR "/gdm-crash-logger", &s) == 0) {
- fallback = crashlogger_get_backtrace () ? FALSE : TRUE;
- }
-
- if (fallback) {
- fallback_get_backtrace ();
- }
-}
-
-static void
-signal_handler (int signo)
-{
- static int in_fatal = 0;
- int ignore;
- guchar signo_byte = signo;
-
- /* avoid loops */
- if (in_fatal > 0) {
- return;
- }
-
- ++in_fatal;
-
- switch (signo) {
- case SIGSEGV:
- case SIGBUS:
- case SIGILL:
- case SIGABRT:
- case SIGTRAP:
- gdm_signal_handler_backtrace ();
- exit (1);
- break;
- case SIGFPE:
- case SIGPIPE:
- /* let the fatal signals interrupt us */
- --in_fatal;
- gdm_signal_handler_backtrace ();
- ignore = write (signal_pipes [1], &signo_byte, 1);
- break;
- default:
- --in_fatal;
- ignore = write (signal_pipes [1], &signo_byte, 1);
- break;
- }
-}
-
-static void
-catch_signal (GdmSignalHandler *handler,
- int signal_number)
-{
- struct sigaction action;
- struct sigaction *old_action;
-
- g_debug ("GdmSignalHandler: Registering for %d signals", signal_number);
-
- action.sa_handler = signal_handler;
- sigemptyset (&action.sa_mask);
- action.sa_flags = 0;
-
- old_action = g_new0 (struct sigaction, 1);
-
- sigaction (signal_number, &action, old_action);
-
- g_hash_table_insert (handler->priv->action_lookup,
- GINT_TO_POINTER (signal_number),
- old_action);
-}
-
-static void
-uncatch_signal (GdmSignalHandler *handler,
- int signal_number)
-{
- struct sigaction *old_action;
-
- g_debug ("GdmSignalHandler: Unregistering for %d signals", signal_number);
-
- old_action = g_hash_table_lookup (handler->priv->action_lookup,
- GINT_TO_POINTER (signal_number));
- g_hash_table_remove (handler->priv->action_lookup,
- GINT_TO_POINTER (signal_number));
-
- sigaction (signal_number, old_action, NULL);
-
- g_free (old_action);
-}
-
-guint
-gdm_signal_handler_add (GdmSignalHandler *handler,
- int signal_number,
- GdmSignalHandlerFunc callback,
- gpointer data)
-{
- CallbackData *cdata;
- GSList *list;
-
- g_return_val_if_fail (GDM_IS_SIGNAL_HANDLER (handler), 0);
-
- cdata = g_new0 (CallbackData, 1);
- cdata->signal_number = signal_number;
- cdata->func = callback;
- cdata->data = data;
- cdata->id = handler->priv->next_id++;
-
- g_debug ("GdmSignalHandler: Adding handler %u: signum=%d %p", cdata->id, cdata->signal_number, cdata->func);
-
- if (g_hash_table_lookup (handler->priv->action_lookup, GINT_TO_POINTER (signal_number)) == NULL) {
- catch_signal (handler, signal_number);
- }
-
- /* ID lookup owns the CallbackData */
- g_hash_table_insert (handler->priv->id_lookup, GUINT_TO_POINTER (cdata->id), cdata);
-
- list = g_hash_table_lookup (handler->priv->lookup, GINT_TO_POINTER (signal_number));
- list = g_slist_prepend (list, GUINT_TO_POINTER (cdata->id));
-
- g_hash_table_insert (handler->priv->lookup, GINT_TO_POINTER (signal_number), list);
-
- return cdata->id;
-}
-
-void
-gdm_signal_handler_add_fatal (GdmSignalHandler *handler)
-{
- g_return_if_fail (GDM_IS_SIGNAL_HANDLER (handler));
-
- gdm_signal_handler_add (handler, SIGILL, NULL, NULL);
- gdm_signal_handler_add (handler, SIGBUS, NULL, NULL);
- gdm_signal_handler_add (handler, SIGSEGV, NULL, NULL);
- gdm_signal_handler_add (handler, SIGABRT, NULL, NULL);
- gdm_signal_handler_add (handler, SIGTRAP, NULL, NULL);
-}
-
-static void
-callback_data_free (CallbackData *d)
-{
- g_free (d);
-}
-
-static void
-gdm_signal_handler_remove_and_free_data (GdmSignalHandler *handler,
- CallbackData *cdata)
-{
- GSList *list;
-
- g_return_if_fail (GDM_IS_SIGNAL_HANDLER (handler));
-
- list = g_hash_table_lookup (handler->priv->lookup, GINT_TO_POINTER (cdata->signal_number));
- list = g_slist_remove_all (list, GUINT_TO_POINTER (cdata->id));
- if (list == NULL) {
- uncatch_signal (handler, cdata->signal_number);
- }
-
- g_debug ("GdmSignalHandler: Removing handler %u: signum=%d %p", cdata->signal_number, cdata->id, cdata->func);
- /* put changed list back in */
- g_hash_table_insert (handler->priv->lookup, GINT_TO_POINTER (cdata->signal_number), list);
-
- g_hash_table_remove (handler->priv->id_lookup, GUINT_TO_POINTER (cdata->id));
-}
-
-void
-gdm_signal_handler_remove (GdmSignalHandler *handler,
- guint id)
-{
- CallbackData *found;
-
- g_return_if_fail (GDM_IS_SIGNAL_HANDLER (handler));
-
- found = g_hash_table_lookup (handler->priv->id_lookup, GUINT_TO_POINTER (id));
- if (found != NULL) {
- gdm_signal_handler_remove_and_free_data (handler, found);
- found = NULL;
- }
-}
-
-static CallbackData *
-find_callback_data_by_func (GdmSignalHandler *handler,
- guint signal_number,
- GdmSignalHandlerFunc callback,
- gpointer data)
-{
- GSList *list;
- GSList *l;
- CallbackData *found;
-
- found = NULL;
-
- list = g_hash_table_lookup (handler->priv->lookup, GINT_TO_POINTER (signal_number));
-
- for (l = list; l != NULL; l = l->next) {
- guint id;
- CallbackData *d;
-
- id = GPOINTER_TO_UINT (l->data);
-
- d = g_hash_table_lookup (handler->priv->id_lookup, GUINT_TO_POINTER (id));
- if (d != NULL
- && d->func == callback
- && d->data == data) {
- found = d;
- break;
- }
- }
-
- return found;
-}
-
-void
-gdm_signal_handler_remove_func (GdmSignalHandler *handler,
- guint signal_number,
- GdmSignalHandlerFunc callback,
- gpointer data)
-{
- CallbackData *found;
-
- g_return_if_fail (GDM_IS_SIGNAL_HANDLER (handler));
-
- found = find_callback_data_by_func (handler, signal_number, callback, data);
-
- if (found != NULL) {
- gdm_signal_handler_remove_and_free_data (handler, found);
- found = NULL;
- }
-
- /* FIXME: once all handlers are removed deregister signum handler */
-}
-
-static void
-gdm_signal_handler_class_init (GdmSignalHandlerClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = gdm_signal_handler_finalize;
-
- g_type_class_add_private (klass, sizeof (GdmSignalHandlerPrivate));
-}
-
-static void
-signal_list_free (GSList *list)
-{
- g_slist_free (list);
-}
-
-void
-gdm_signal_handler_set_fatal_func (GdmSignalHandler *handler,
- GDestroyNotify func,
- gpointer user_data)
-{
- g_return_if_fail (GDM_IS_SIGNAL_HANDLER (handler));
-
- handler->priv->fatal_func = func;
- handler->priv->fatal_data = user_data;
-}
-
-static void
-gdm_signal_handler_init (GdmSignalHandler *handler)
-{
- GIOChannel *ioc;
-
- handler->priv = GDM_SIGNAL_HANDLER_GET_PRIVATE (handler);
-
- handler->priv->next_id = 1;
-
- handler->priv->lookup = g_hash_table_new (NULL, NULL);
- handler->priv->id_lookup = g_hash_table_new (NULL, NULL);
- handler->priv->action_lookup = g_hash_table_new (NULL, NULL);
-
- if (pipe (signal_pipes) == -1) {
- g_error ("Could not create pipe() for signal handling");
- }
- fcntl(signal_pipes[0], F_SETFD, FD_CLOEXEC);
- fcntl(signal_pipes[1], F_SETFD, FD_CLOEXEC);
-
- ioc = g_io_channel_unix_new (signal_pipes[0]);
- g_io_channel_set_flags (ioc, G_IO_FLAG_NONBLOCK, NULL);
- g_io_add_watch (ioc, G_IO_IN, (GIOFunc)signal_io_watch, handler);
- g_io_channel_set_close_on_unref (ioc, TRUE);
- g_io_channel_unref (ioc);
-}
-
-static void
-gdm_signal_handler_finalize (GObject *object)
-{
- GdmSignalHandler *handler;
- GList *l;
-
- g_return_if_fail (object != NULL);
- g_return_if_fail (GDM_IS_SIGNAL_HANDLER (object));
-
- handler = GDM_SIGNAL_HANDLER (object);
-
- g_debug ("GdmSignalHandler: Finalizing signal handler");
-
- g_return_if_fail (handler->priv != NULL);
- for (l = g_hash_table_get_values (handler->priv->lookup);
- l != NULL; l = l->next) {
- signal_list_free ((GSList *) l->data);
- }
- g_hash_table_destroy (handler->priv->lookup);
- for (l = g_hash_table_get_values (handler->priv->id_lookup);
- l != NULL; l = l->next) {
- callback_data_free ((CallbackData *) l->data);
- }
- g_hash_table_destroy (handler->priv->id_lookup);
- for (l = g_hash_table_get_values (handler->priv->action_lookup);
- l != NULL; l = l->next) {
- g_free (l->data);
- }
- g_hash_table_destroy (handler->priv->action_lookup);
-
- close (signal_pipes [0]);
- close (signal_pipes [1]);
-
- G_OBJECT_CLASS (gdm_signal_handler_parent_class)->finalize (object);
-}
-
-GdmSignalHandler *
-gdm_signal_handler_new (void)
-{
- if (signal_handler_object != NULL) {
- g_object_ref (signal_handler_object);
- } else {
- signal_handler_object = g_object_new (GDM_TYPE_SIGNAL_HANDLER, NULL);
- g_object_add_weak_pointer (signal_handler_object,
- (gpointer *) &signal_handler_object);
- }
-
- return GDM_SIGNAL_HANDLER (signal_handler_object);
-}
diff --git a/common/gdm-signal-handler.h b/common/gdm-signal-handler.h
deleted file mode 100644
index 6909240c..00000000
--- a/common/gdm-signal-handler.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-
-#ifndef __GDM_SIGNAL_HANDLER_H
-#define __GDM_SIGNAL_HANDLER_H
-
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-#define GDM_TYPE_SIGNAL_HANDLER (gdm_signal_handler_get_type ())
-#define GDM_SIGNAL_HANDLER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GDM_TYPE_SIGNAL_HANDLER, GdmSignalHandler))
-#define GDM_SIGNAL_HANDLER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GDM_TYPE_SIGNAL_HANDLER, GdmSignalHandlerClass))
-#define GDM_IS_SIGNAL_HANDLER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GDM_TYPE_SIGNAL_HANDLER))
-#define GDM_IS_SIGNAL_HANDLER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GDM_TYPE_SIGNAL_HANDLER))
-#define GDM_SIGNAL_HANDLER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GDM_TYPE_SIGNAL_HANDLER, GdmSignalHandlerClass))
-
-
-typedef gboolean (*GdmSignalHandlerFunc) (int signal,
- gpointer data);
-
-typedef struct GdmSignalHandlerPrivate GdmSignalHandlerPrivate;
-
-typedef struct
-{
- GObject parent;
- GdmSignalHandlerPrivate *priv;
-} GdmSignalHandler;
-
-typedef struct
-{
- GObjectClass parent_class;
-} GdmSignalHandlerClass;
-
-GType gdm_signal_handler_get_type (void);
-
-GdmSignalHandler * gdm_signal_handler_new (void);
-void gdm_signal_handler_set_fatal_func (GdmSignalHandler *handler,
- GDestroyNotify func,
- gpointer user_data);
-
-void gdm_signal_handler_add_fatal (GdmSignalHandler *handler);
-guint gdm_signal_handler_add (GdmSignalHandler *handler,
- int signal_number,
- GdmSignalHandlerFunc callback,
- gpointer data);
-void gdm_signal_handler_remove (GdmSignalHandler *handler,
- guint id);
-void gdm_signal_handler_remove_func (GdmSignalHandler *handler,
- guint signal_number,
- GdmSignalHandlerFunc callback,
- gpointer data);
-
-
-G_END_DECLS
-
-#endif /* __GDM_SIGNAL_HANDLER_H */
diff --git a/daemon/gdm-server.c b/daemon/gdm-server.c
index 83bbce9d..01fc5d48 100644
--- a/daemon/gdm-server.c
+++ b/daemon/gdm-server.c
@@ -54,7 +54,6 @@
#include <X11/Xlib.h> /* for Display */
#include "gdm-common.h"
-#include "gdm-signal-handler.h"
#include "gdm-settings-direct.h"
#include "gdm-settings-keys.h"
@@ -96,6 +95,7 @@ struct GdmServerPrivate
char *chosen_hostname;
guint child_watch_id;
+ guint sigusr1_id;
gboolean is_initial;
};
@@ -190,51 +190,17 @@ gdm_server_get_display_device (GdmServer *server)
}
static gboolean
-emit_ready_idle (GdmServer *server)
+on_sigusr1 (gpointer user_data)
+
{
+ GdmServer *server = user_data;
+
g_debug ("GdmServer: Got USR1 from X server - emitting READY");
g_signal_emit (server, signals[READY], 0);
return FALSE;
}
-
-static gboolean
-signal_cb (int signo,
- GdmServer *server)
-
-{
- g_idle_add ((GSourceFunc)emit_ready_idle, server);
-
- return TRUE;
-}
-
-static void
-add_ready_handler (GdmServer *server)
-{
- GdmSignalHandler *signal_handler;
-
- signal_handler = gdm_signal_handler_new ();
- gdm_signal_handler_add (signal_handler,
- SIGUSR1,
- (GdmSignalHandlerFunc)signal_cb,
- server);
- g_object_unref (signal_handler);
-}
-
-static void
-remove_ready_handler (GdmServer *server)
-{
- GdmSignalHandler *signal_handler;
-
- signal_handler = gdm_signal_handler_new ();
- gdm_signal_handler_remove_func (signal_handler,
- SIGUSR1,
- (GdmSignalHandlerFunc)signal_cb,
- server);
- g_object_unref (signal_handler);
-}
-
/* We keep a connection (parent_dsp) open with the parent X server
* before running a proxy on it to prevent the X server resetting
* as we open and close other connections.
@@ -1080,7 +1046,9 @@ gdm_server_init (GdmServer *server)
server->priv->log_dir = g_strdup (LOGDIR);
- add_ready_handler (server);
+ server->priv->sigusr1_id = g_unix_signal_add (SIGUSR1,
+ on_sigusr1,
+ server);
}
static void
@@ -1095,7 +1063,8 @@ gdm_server_finalize (GObject *object)
g_return_if_fail (server->priv != NULL);
- remove_ready_handler (server);
+ if (server->priv->sigusr1_id > 0)
+ g_source_remove (server->priv->sigusr1_id);
gdm_server_stop (server);
diff --git a/daemon/main.c b/daemon/main.c
index a5a3b52c..7a8c8e22 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -43,7 +43,6 @@
#include "gdm-manager.h"
#include "gdm-log.h"
#include "gdm-common.h"
-#include "gdm-signal-handler.h"
#include "gdm-settings.h"
#include "gdm-settings-direct.h"
@@ -267,60 +266,41 @@ gdm_daemon_lookup_user (uid_t *uidp,
}
static gboolean
-signal_cb (int signo,
- gpointer data)
+on_shutdown_signal_cb (gpointer user_data)
{
- int ret;
+ GMainLoop *mainloop = user_data;
- g_debug ("Got callback for signal %d", signo);
+ g_main_loop_quit (mainloop);
- ret = TRUE;
+ return FALSE;
+}
- switch (signo) {
- case SIGINT:
- case SIGTERM:
- /* let the fatal signals interrupt us */
- g_debug ("Caught signal %d, shutting down normally.", signo);
- ret = FALSE;
-
- break;
-
- case SIGHUP:
- g_debug ("Got HUP signal");
- /* Reread config stuff like system config files, VPN service
- * files, etc
- */
- g_object_unref (settings);
- settings = gdm_settings_new ();
- if (settings != NULL) {
- if (! gdm_settings_direct_init (settings, DATADIR "/gdm/gdm.schemas", "/")) {
- g_warning ("Unable to initialize settings");
- }
+static gboolean
+on_sighup_cb (gpointer user_data)
+{
+ g_debug ("Got HUP signal");
+ /* Reread config stuff like system config files, VPN service
+ * files, etc
+ */
+ g_object_unref (settings);
+ settings = gdm_settings_new ();
+ if (settings != NULL) {
+ if (! gdm_settings_direct_init (settings, DATADIR "/gdm/gdm.schemas", "/")) {
+ g_warning ("Unable to initialize settings");
}
-
- ret = TRUE;
-
- break;
-
- case SIGUSR1:
- g_debug ("Got USR1 signal");
- /* FIXME:
- * Play with log levels or something
- */
- ret = TRUE;
-
- gdm_log_toggle_debug ();
-
- break;
-
- default:
- g_debug ("Caught unhandled signal %d", signo);
- ret = TRUE;
-
- break;
}
- return ret;
+ return TRUE;
+}
+
+static gboolean
+on_sigusr1_cb (gpointer user_data)
+{
+ g_debug ("Got USR1 signal");
+
+ gdm_log_toggle_debug ();
+
+ return TRUE;
}
static gboolean
@@ -346,7 +326,6 @@ main (int argc,
GError *error = NULL;
int ret;
gboolean res;
- GdmSignalHandler *signal_handler;
static gboolean do_timed_exit = FALSE;
static gboolean print_version = FALSE;
static gboolean fatal_warnings = FALSE;
@@ -432,15 +411,10 @@ main (int argc,
main_loop = g_main_loop_new (NULL, FALSE);
- signal_handler = gdm_signal_handler_new ();
- gdm_signal_handler_set_fatal_func (signal_handler,
- (GDestroyNotify)g_main_loop_quit,
- main_loop);
- gdm_signal_handler_add_fatal (signal_handler);
- gdm_signal_handler_add (signal_handler, SIGTERM, signal_cb, NULL);
- gdm_signal_handler_add (signal_handler, SIGINT, signal_cb, NULL);
- gdm_signal_handler_add (signal_handler, SIGHUP, signal_cb, NULL);
- gdm_signal_handler_add (signal_handler, SIGUSR1, signal_cb, NULL);
+ g_unix_signal_add (SIGTERM, on_shutdown_signal_cb, main_loop);
+ g_unix_signal_add (SIGINT, on_shutdown_signal_cb, main_loop);
+ g_unix_signal_add (SIGHUP, on_sighup_cb, NULL);
+ g_unix_signal_add (SIGUSR1, on_sigusr1_cb, NULL);
if (do_timed_exit) {
g_timeout_add_seconds (30, (GSourceFunc) timed_exit_cb, main_loop);
@@ -452,7 +426,6 @@ main (int argc,
g_clear_object (&manager);
g_clear_object (&settings);
- g_clear_object (&signal_handler);
gdm_settings_direct_shutdown ();
gdm_log_shutdown ();
diff --git a/daemon/session-worker-main.c b/daemon/session-worker-main.c
index 3383e66d..fb3d3a7e 100644
--- a/daemon/session-worker-main.c
+++ b/daemon/session-worker-main.c
@@ -35,7 +35,6 @@
#include <glib/gi18n.h>
#include <glib-object.h>
-#include "gdm-signal-handler.h"
#include "gdm-common.h"
#include "gdm-log.h"
#include "gdm-session-worker.h"
@@ -47,51 +46,23 @@
static GdmSettings *settings = NULL;
static gboolean
-signal_cb (int signo,
- gpointer data)
+on_shutdown_signal_cb (gpointer user_data)
{
- int ret;
+ GMainLoop *mainloop = user_data;
- g_debug ("Got callback for signal %d", signo);
+ g_main_loop_quit (mainloop);
- ret = TRUE;
-
- switch (signo) {
- case SIGINT:
- case SIGTERM:
- /* let the fatal signals interrupt us */
- g_debug ("Caught signal %d, shutting down normally.", signo);
- ret = FALSE;
- break;
-
- case SIGHUP:
- g_debug ("Got HUP signal");
- /* FIXME:
- * Reread config stuff like system config files, VPN service files, etc
- */
- ret = TRUE;
-
- break;
-
- case SIGUSR1:
- g_debug ("Got USR1 signal");
- /* FIXME:
- * Play with log levels or something
- */
- ret = TRUE;
-
- gdm_log_toggle_debug ();
-
- break;
-
- default:
- g_debug ("Caught unhandled signal %d", signo);
- ret = TRUE;
-
- break;
- }
+ return FALSE;
+}
- return ret;
+static gboolean
+on_sigusr1_cb (gpointer user_data)
+{
+ g_debug ("Got USR1 signal");
+
+ gdm_log_toggle_debug ();
+
+ return TRUE;
}
static gboolean
@@ -115,7 +86,6 @@ main (int argc,
GMainLoop *main_loop;
GOptionContext *context;
GdmSessionWorker *worker;
- GdmSignalHandler *signal_handler;
const char *address;
gboolean is_for_reauth;
static GOptionEntry entries [] = {
@@ -163,13 +133,9 @@ main (int argc,
main_loop = g_main_loop_new (NULL, FALSE);
- signal_handler = gdm_signal_handler_new ();
- gdm_signal_handler_set_fatal_func (signal_handler,
- (GDestroyNotify)g_main_loop_quit,
- main_loop);
- gdm_signal_handler_add (signal_handler, SIGINT, signal_cb, NULL);
- gdm_signal_handler_add (signal_handler, SIGHUP, signal_cb, NULL);
- gdm_signal_handler_add (signal_handler, SIGUSR1, signal_cb, NULL);
+ g_unix_signal_add (SIGTERM, on_shutdown_signal_cb, main_loop);
+ g_unix_signal_add (SIGINT, on_shutdown_signal_cb, main_loop);
+ g_unix_signal_add (SIGUSR1, on_sigusr1_cb, NULL);
g_main_loop_run (main_loop);
@@ -177,13 +143,8 @@ main (int argc,
g_object_unref (worker);
}
- if (signal_handler != NULL) {
- g_object_unref (signal_handler);
- }
-
g_main_loop_unref (main_loop);
-
g_debug ("Worker finished");
return 0;
diff --git a/daemon/simple-slave-main.c b/daemon/simple-slave-main.c
index 866d814d..7df80fb0 100644
--- a/daemon/simple-slave-main.c
+++ b/daemon/simple-slave-main.c
@@ -37,7 +37,6 @@
#include <gio/gio.h>
#include "gdm-xerrors.h"
-#include "gdm-signal-handler.h"
#include "gdm-log.h"
#include "gdm-common.h"
#include "gdm-simple-slave.h"
@@ -71,56 +70,23 @@ get_system_bus (void)
}
static gboolean
-signal_cb (int signo,
- gpointer data)
+on_shutdown_signal_cb (gpointer user_data)
{
- int ret;
+ GMainLoop *mainloop = user_data;
- g_debug ("Got callback for signal %d", signo);
+ g_main_loop_quit (mainloop);
- ret = TRUE;
-
- switch (signo) {
- case SIGINT:
- case SIGTERM:
- /* let the fatal signals interrupt us */
- g_debug ("Caught signal %d, shutting down normally.", signo);
- ret = FALSE;
-
- break;
-
- case SIGHUP:
- g_debug ("Got HUP signal");
- /* FIXME:
- * Reread config stuff like system config files, VPN service files, etc
- */
- ret = TRUE;
-
- break;
-
- case SIGUSR1:
- g_debug ("Got USR1 signal");
- /* we get this from xorg - can't use for anything else */
- ret = TRUE;
-
- break;
-
- case SIGUSR2:
- g_debug ("Got USR2 signal");
- ret = TRUE;
-
- gdm_log_toggle_debug ();
-
- break;
-
- default:
- g_debug ("Caught unhandled signal %d", signo);
- ret = TRUE;
-
- break;
- }
+ return FALSE;
+}
- return ret;
+static gboolean
+on_sigusr2_cb (gpointer user_data)
+{
+ g_debug ("Got USR2 signal");
+
+ gdm_log_toggle_debug ();
+
+ return TRUE;
}
static void
@@ -155,7 +121,6 @@ main (int argc,
GDBusConnection *connection;
GdmSlave *slave;
static char *display_id = NULL;
- GdmSignalHandler *signal_handler;
static GOptionEntry entries [] = {
{ "display-id", 0, 0, G_OPTION_ARG_STRING, &display_id, N_("Display ID"), N_("ID") },
{ NULL }
@@ -209,15 +174,9 @@ main (int argc,
main_loop = g_main_loop_new (NULL, FALSE);
- signal_handler = gdm_signal_handler_new ();
- gdm_signal_handler_set_fatal_func (signal_handler,
- (GDestroyNotify)g_main_loop_quit,
- main_loop);
- gdm_signal_handler_add (signal_handler, SIGTERM, signal_cb, NULL);
- gdm_signal_handler_add (signal_handler, SIGINT, signal_cb, NULL);
- gdm_signal_handler_add (signal_handler, SIGHUP, signal_cb, NULL);
- gdm_signal_handler_add (signal_handler, SIGUSR1, signal_cb, NULL);
- gdm_signal_handler_add (signal_handler, SIGUSR2, signal_cb, NULL);
+ g_unix_signal_add (SIGTERM, on_shutdown_signal_cb, main_loop);
+ g_unix_signal_add (SIGINT, on_shutdown_signal_cb, main_loop);
+ g_unix_signal_add (SIGUSR2, on_sigusr2_cb, NULL);
slave = gdm_simple_slave_new (display_id);
if (slave == NULL) {
@@ -235,10 +194,6 @@ main (int argc,
g_object_unref (slave);
}
- if (signal_handler != NULL) {
- g_object_unref (signal_handler);
- }
-
g_main_loop_unref (main_loop);
out:
diff --git a/daemon/xdmcp-chooser-slave-main.c b/daemon/xdmcp-chooser-slave-main.c
index 8b58abaa..450e37bf 100644
--- a/daemon/xdmcp-chooser-slave-main.c
+++ b/daemon/xdmcp-chooser-slave-main.c
@@ -69,61 +69,6 @@ get_system_bus (void)
return bus;
}
-static gboolean
-signal_cb (int signo,
- gpointer data)
-{
- int ret;
-
- g_debug ("Got callback for signal %d", signo);
-
- ret = TRUE;
-
- switch (signo) {
- case SIGINT:
- case SIGTERM:
- /* let the fatal signals interrupt us */
- g_debug ("Caught signal %d, shutting down normally.", signo);
- ret = FALSE;
-
- break;
-
- case SIGHUP:
- g_debug ("Got HUP signal");
- /* FIXME:
- * Reread config stuff like system config files, VPN service files, etc
- */
- ret = TRUE;
-
- break;
-
- case SIGUSR1:
- g_debug ("Got USR1 signal");
- /* we get this from xorg - can't use for anything else */
- ret = TRUE;
-
- gdm_log_toggle_debug ();
-
- break;
-
- case SIGUSR2:
- g_debug ("Got USR2 signal");
- ret = TRUE;
-
- gdm_log_toggle_debug ();
-
- break;
-
- default:
- g_debug ("Caught unhandled signal %d", signo);
- ret = TRUE;
-
- break;
- }
-
- return ret;
-}
-
static void
on_slave_stopped (GdmSlave *slave,
GMainLoop *main_loop)
@@ -134,6 +79,26 @@ on_slave_stopped (GdmSlave *slave,
}
static gboolean
+on_shutdown_signal_cb (gpointer user_data)
+{
+ GMainLoop *mainloop = user_data;
+
+ g_main_loop_quit (mainloop);
+
+ return FALSE;
+}
+
+static gboolean
+on_sigusr2_cb (gpointer user_data)
+{
+ g_debug ("Got USR2 signal");
+
+ gdm_log_toggle_debug ();
+
+ return TRUE;
+}
+
+static gboolean
is_debug_set (void)
{
gboolean debug = FALSE;
@@ -156,7 +121,6 @@ main (int argc,
GDBusConnection *connection;
GdmSlave *slave;
static char *display_id = NULL;
- GdmSignalHandler *signal_handler;
static GOptionEntry entries [] = {
{ "display-id", 0, 0, G_OPTION_ARG_STRING, &display_id, N_("Display ID"), N_("ID") },
{ NULL }
@@ -202,15 +166,9 @@ main (int argc,
main_loop = g_main_loop_new (NULL, FALSE);
- signal_handler = gdm_signal_handler_new ();
- gdm_signal_handler_set_fatal_func (signal_handler,
- (GDestroyNotify)g_main_loop_quit,
- main_loop);
- gdm_signal_handler_add (signal_handler, SIGTERM, signal_cb, NULL);
- gdm_signal_handler_add (signal_handler, SIGINT, signal_cb, NULL);
- gdm_signal_handler_add (signal_handler, SIGHUP, signal_cb, NULL);
- gdm_signal_handler_add (signal_handler, SIGUSR1, signal_cb, NULL);
- gdm_signal_handler_add (signal_handler, SIGUSR2, signal_cb, NULL);
+ g_unix_signal_add (SIGTERM, on_shutdown_signal_cb, main_loop);
+ g_unix_signal_add (SIGINT, on_shutdown_signal_cb, main_loop);
+ g_unix_signal_add (SIGUSR2, on_sigusr2_cb, NULL);
slave = gdm_xdmcp_chooser_slave_new (display_id);
if (slave == NULL) {
diff --git a/gui/simple-greeter/greeter-main.c b/gui/simple-greeter/greeter-main.c
index 7d9632c2..055f031d 100644
--- a/gui/simple-greeter/greeter-main.c
+++ b/gui/simple-greeter/greeter-main.c
@@ -32,7 +32,6 @@
#include "gdm-log.h"
#include "gdm-common.h"
-#include "gdm-signal-handler.h"
#include "gdm-settings-client.h"
#include "gdm-settings-keys.h"
#include "gdm-profile.h"
@@ -67,54 +66,14 @@ is_debug_set (void)
return debug;
}
-
static gboolean
-signal_cb (int signo,
- gpointer data)
+on_sigusr1_cb (gpointer user_data)
{
- int ret;
-
- g_debug ("Got callback for signal %d", signo);
-
- ret = TRUE;
-
- switch (signo) {
- case SIGINT:
- case SIGTERM:
- /* let the fatal signals interrupt us */
- g_debug ("Caught signal %d, shutting down normally.", signo);
- ret = FALSE;
-
- break;
-
- case SIGHUP:
- g_debug ("Got HUP signal");
- /* FIXME:
- * Reread config stuff like system config files, VPN service files, etc
- */
- ret = TRUE;
-
- break;
-
- case SIGUSR1:
- g_debug ("Got USR1 signal");
- /* FIXME:
- * Play with log levels or something
- */
- ret = TRUE;
-
- gdm_log_toggle_debug ();
-
- break;
-
- default:
- g_debug ("Caught unhandled signal %d", signo);
- ret = TRUE;
-
- break;
- }
-
- return ret;
+ g_debug ("Got USR1 signal");
+
+ gdm_log_toggle_debug ();
+
+ return TRUE;
}
static gboolean
@@ -257,7 +216,6 @@ main (int argc, char *argv[])
GError *error;
GdmGreeterSession *session;
gboolean res;
- GdmSignalHandler *signal_handler;
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
@@ -287,12 +245,7 @@ main (int argc, char *argv[])
gtk_init (&argc, &argv);
- signal_handler = gdm_signal_handler_new ();
- gdm_signal_handler_add_fatal (signal_handler);
- gdm_signal_handler_add (signal_handler, SIGTERM, signal_cb, NULL);
- gdm_signal_handler_add (signal_handler, SIGINT, signal_cb, NULL);
- gdm_signal_handler_add (signal_handler, SIGHUP, signal_cb, NULL);
- gdm_signal_handler_add (signal_handler, SIGUSR1, signal_cb, NULL);
+ g_unix_signal_add (SIGUSR1, on_sigusr1_cb, NULL);
gdm_profile_start ("Creating new greeter session");
session = gdm_greeter_session_new ();
diff --git a/po/POTFILES.in b/po/POTFILES.in
index a6cbf726..94db9260 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -9,7 +9,6 @@ common/gdm-settings-client.c
common/gdm-settings-desktop-backend.c
common/gdm-settings-direct.c
common/gdm-settings-utils.c
-common/gdm-signal-handler.c
common/test-log.c
common/test-settings-client.c
common/test-settings-server.c