[gdm] Port to g_unix_signal_add(), drop GdmSignalHandler
- From: Ray Strode <halfline src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdm] Port to g_unix_signal_add(), drop GdmSignalHandler
- Date: Tue, 22 Jan 2013 16:56:42 +0000 (UTC)
commit 4952f6e5b023428e5f11f763531533c7b262f324
Author: Colin Walters <walters verbum org>
Date: Mon Dec 3 13:53:44 2012 -0500
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.
https://bugzilla.gnome.org/show_bug.cgi?id=676181
.gitignore | 1 -
common/Makefile.am | 16 -
common/gdm-common.h | 2 +-
common/gdm-crash-logger.c | 105 -------
common/gdm-signal-handler.c | 549 -------------------------------------
common/gdm-signal-handler.h | 75 -----
daemon/gdm-server.c | 51 +---
daemon/main.c | 87 ++----
daemon/session-worker-main.c | 67 +----
daemon/simple-slave-main.c | 73 +----
daemon/xdmcp-chooser-slave-main.c | 93 ++-----
gui/simple-greeter/greeter-main.c | 57 +----
po/POTFILES.in | 1 -
13 files changed, 97 insertions(+), 1080 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index d5d62b6..944923a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -93,7 +93,6 @@ Xsession
INSTALL
aclocal.m4
autom4te.cache/
-common/gdm-crash-logger
common/test-log
common/test-settings-client
common/test-settings-server
diff --git a/common/Makefile.am b/common/Makefile.am
index 1534ccb..c28d9b2 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -35,20 +35,6 @@ BUILT_SOURCES = \
gdmdir = $(datadir)/gdm
gdm_DATA = gdb-cmd
-libexec_PROGRAMS = gdm-crash-logger
-gdm_crash_logger_SOURCES = gdm-crash-logger.c
-gdm_crash_logger_CPPFLAGS = \
- $(AM_CPPFLAGS) \
- $(GTHREAD_CFLAGS) \
- -DG_DISABLE_DEPRECATED \
- -DBINDIR=\"$(bindir)\" \
- -DSBINDIR=\"$(sbindir)\" \
- -DDATADIR=\"$(datadir)\" \
- -DSYSCONFDIR=\"$(sysconfdir)\" \
- -DLOCALSTATEDIR=\"$(localstatedir)\" \
- $(NULL)
-gdm_crash_logger_LDADD = $(GTHREAD_LIBS)
-
gdm-settings-glue.c gdm-settings-glue.h : gdm-settings.xml Makefile.am
$(AM_V_GEN)gdbus-codegen \
--c-namespace=GdmDBus \
@@ -84,8 +70,6 @@ libgdmcommon_la_SOURCES = \
gdm-settings-client.c \
gdm-log.h \
gdm-log.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 7c72990..61d2dd3 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 <errno.h>
diff --git a/daemon/gdm-server.c b/daemon/gdm-server.c
index 83bbce9..01fc5d4 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 316e908..b2ec1bf 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;
+ return TRUE;
+}
- default:
- g_debug ("Caught unhandled signal %d", signo);
- ret = TRUE;
+static gboolean
+on_sigusr1_cb (gpointer user_data)
+{
+ g_debug ("Got USR1 signal");
- break;
- }
+ gdm_log_toggle_debug ();
- return ret;
+ 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;
@@ -430,15 +409,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);
@@ -450,7 +424,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 57027cf..40cd08b 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;
+ return FALSE;
+}
- default:
- g_debug ("Caught unhandled signal %d", signo);
- ret = TRUE;
+static gboolean
+on_sigusr1_cb (gpointer user_data)
+{
+ g_debug ("Got USR1 signal");
- break;
- }
+ gdm_log_toggle_debug ();
- return ret;
+ 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 [] = {
@@ -161,13 +131,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);
@@ -175,13 +141,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 b6e6ee4..52fc9b0 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 ();
+ return FALSE;
+}
- break;
+static gboolean
+on_sigusr2_cb (gpointer user_data)
+{
+ g_debug ("Got USR2 signal");
- default:
- g_debug ("Caught unhandled signal %d", signo);
- ret = TRUE;
+ gdm_log_toggle_debug ();
- break;
- }
-
- return ret;
+ 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 }
@@ -207,15 +172,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) {
@@ -233,10 +192,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 e6bd30c..0c122dc 100644
--- a/daemon/xdmcp-chooser-slave-main.c
+++ b/daemon/xdmcp-chooser-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-xdmcp-chooser-slave.h"
@@ -69,61 +68,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 +78,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 +120,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 }
@@ -200,15 +163,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) {
@@ -226,10 +183,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/gui/simple-greeter/greeter-main.c b/gui/simple-greeter/greeter-main.c
index d83493e..b17da46 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;
+ g_debug ("Got USR1 signal");
- case SIGUSR1:
- g_debug ("Got USR1 signal");
- /* FIXME:
- * Play with log levels or something
- */
- ret = TRUE;
+ gdm_log_toggle_debug ();
- gdm_log_toggle_debug ();
-
- break;
-
- default:
- g_debug ("Caught unhandled signal %d", signo);
- ret = TRUE;
-
- break;
- }
-
- return ret;
+ 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");
@@ -285,12 +243,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 d272658..d8fdd61 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -8,7 +8,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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]