[PATCH] for gnome-session



Hi

Attached patch makes gnome-session use a single GConfClient instead of being getting/unreffing
it every time it's needed.

This is safe code-wise and makes startup improve a little bit more, apart from fixing a couple
of leaks (initialize_ice and set_sessionsave_mode). It's been approved
already by Vincent Untz on IRC.
-- 
Rodrigo Moya <rodrigo novell com>
? depcomp
? nohup.out
? performance.patch
? stamp-h1
? gnome-session/gsm-motd.c
? gnome-session/gsm-motd.h
? po/stamp-it
Index: gnome-session/ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-session/gnome-session/ChangeLog,v
retrieving revision 1.482
diff -u -p -r1.482 ChangeLog
--- gnome-session/ChangeLog	9 Mar 2006 22:09:39 -0000	1.482
+++ gnome-session/ChangeLog	10 Mar 2006 11:13:05 -0000
@@ -1,3 +1,17 @@
+2006-03-10  Rodrigo Moya <rodrigo novell com>
+
+	* util.[ch] (gsm_get_conf_client): new function to share a
+	GConfClient in all modules.
+
+	* gsm-at-startup.c (gsm_assistive_technologies_start):
+	* gsm-remote-desktop.c (gsm_remote_desktop_start):
+	* gsm-sound.c (esd_enabled, sound_events_enabled):
+	* gsm-xrandr.c (gsm_set_display_properties):
+	* ice.c (initialize_ice):
+	* logout.c (get_default_option, set_default_option):
+	* main.c (main):
+	* save.c (set_autosave_mode): use the shared GConfClient.
+
 2006-03-09  Thomas Wood  <thos gnome org>
 
 	* gnome-splash.png: New splash screen for GNOME 2.14.
Index: gnome-session/gsm-at-startup.c
===================================================================
RCS file: /cvs/gnome/gnome-session/gnome-session/gsm-at-startup.c,v
retrieving revision 1.3
diff -u -p -r1.3 gsm-at-startup.c
--- gnome-session/gsm-at-startup.c	10 Jan 2006 00:48:20 -0000	1.3
+++ gnome-session/gsm-at-startup.c	10 Mar 2006 11:13:05 -0000
@@ -27,7 +27,7 @@ gsm_assistive_technologies_start (void)
   GConfClient *client;
   GSList *list;
 
-  client  = gconf_client_get_default ();
+  client  = gsm_get_conf_client ();
   list = gconf_client_get_list (client, AT_STARTUP_KEY, GCONF_VALUE_STRING, &error);
   if (error)
     {
@@ -45,7 +45,6 @@ gsm_assistive_technologies_start (void)
 	}
       g_slist_free (list);
     }
-  g_object_unref (client);
 }
 
 void
Index: gnome-session/gsm-remote-desktop.c
===================================================================
RCS file: /cvs/gnome/gnome-session/gnome-session/gsm-remote-desktop.c,v
retrieving revision 1.2
diff -u -p -r1.2 gsm-remote-desktop.c
--- gnome-session/gsm-remote-desktop.c	3 Feb 2006 15:55:23 -0000	1.2
+++ gnome-session/gsm-remote-desktop.c	10 Mar 2006 11:13:06 -0000
@@ -250,7 +250,7 @@ static RemoteDesktopData remote_desktop_
 void
 gsm_remote_desktop_start (void)
 {
-  remote_desktop_data.client = gconf_client_get_default ();
+  remote_desktop_data.client = gsm_get_conf_client ();
 
   remote_desktop_data.enabled = gconf_client_get_bool (remote_desktop_data.client,
 						       REMOTE_DESKTOP_KEY,
@@ -287,6 +287,5 @@ gsm_remote_desktop_cleanup (void)
   gconf_client_notify_remove (remote_desktop_data.client, remote_desktop_data.listener);
   remote_desktop_data.listener = 0;
 
-  g_object_unref (remote_desktop_data.client);
   remote_desktop_data.client = NULL;
 }
Index: gnome-session/gsm-sound.c
===================================================================
RCS file: /cvs/gnome/gnome-session/gnome-session/gsm-sound.c,v
retrieving revision 1.5
diff -u -p -r1.5 gsm-sound.c
--- gnome-session/gsm-sound.c	8 Oct 2002 03:01:09 -0000	1.5
+++ gnome-session/gsm-sound.c	10 Mar 2006 11:13:06 -0000
@@ -5,8 +5,8 @@
 #ifdef HAVE_ESD /* almost whole file */
 #include <unistd.h>
 #include <libgnome/libgnome.h>
-#include <gconf/gconf-client.h>
 #include <esd.h>
+#include "util.h"
 
 #define ENABLE_ESD_KEY    "/desktop/gnome/sound/enable_esd"
 #define ENABLE_SOUNDS_KEY "/desktop/gnome/sound/event_sounds"
@@ -18,7 +18,7 @@ esd_enabled (void)
   GError      *error = NULL;
   gboolean     retval;
 
-  client = gconf_client_get_default ();
+  client = gsm_get_conf_client ();
 
   retval = gconf_client_get_bool (client, ENABLE_ESD_KEY, &error);
   if (error)
@@ -28,8 +28,6 @@ esd_enabled (void)
       return FALSE;  /* Fallback value */
     }
 
-  g_object_unref (client);
-
   return retval;
 }
 
@@ -40,7 +38,7 @@ sound_events_enabled (void)
   GError      *error = NULL;
   gboolean     retval;
 
-  client = gconf_client_get_default ();
+  client = gsm_get_conf_client ();
 
   retval = gconf_client_get_bool (client, ENABLE_SOUNDS_KEY, &error);
   if (error)
@@ -50,8 +48,6 @@ sound_events_enabled (void)
       return FALSE;  /* Fallback value */
     }
 
-  g_object_unref (client);
-
   return retval;
 }
 
@@ -60,7 +56,7 @@ start_esd (void) 
 {
   GError *err = NULL;
   time_t starttime;
-	
+
   if (!g_spawn_command_line_async (ESD_SERVER" -nobeeps", &err))
     {
       g_warning ("Could not start esd: %s\n", err->message);
@@ -72,13 +68,13 @@ start_esd (void) 
   gnome_sound_init (NULL);
 
   while (gnome_sound_connection_get () < 0
-	 && ((time(NULL) - starttime) < 4)) 
+	 && ((time(NULL) - starttime) < 4))
     {
 #ifdef HAVE_USLEEP
       usleep(200);
 #endif
       gnome_sound_init(NULL);
-    }  
+    }
 }
 
 static gboolean
Index: gnome-session/gsm-xrandr.c
===================================================================
RCS file: /cvs/gnome/gnome-session/gnome-session/gsm-xrandr.c,v
retrieving revision 1.3
diff -u -p -r1.3 gsm-xrandr.c
--- gnome-session/gsm-xrandr.c	4 Aug 2005 15:25:44 -0000	1.3
+++ gnome-session/gsm-xrandr.c	10 Mar 2006 11:13:06 -0000
@@ -131,7 +131,7 @@ gsm_set_display_properties (void)
       return;
     }
 
-  client = gconf_client_get_default ();
+  client = gsm_get_conf_client ();
   
   i = 0;
   specific_path = NULL;
@@ -195,8 +195,6 @@ gsm_set_display_properties (void)
 	    }
 	}
     }
-	  
-  g_object_unref (client);
   
   g_free (specific_path);
 
Index: gnome-session/ice.c
===================================================================
RCS file: /cvs/gnome/gnome-session/gnome-session/ice.c,v
retrieving revision 1.38
diff -u -p -r1.38 ice.c
--- gnome-session/ice.c	16 May 2005 22:43:47 -0000	1.38
+++ gnome-session/ice.c	10 Mar 2006 11:13:06 -0000
@@ -333,7 +333,7 @@ initialize_ice (void)
   saved_umask = umask (0);
   umask (saved_umask);
 
-  allow_tcp = gconf_client_get_bool (gconf_client_get_default (), ALLOW_TCP_KEY, NULL);
+  allow_tcp = gconf_client_get_bool (gsm_get_conf_client (), ALLOW_TCP_KEY, NULL);
  
   if (SmsInitialize (GsmVendor, VERSION, new_client, NULL,
 		     auth_proc, sizeof error, error)) 
Index: gnome-session/logout.c
===================================================================
RCS file: /cvs/gnome/gnome-session/gnome-session/logout.c,v
retrieving revision 1.60
diff -u -p -r1.60 logout.c
--- gnome-session/logout.c	26 Apr 2005 10:56:50 -0000	1.60
+++ gnome-session/logout.c	10 Mar 2006 11:13:06 -0000
@@ -290,13 +290,12 @@ get_default_option (void)
   char        *str;
   int          option;
 
-  gconf_client = gconf_client_get_default ();
+  gconf_client = gsm_get_conf_client ();
   str = gconf_client_get_string (gconf_client, LOGOUT_OPTION_KEY, NULL);
 
   if (str == NULL || !gconf_string_to_enum (logout_options_lookup_table, str, &option))
     option = OPTION_LOGOUT;
-  
-  g_object_unref (gconf_client);
+
   g_free (str);
   return option;
 }
@@ -307,14 +306,12 @@ set_default_option (int option)
   GConfClient *gconf_client;
   const char  *str;
 
-  gconf_client = gconf_client_get_default ();
+  gconf_client = gsm_get_conf_client ();
 
   str = gconf_enum_to_string (logout_options_lookup_table, option);
   g_assert (str != NULL);
 
   gconf_client_set_string (gconf_client, LOGOUT_OPTION_KEY, str, NULL);
-
-  g_object_unref (gconf_client);
 }
 
 static gboolean
Index: gnome-session/main.c
===================================================================
RCS file: /cvs/gnome/gnome-session/gnome-session/main.c,v
retrieving revision 1.76
diff -u -p -r1.76 main.c
--- gnome-session/main.c	6 Mar 2006 13:30:08 -0000	1.76
+++ gnome-session/main.c	10 Mar 2006 11:13:06 -0000
@@ -327,13 +327,13 @@ main (int argc, char *argv[])
   char *ep;
   char *session_name_env;
   Session *the_session;
-  GConfClient *gconf_client;
   gboolean splashing;
   gboolean a_t_support;
   GError *err;
   int status;
   char *display_str;
   char **versions;
+  GConfClient *gconf_client;
   
   if (getenv ("GSM_VERBOSE_DEBUG"))
     gsm_set_verbose (TRUE);
@@ -391,7 +391,7 @@ main (int argc, char *argv[])
     }
   
   /* Read the config option early, so that we know if a11y is set or not */ 
-  gconf_client = gconf_client_get_default ();
+  gconf_client = gsm_get_conf_client ();
   gconf_client_add_dir (gconf_client, GSM_GCONF_CONFIG_PREFIX, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); 
   a_t_support = gconf_client_get_bool (gconf_client, ACCESSIBILITY_KEY, NULL);
 
@@ -446,8 +446,6 @@ main (int argc, char *argv[])
 			   update_boolean,
 			   &logout_prompt, NULL, NULL);
 
-  g_object_unref (gconf_client);
-
   gnome_config_push_prefix (GSM_OPTION_CONFIG_PREFIX);
 
   /* If the session wasn't set on the command line, but we see a
@@ -497,7 +495,8 @@ main (int argc, char *argv[])
   gsm_sound_logout ();
 
   gsm_keyring_daemon_stop ();
-  
+
+  g_object_unref (gconf_client);
   gsm_shutdown_gconfd ();
 
   clean_ice ();
Index: gnome-session/save.c
===================================================================
RCS file: /cvs/gnome/gnome-session/gnome-session/save.c,v
retrieving revision 1.77
diff -u -p -r1.77 save.c
--- gnome-session/save.c	28 Feb 2006 16:21:56 -0000	1.77
+++ gnome-session/save.c	10 Mar 2006 11:13:06 -0000
@@ -598,7 +598,7 @@ set_sessionsave_mode (gboolean sessionsa
 void 
 set_autosave_mode (gboolean auto_save_mode)
 {
-      gconf_client_set_bool (gconf_client_get_default (), AUTOSAVE_MODE_KEY, auto_save_mode, NULL);
+      gconf_client_set_bool (gsm_get_conf_client (), AUTOSAVE_MODE_KEY, auto_save_mode, NULL);
 }
 
 void
Index: gnome-session/util.c
===================================================================
RCS file: /cvs/gnome/gnome-session/gnome-session/util.c,v
retrieving revision 1.3
diff -u -p -r1.3 util.c
--- gnome-session/util.c	27 Sep 2004 17:48:49 -0000	1.3
+++ gnome-session/util.c	10 Mar 2006 11:13:06 -0000
@@ -140,3 +140,14 @@ gsm_compare_commands (int argc1, char **
 
 	return TRUE;
 }
+
+GConfClient *
+gsm_get_conf_client (void)
+{
+	static GConfClient *client = NULL;
+
+	if (!client)
+		client = gconf_client_get_default ();
+
+	return client;
+}
Index: gnome-session/util.h
===================================================================
RCS file: /cvs/gnome/gnome-session/gnome-session/util.h,v
retrieving revision 1.3
diff -u -p -r1.3 util.h
--- gnome-session/util.h	27 Sep 2004 17:48:49 -0000	1.3
+++ gnome-session/util.h	10 Mar 2006 11:13:06 -0000
@@ -3,6 +3,7 @@
 
 #include <glib.h>
 #include <stdio.h>
+#include <gconf/gconf-client.h>
 
 void gsm_warning    (const char *format,
                      ...) G_GNUC_PRINTF (1, 2);
@@ -18,5 +19,7 @@ void gsm_set_verbose (gboolean setting);
 
 gboolean gsm_compare_commands (int argc1, char **argv1,
 			       int argc2, char **argv2);
+
+GConfClient *gsm_get_conf_client (void);
 
 #endif /* UTIL_H */


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