[gdm/wip/modernize: 5/10] Port to g_unix_signal_add(), drop GdmSignalHandler
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdm/wip/modernize: 5/10] Port to g_unix_signal_add(), drop GdmSignalHandler
- Date: Mon, 3 Dec 2012 19:33:27 +0000 (UTC)
commit bc10ee71ce68acad963a72307c8f06240a99b2e1
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.
common/Makefile.am | 2 -
common/gdm-common.h | 2 +-
common/gdm-signal-handler.c | 549 -------------------------------------
common/gdm-signal-handler.h | 75 -----
daemon/gdm-server.c | 51 +---
daemon/main.c | 91 +++----
daemon/session-worker-main.c | 71 +----
daemon/simple-slave-main.c | 77 +----
daemon/xdmcp-chooser-slave-main.c | 88 ++-----
gui/simple-greeter/greeter-main.c | 61 +----
po/POTFILES.in | 1 -
11 files changed, 105 insertions(+), 963 deletions(-)
---
diff --git a/common/Makefile.am b/common/Makefile.am
index 001e282..a93b72c 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 1a0c258..f1e945b 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/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 a5a3b52..7a8c8e2 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 3383e66..fb3d3a7 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 866d814..7df80fb 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 8b58aba..450e37b 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 7d9632c..055f031 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 a6cbf72..94db926 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]