2222 */
2323
2424#include <glib.h>
25+ #include <stdbool.h>
26+ #include <stdio.h>
27+
2528#include <string.h>
2629#include "gnc-environment.h"
2730#include "gnc-path.h"
@@ -96,6 +99,17 @@ static gchar *environment_expand(gchar *param)
9699 return expanded ;
97100}
98101
102+ static bool
103+ char_array_contains (const char * * array , unsigned num_keys , const char * key )
104+ {
105+ for (unsigned i = 0 ; i < num_keys ; ++ i )
106+ {
107+ if (strcmp (key , array [i ]) == 0 )
108+ return true;
109+ }
110+ return false;
111+ }
112+
99113static void
100114gnc_environment_parse_one (const gchar * env_path )
101115{
@@ -104,6 +118,9 @@ gnc_environment_parse_one (const gchar *env_path)
104118 gsize param_count ;
105119 gint i ;
106120 gboolean got_keyfile ;
121+ const unsigned num_keys = 6 ;
122+ const char * reserved_keys [] = {"GNC_HOME" , "GNC_BIN" , "GNC_LIB" ,
123+ "GNC_DATA" , "GNC_CONF" , "SYS_LIB" };
107124
108125 got_keyfile = g_key_file_load_from_file (keyfile , env_path , G_KEY_FILE_NONE , NULL );
109126 if ( !got_keyfile )
@@ -120,8 +137,10 @@ gnc_environment_parse_one (const gchar *env_path)
120137 gsize val_count ;
121138 gint j ;
122139 gchar * new_val = NULL , * tmp_val ;
140+ if (char_array_contains (reserved_keys , num_keys , env_vars [i ]))
141+ continue ;
123142
124- /* For each variable, read its new value, optionally expand it and set/unset it */
143+ /* for each variable, read its new value, optionally expand it and set/unset it */
125144 val_list = g_key_file_get_string_list (keyfile , "Variables" ,
126145 env_vars [i ], & val_count ,
127146 NULL );
@@ -170,27 +189,27 @@ gnc_environment_setup (void)
170189
171190 /* Export default parameters to the environment */
172191 env_parm = gnc_path_get_prefix ();
173- if (!g_setenv ("GNC_HOME" , env_parm , FALSE ))
192+ if (!g_setenv ("GNC_HOME" , env_parm , TRUE ))
174193 g_warning ("Couldn't set/override environment variable GNC_HOME." );
175194 g_free (env_parm );
176195 env_parm = gnc_path_get_bindir ();
177- if (!g_setenv ("GNC_BIN" , env_parm , FALSE ))
196+ if (!g_setenv ("GNC_BIN" , env_parm , TRUE ))
178197 g_warning ("Couldn't set/override environment variable GNC_BIN." );
179198 g_free (env_parm );
180199 env_parm = gnc_path_get_pkglibdir ();
181- if (!g_setenv ("GNC_LIB" , env_parm , FALSE ))
200+ if (!g_setenv ("GNC_LIB" , env_parm , TRUE ))
182201 g_warning ("Couldn't set/override environment variable GNC_LIB." );
183202 g_free (env_parm );
184203 env_parm = gnc_path_get_pkgdatadir ();
185- if (!g_setenv ("GNC_DATA" , env_parm , FALSE ))
204+ if (!g_setenv ("GNC_DATA" , env_parm , TRUE ))
186205 g_warning ("Couldn't set/override environment variable GNC_DATA." );
187206 g_free (env_parm );
188207 env_parm = gnc_path_get_pkgsysconfdir ();
189- if (!g_setenv ("GNC_CONF" , env_parm , FALSE ))
208+ if (!g_setenv ("GNC_CONF" , env_parm , TRUE ))
190209 g_warning ("Couldn't set/override environment variable GNC_CONF." );
191210 g_free (env_parm );
192211 env_parm = gnc_path_get_libdir ();
193- if (!g_setenv ("SYS_LIB" , env_parm , FALSE ))
212+ if (!g_setenv ("SYS_LIB" , env_parm , TRUE ))
194213 g_warning ("Couldn't set/override environment variable SYS_LIB." );
195214 g_free (env_parm );
196215
0 commit comments