From 2cafb8be2d4346474b5bf90c318f58ccca49d83b Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Wed, 20 Feb 2013 15:17:21 -0500 Subject: [PATCH] window: fix meta_window_is_remote across hostname changes meta_window_is_remote compares a cached copy of the system hostname with the hostname of the client window (as presented by the WM_CLIENT_MACHINE property). Of course, the system hostname can change at any time, so caching it is wrong. Also, the WM_CLIENT_MACHINE property won't necessarily change when the system hostname changes, so comparing it with the new system hostname is wrong, too. This commit makes the code call gethostname() at the time WM_CLIENT_MACHINE is set, check whether it's remote then, and cache that value, rather than comparing potentially out of sync hostnames later. https://bugzilla.gnome.org/show_bug.cgi?id=688716 --- src/core/display-private.h | 1 - src/core/display.c | 9 --------- src/core/window-private.h | 3 +++ src/core/window-props.c | 19 +++++++++++++++++++ src/core/window.c | 7 ++----- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/core/display-private.h b/src/core/display-private.h index 99984e14a..c4abbfa86 100644 --- a/src/core/display-private.h +++ b/src/core/display-private.h @@ -93,7 +93,6 @@ struct _MetaDisplay char *name; Display *xdisplay; - char *hostname; Window leader_window; Window timestamp_pinging_window; diff --git a/src/core/display.c b/src/core/display.c index 2e522a9e9..b1e654338 100644 --- a/src/core/display.c +++ b/src/core/display.c @@ -466,7 +466,6 @@ meta_display_open (void) GSList *tmp; int i; guint32 timestamp; - char buf[257]; /* A list of all atom names, so that we can intern them in one go. */ char *atom_names[] = { @@ -501,13 +500,6 @@ meta_display_open (void) */ the_display->name = g_strdup (XDisplayName (NULL)); the_display->xdisplay = xdisplay; - if (gethostname (buf, sizeof(buf)-1) == 0) - { - buf[sizeof(buf)-1] = '\0'; - the_display->hostname = g_strdup (buf); - } - else - the_display->hostname = NULL; the_display->error_trap_synced_at_last_pop = TRUE; the_display->error_traps = 0; the_display->error_trap_handler = NULL; @@ -1116,7 +1108,6 @@ meta_display_close (MetaDisplay *display, meta_display_free_window_prop_hooks (display); meta_display_free_group_prop_hooks (display); - g_free (display->hostname); g_free (display->name); meta_display_shutdown_keys (display); diff --git a/src/core/window-private.h b/src/core/window-private.h index 04ee11046..311af1963 100644 --- a/src/core/window-private.h +++ b/src/core/window-private.h @@ -346,6 +346,9 @@ struct _MetaWindow /* if TRUE, we are freezing updates during a resize */ guint updates_frozen_for_resize : 1; + /* whether or not the window is from a program running on another machine */ + guint is_remote : 1; + /* if non-NULL, the bounds of the window frame */ cairo_region_t *frame_bounds; diff --git a/src/core/window-props.c b/src/core/window-props.c index 7f44d174b..b4225631f 100644 --- a/src/core/window-props.c +++ b/src/core/window-props.c @@ -37,6 +37,7 @@ */ #define _GNU_SOURCE +#define _SVID_SOURCE /* for gethostname() */ #include #include "window-props.h" @@ -48,6 +49,11 @@ #include #include +#ifndef HOST_NAME_MAX +/* Solaris headers apparently don't define this so do so manually; #326745 */ +#define HOST_NAME_MAX 255 +#endif + typedef void (* ReloadValueFunc) (MetaWindow *window, MetaPropValue *value, gboolean initial); @@ -195,6 +201,19 @@ reload_wm_client_machine (MetaWindow *window, meta_verbose ("Window has client machine \"%s\"\n", window->wm_client_machine ? window->wm_client_machine : "unset"); + + if (window->wm_client_machine == NULL) + { + window->is_remote = FALSE; + } + else + { + char hostname[HOST_NAME_MAX + 1] = ""; + + gethostname (hostname, HOST_NAME_MAX + 1); + + window->is_remote = g_strcmp0 (window->wm_client_machine, hostname) != 0; + } } static void diff --git a/src/core/window.c b/src/core/window.c index 19d1988f7..210cf22a5 100644 --- a/src/core/window.c +++ b/src/core/window.c @@ -1161,6 +1161,7 @@ meta_window_new_with_attrs (MetaDisplay *display, window->role = NULL; window->sm_client_id = NULL; window->wm_client_machine = NULL; + window->is_remote = FALSE; window->startup_id = NULL; window->net_wm_pid = -1; @@ -10895,11 +10896,7 @@ meta_window_get_client_machine (MetaWindow *window) gboolean meta_window_is_remote (MetaWindow *window) { - g_return_val_if_fail (META_IS_WINDOW (window), FALSE); - - if (window->wm_client_machine != NULL) - return g_strcmp0 (window->wm_client_machine, window->display->hostname) != 0; - return FALSE; + return window->is_remote; } /**