[PATCH] gnome-session: user set environment variables on startup



Hi,

The attached patch allows a user to add environment variables to
gnome-session on startup which are then inherited by client programs.
The environment variables are read from a gconf DB list at 
/apps/gnome-session/options/user_envrionment.

The reason for this is to allow things like having ~/bin in PATH for
such things as the Run dialog. AFAIK there is no other way to achieve
this through other login scripts.

If accepted I will add a tab to the gnome-session capplet to configure
the list of variables.

The patch files are against CVS head.
Index: gnome-session/gnome-session.schemas.in
===================================================================
RCS file: /cvs/gnome/gnome-session/gnome-session/gnome-session.schemas.in,v
retrieving revision 1.3
diff -b -B -u -r1.3 gnome-session.schemas.in
--- gnome-session/gnome-session.schemas.in	26 Apr 2005 10:56:50 -0000	1.3
+++ gnome-session/gnome-session.schemas.in	21 Aug 2005 03:49:07 -0000
@@ -67,5 +67,17 @@
             <long>This is the option that will be selected in the logout dialog, valid values are "logout" for logging out, "shutdown" for halting the system and "restart" for restarting the system.</long>
          </locale>
       </schema>
+      <schema>
+         <key>/schemas/apps/gnome-session/options/user_environment</key>
+         <applyto>/apps/gnome-session/options/user_environment</applyto>
+         <owner>gnome</owner>
+         <type>list</type>
+         <list_type>string</list_type>
+         <default>[]</default>
+         <locale name="C">
+            <short>List of variables to add to gnome-session's environment</short>
+            <long>List of user supplied name/value pairs to add to gnome-session's envrionment on startup.</long>
+         </locale>
+      </schema>
    </schemalist>
 </gconfschemafile>
Index: gnome-session/main.c
===================================================================
RCS file: /cvs/gnome/gnome-session/gnome-session/main.c,v
retrieving revision 1.67
diff -b -B -u -r1.67 main.c
--- gnome-session/main.c	25 Jul 2005 07:13:53 -0000	1.67
+++ gnome-session/main.c	21 Aug 2005 03:48:04 -0000
@@ -149,6 +149,32 @@
   putenv (env_string);
 }
 
+/* Set environment variables from list of name/value pairs */
+static void
+add_environment_list(GSList *list) {
+  guint count = 1;
+  GSList *i, *last = NULL;
+  
+  for (i=list; (i != NULL) && (i->data != NULL); i = g_slist_next(i)) {
+    if ( ((count++ % 2) == 0) && (last->data != '\0') )
+      setenv(last->data, i->data, 1);
+    last = i;
+  }
+}
+
+static void
+free_environment_list(GSList *list) {
+  GSList* i;
+
+  for (i=list; i != NULL; i = g_slist_next(i)) {
+    if (i->data != NULL)
+      g_free(i->data);
+  }
+
+  if (list != NULL)
+    g_slist_free(list);
+}
+
 static void
 update_boolean (GConfClient *client,
 		guint cnxn_id,
@@ -325,6 +351,7 @@
   GError *err;
   int status;
   char *display_str;
+  GSList* env_list = NULL;
   
   if (getenv ("GSM_VERBOSE_DEBUG"))
     gsm_set_verbose (TRUE);
@@ -404,6 +431,7 @@
   autosave       = gconf_client_get_bool (gconf_client, AUTOSAVE_MODE_KEY, NULL);
   logout_prompt  = gconf_client_get_bool (gconf_client, LOGOUT_PROMPT_KEY, NULL);
   a_t_support    = gconf_client_get_bool (gconf_client, ACCESSIBILITY_KEY, NULL);
+  env_list       = gconf_client_get_list (gconf_client, USER_ENVIRONMENT_KEY, GCONF_VALUE_STRING, NULL);
 
   gconf_client_notify_add (gconf_client,
 			   AUTOSAVE_MODE_KEY,
@@ -447,6 +475,10 @@
   putenv (session_name_env);
   the_session = read_session (session_name);
 
+  /* Apply user supplied environment variables */
+  add_environment_list(env_list);
+  free_environment_list(env_list);  
+
   gsm_sound_login ();
 
   gsm_gsd_start ();


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