[gnome-keyring] [daemon] Fix a delay when the daemon quits



commit aabb6f6c77796e7d1f8ba961c109fa093291326c
Author: Vincent Untz <vuntz gnome org>
Date:   Fri Oct 2 19:27:07 2009 +0200

    [daemon] Fix a delay when the daemon quits
    
    g-k-d is a multi-threaded program, using a signal thread to stop the
    main loop. The main thread was using raise() to send SIGTERM to the
    signal thread, but it actually sends the signal to itself;
    pthread_kill() has to be used.
    
    This also implies a switch to pthread_create() instead of
    g_thread_create() since the GThread API doesn't cover pthread_kill().

 daemon/gkr-daemon.c |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)
---
diff --git a/daemon/gkr-daemon.c b/daemon/gkr-daemon.c
index c63081e..a2107d9 100644
--- a/daemon/gkr-daemon.c
+++ b/daemon/gkr-daemon.c
@@ -43,6 +43,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <pthread.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -90,6 +91,8 @@ static gboolean run_for_start = FALSE;
 static gchar* run_components = NULL;
 static gchar* login_password = NULL;
 static gboolean initialization_completed = FALSE;
+static gboolean sig_thread_valid = FALSE;
+static pthread_t sig_thread;
 
 static GOptionEntry option_entries[] = {
 	{ "foreground", 'f', 0, G_OPTION_ARG_NONE, &run_foreground, 
@@ -370,7 +373,7 @@ signal_thread (gpointer user_data)
 static void
 setup_signal_handling (GMainLoop *loop)
 {
-	GError *error = NULL;
+	int res;
 
 	/*
 	 * Block these signals for this thread, and any threads
@@ -387,11 +390,12 @@ setup_signal_handling (GMainLoop *loop)
 	sigaddset (&signal_set, SIGTERM);
 	pthread_sigmask (SIG_BLOCK, &signal_set, NULL);
 
-	g_thread_create (signal_thread, loop, FALSE, &error);
-	if (error != NULL) {
+	res = pthread_create (&sig_thread, NULL, signal_thread, loop);
+	if (res == 0) {
+		sig_thread_valid = TRUE;
+	} else {
 		g_warning ("couldn't startup thread for signal handling: %s",
-		           error && error->message ? error->message : "");
-		g_clear_error (&error);
+		           g_strerror (res));
 	}
 }
 
@@ -404,7 +408,10 @@ gkr_daemon_quit (void)
 	 * starts the shutdown process.
 	 */
 
-	raise (SIGTERM);
+	if (sig_thread_valid)
+		pthread_kill (sig_thread, SIGTERM);
+	else
+		raise (SIGTERM);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]