gnome-terminal r3093 - trunk/src
- From: chpe svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-terminal r3093 - trunk/src
- Date: Thu, 25 Sep 2008 18:42:48 +0000 (UTC)
Author: chpe
Date: Thu Sep 25 18:42:48 2008
New Revision: 3093
URL: http://svn.gnome.org/viewvc/gnome-terminal?rev=3093&view=rev
Log:
Bug 98715 â loses parent environment variables on startup
Based on a patch by Davyd Madeley.
Modified:
trunk/src/terminal-app.c
trunk/src/terminal-app.h
trunk/src/terminal-factory-service.xml
trunk/src/terminal-screen.c
trunk/src/terminal-screen.h
trunk/src/terminal-window.c
trunk/src/terminal.c
Modified: trunk/src/terminal-app.c
==============================================================================
--- trunk/src/terminal-app.c (original)
+++ trunk/src/terminal-app.c Thu Sep 25 18:42:48 2008
@@ -1634,6 +1634,7 @@
char **override_command,
const char *title,
const char *working_dir,
+ char **child_env,
double zoom)
{
TerminalScreen *screen;
@@ -1659,6 +1660,9 @@
if (override_command)
terminal_screen_set_override_command (screen, override_command);
+ if (child_env)
+ terminal_screen_set_initial_environment (screen, child_env);
+
terminal_screen_set_font_scale (screen, zoom);
terminal_screen_set_font (screen);
Modified: trunk/src/terminal-app.h
==============================================================================
--- trunk/src/terminal-app.h (original)
+++ trunk/src/terminal-app.h Thu Sep 25 18:42:48 2008
@@ -76,6 +76,7 @@
char **override_command,
const char *title,
const char *working_dir,
+ char **child_env,
double zoom);
TerminalWindow *terminal_app_get_current_window (TerminalApp *app);
Modified: trunk/src/terminal-factory-service.xml
==============================================================================
--- trunk/src/terminal-factory-service.xml (original)
+++ trunk/src/terminal-factory-service.xml Thu Sep 25 18:42:48 2008
@@ -4,6 +4,7 @@
<arg type="s" name="working_directory" direction="in" />
<arg type="s" name="display_name" direction="in" />
<arg type="s" name="startup_id" direction="in" />
+ <arg type="as" name="environment" direction="in" />
<arg type="as" name="arguments" direction="in" />
</method>
</interface>
Modified: trunk/src/terminal-screen.c
==============================================================================
--- trunk/src/terminal-screen.c (original)
+++ trunk/src/terminal-screen.c Thu Sep 25 18:42:48 2008
@@ -63,6 +63,7 @@
char *cooked_title, *cooked_icon_title;
char *title_from_arg;
gboolean icon_title_set;
+ char **initial_env;
char **override_command;
char *working_dir;
int child_pid;
@@ -88,6 +89,7 @@
PROP_ICON_TITLE_SET,
PROP_OVERRIDE_COMMAND,
PROP_TITLE,
+ PROP_INITIAL_ENVIRONMENT
};
enum
@@ -404,6 +406,9 @@
case PROP_OVERRIDE_COMMAND:
g_value_set_boxed (value, terminal_screen_get_override_command (screen));
break;
+ case PROP_INITIAL_ENVIRONMENT:
+ g_value_set_boxed (value, terminal_screen_get_initial_environment (screen));
+ break;
case PROP_TITLE:
g_value_set_string (value, terminal_screen_get_title (screen));
break;
@@ -434,6 +439,9 @@
case PROP_OVERRIDE_COMMAND:
terminal_screen_set_override_command (screen, g_value_get_boxed (value));
break;
+ case PROP_INITIAL_ENVIRONMENT:
+ terminal_screen_set_initial_environment (screen, g_value_get_boxed (value));
+ break;
case PROP_ICON_TITLE:
case PROP_ICON_TITLE_SET:
case PROP_TITLE:
@@ -538,6 +546,13 @@
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+ g_object_class_install_property
+ (object_class,
+ PROP_INITIAL_ENVIRONMENT,
+ g_param_spec_boxed ("initial-environment", NULL, NULL,
+ G_TYPE_STRV,
+ G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+
g_type_class_add_private (object_class, sizeof (TerminalScreenPrivate));
/* Precompile the regexes */
@@ -1090,6 +1105,27 @@
return (const char**) screen->priv->override_command;
}
+void
+terminal_screen_set_initial_environment (TerminalScreen *screen,
+ char **argv)
+{
+ TerminalScreenPrivate *priv;
+
+ g_return_if_fail (TERMINAL_IS_SCREEN (screen));
+
+ priv = screen->priv;
+ g_assert (priv->initial_env == NULL);
+ priv->initial_env = g_strdupv (argv);
+}
+
+char**
+terminal_screen_get_initial_environment (TerminalScreen *screen)
+{
+ g_return_val_if_fail (TERMINAL_IS_SCREEN (screen), NULL);
+
+ return screen->priv->initial_env;
+}
+
static void
show_command_error_dialog (TerminalScreen *screen,
GError *error)
@@ -1178,57 +1214,53 @@
static char**
get_child_environment (TerminalScreen *screen)
{
- GtkWidget *term;
- char **env, **p, **retval;
+ TerminalScreenPrivate *priv = screen->priv;
+ GtkWidget *term = GTK_WIDGET (screen);
+ char **env;
+ char *e, *v;
char *proxymode, *proxyhost;
gboolean use_proxy;
- int i;
GConfClient *conf;
-#define EXTRA_ENV_VARS 8
+ GHashTable *env_table;
+ GHashTableIter iter;
+ GPtrArray *retval;
+ guint i;
- term = GTK_WIDGET (screen);
+ env_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ /* First take the factory's environment */
env = g_listenv ();
- retval = g_new (char *, g_strv_length (env) + 1 + EXTRA_ENV_VARS);
-
- for (i = 0, p = env; *p; p++)
+ for (i = 0; env[i]; ++i)
+ g_hash_table_insert (env_table, env[i], g_strdup (g_getenv (env[i])));
+ g_free (env); /* the strings themselves are now owned by the hash table */
+
+ /* and then merge the child environment, if any */
+ env = priv->initial_env;
+ if (env)
{
- /* Strip all these out, we'll replace some of them */
- if ((strcmp (*p, "COLUMNS") == 0) ||
- (strcmp (*p, "LINES") == 0) ||
- (strcmp (*p, "WINDOWID") == 0) ||
- (strcmp (*p, "TERM") == 0) ||
- (strcmp (*p, "GNOME_DESKTOP_ICON") == 0) ||
- (strcmp (*p, "COLORTERM") == 0) ||
- (strcmp (*p, "DISPLAY") == 0))
- {
- /* nothing: do not copy */
- }
- else
+ for (i = 0; env[i]; ++i)
{
- retval[i] = g_strdup_printf ("%s=%s", *p, g_getenv (*p));
- ++i;
+ v = strchr (env[i], '=');
+ if (v)
+ g_hash_table_replace (env_table, g_strndup (env[i], v - env[i]), g_strdup (v + 1));
+ else
+ g_hash_table_replace (env_table, g_strdup (env[i]), NULL);
}
}
- retval[i] = g_strdup ("COLORTERM="EXECUTABLE_NAME);
- ++i;
-
- retval[i] = g_strdup ("TERM=xterm"); /* FIXME configurable later? */
- ++i;
-
+ g_hash_table_remove (env_table, "COLUMNS");
+ g_hash_table_remove (env_table, "LINES");
+ g_hash_table_remove (env_table, "GNOME_DESKTOP_ICON");
+
+ g_hash_table_replace (env_table, g_strdup ("COLORTERM"), g_strdup (EXECUTABLE_NAME));
+ g_hash_table_replace (env_table, g_strdup ("TERM"), g_strdup ("xterm")); /* FIXME configurable later? */
+
#ifdef GDK_WINDOWING_X11
- /* FIXME: moving the tab between windows, or the window between displays will make this invalid... */
- retval[i] = g_strdup_printf ("WINDOWID=%ld",
- GDK_WINDOW_XWINDOW (term->window));
- ++i;
-
- /* FIXME: moving the window between displays will make this invalid... */
- retval[i] = g_strdup_printf ("DISPLAY=%s",
- gdk_display_get_name(gtk_widget_get_display(term)));
- ++i;
+ /* FIXME: moving the tab between windows, or the window between displays will make the next two invalid... */
+ g_hash_table_replace (env_table, g_strdup ("WINDOWID"), g_strdup_printf ("%ld", GDK_WINDOW_XWINDOW (term->window)));
+ g_hash_table_replace (env_table, g_strdup ("DISPLAY"), g_strdup (gdk_display_get_name (gtk_widget_get_display (term))));
#endif
-
+
conf = gconf_client_get_default ();
/* Series of conditions under which we don't set http_proxy */
@@ -1292,13 +1324,11 @@
if (port && host && host != '\0')
{
if (auth)
- retval[i] = g_strdup_printf ("http_proxy=http://%s %s:%d/",
- auth, host, port);
+ g_hash_table_replace (env_table, g_strdup ("http_proxy"),
+ g_strdup_printf ("http://%s %s:%d/", auth, host, port));
else
- retval[i] = g_strdup_printf ("http_proxy=http://%s:%d/",
- host, port);
-
- ++i;
+ g_hash_table_replace (env_table, g_strdup ("http_proxy"),
+ g_strdup_printf ("http://%s:%d/", host, port));
}
if (auth)
@@ -1343,17 +1373,18 @@
buf[cur-1] = '\0'; /* overwrites last comma */
- retval[i] = g_strdup_printf ("no_proxy=%s", buf);
- g_free (buf);
- ++i;
+ g_hash_table_replace (env_table, g_strdup ("no_proxy"), buf);
}
}
- retval[i] = NULL;
-
- g_strfreev (env);
+ retval = g_ptr_array_sized_new (g_hash_table_size (env_table));
+ g_hash_table_iter_init (&iter, env_table);
+ while (g_hash_table_iter_next (&iter, (gpointer *) &e, (gpointer *) &v))
+ g_ptr_array_add (retval, g_strdup_printf ("%s=%s", e, v ? v : ""));
+ g_ptr_array_add (retval, NULL);
- return retval;
+ g_hash_table_destroy (env_table);
+ return (char **) g_ptr_array_free (retval, FALSE);
}
void
@@ -1361,13 +1392,11 @@
{
TerminalScreenPrivate *priv = screen->priv;
TerminalProfile *profile;
- char **env;
- char *path;
- char **argv;
+ char **env, **argv;
+ char *path;
GError *err;
gboolean update_records;
-
-
+
profile = priv->profile;
err = NULL;
@@ -1377,7 +1406,7 @@
g_error_free (err);
return;
}
-
+
env = get_child_environment (screen);
update_records = terminal_profile_get_property_boolean (profile, TERMINAL_PROFILE_UPDATE_RECORDS);
Modified: trunk/src/terminal-screen.h
==============================================================================
--- trunk/src/terminal-screen.h (original)
+++ trunk/src/terminal-screen.h Thu Sep 25 18:42:48 2008
@@ -84,6 +84,10 @@
char **argv);
const char** terminal_screen_get_override_command (TerminalScreen *screen);
+void terminal_screen_set_initial_environment (TerminalScreen *screen,
+ char **argv);
+char ** terminal_screen_get_initial_environment (TerminalScreen *screen);
+
void terminal_screen_launch_child (TerminalScreen *screen);
const char* terminal_screen_get_raw_title (TerminalScreen *screen);
Modified: trunk/src/terminal-window.c
==============================================================================
--- trunk/src/terminal-window.c (original)
+++ trunk/src/terminal-window.c Thu Sep 25 18:42:48 2008
@@ -2563,6 +2563,7 @@
terminal_app_new_terminal (app, new_window, profile,
NULL, NULL,
terminal_screen_get_working_dir (priv->active_screen),
+ terminal_screen_get_initial_environment (priv->active_screen),
1.0);
gtk_window_present (GTK_WINDOW (new_window));
@@ -2589,6 +2590,7 @@
terminal_app_new_terminal (app, window, profile,
NULL, NULL,
terminal_screen_get_working_dir (priv->active_screen),
+ terminal_screen_get_initial_environment (priv->active_screen),
1.0);
}
Modified: trunk/src/terminal.c
==============================================================================
--- trunk/src/terminal.c (original)
+++ trunk/src/terminal.c Thu Sep 25 18:42:48 2008
@@ -78,6 +78,7 @@
const char *display_name,
const char *startup_id,
const char **argv,
+ const char **env,
GError **error);
#include "terminal-factory-client.h"
@@ -126,6 +127,7 @@
typedef struct
{
+ char **env;
char *startup_id;
char *display_name;
int screen_number;
@@ -781,6 +783,7 @@
option_parsing_results_new (const char *working_directory,
const char *display_name,
const char *startup_id,
+ const char **env,
int *argc,
char **argv)
{
@@ -796,6 +799,7 @@
results->execute = FALSE;
results->use_factory = TRUE;
+ results->env = g_strdupv ((char **) env);
results->startup_id = g_strdup (startup_id);
results->display_name = g_strdup (display_name);
results->initial_windows = NULL;
@@ -849,6 +853,7 @@
g_list_foreach (results->initial_windows, (GFunc) initial_window_free, NULL);
g_list_free (results->initial_windows);
+ g_strfreev (results->env);
g_free (results->default_role);
g_free (results->default_geometry);
g_free (results->default_working_dir);
@@ -1098,6 +1103,7 @@
it->exec_argv,
it->title,
it->working_dir,
+ results->env,
it->zoom_set ? it->zoom : results->zoom);
if (it->active)
@@ -1190,7 +1196,7 @@
argv_copy [i] = argv [i];
argv_copy [i] = NULL;
- parsing_results = option_parsing_results_new (NULL, NULL, NULL, &argc, argv);
+ parsing_results = option_parsing_results_new (NULL, NULL, NULL, NULL, &argc, argv);
startup_id = g_getenv ("DESKTOP_STARTUP_ID");
if (startup_id != NULL && startup_id[0] != '\0')
{
@@ -1272,8 +1278,26 @@
/* Forward to the existing factory and exit */
if (request_name_ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
{
+ char **env;
+ const char *evalue;
+ guint i, n;
+ GPtrArray *env_array;
int ret = EXIT_SUCCESS;
+ env = g_listenv ();
+ n = g_strv_length (env);
+ env_array = g_ptr_array_sized_new (n);
+ for (i = 0; i < n; ++i)
+ {
+ evalue = g_getenv (env[i]);
+ if (evalue)
+ g_ptr_array_add (env_array, g_strdup_printf ("%s=%s", env[i], evalue));
+ }
+ g_ptr_array_add (env_array, NULL);
+
+ g_strfreev (env);
+ env = (char **) g_ptr_array_free (env_array, FALSE);
+
proxy = dbus_g_proxy_new_for_name (connection,
TERMINAL_FACTORY_SERVICE_NAME,
TERMINAL_FACTORY_SERVICE_PATH,
@@ -1282,6 +1306,7 @@
g_get_current_dir (),
parsing_results->display_name,
parsing_results->startup_id,
+ (const char **) env,
(const char **) argv_copy,
&error))
{
@@ -1291,6 +1316,7 @@
}
g_free (argv_copy);
+ g_strfreev (env);
option_parsing_results_free (parsing_results);
exit (ret);
@@ -1776,6 +1802,7 @@
const char *working_directory,
const char *display_name,
const char *startup_id,
+ const char **env,
const char **arguments,
GError **error)
{
@@ -1790,6 +1817,7 @@
parsing_results = option_parsing_results_new (working_directory,
display_name,
startup_id,
+ env,
&argc, argv);
/* FIXMEchpe: I don't think we need this for the forwarded args! */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]