Commit 2cafb8be authored by Ray Strode's avatar Ray Strode

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
parent 64544fa0
......@@ -93,7 +93,6 @@ struct _MetaDisplay
char *name;
Display *xdisplay;
char *hostname;
Window leader_window;
Window timestamp_pinging_window;
......
......@@ -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);
......
......@@ -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;
......
......@@ -37,6 +37,7 @@
*/
#define _GNU_SOURCE
#define _SVID_SOURCE /* for gethostname() */
#include <config.h>
#include "window-props.h"
......@@ -48,6 +49,11 @@
#include <unistd.h>
#include <string.h>
#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
......
......@@ -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;
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment