summaryrefslogtreecommitdiff
path: root/hw/xwin
diff options
context:
space:
mode:
authorJon Turney <jon.turney@dronecode.org.uk>2015-04-28 16:04:40 +0100
committerJon Turney <jon.turney@dronecode.org.uk>2016-06-23 14:15:27 +0100
commit17c8bf348eea4f12ce7cb4ca7db0d0576e28c982 (patch)
tree93bf8655225a83d617c75a82bb549caa0b054833 /hw/xwin
parentc05c4360eea245b3ef5f3a355b95dcd63244ef70 (diff)
hw/xwin: Check for just the hostname in window title
When -hostintitle is enabled, only use the hostname, not a FQDN from WM_CLIENT_MACHINE, when checking if the window title already contains it Also restructure GetWindowName() to fix a potential memory leak. Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk> Reviewed-by: Colin Harrison <colin.harrison@virgin.net>
Diffstat (limited to 'hw/xwin')
-rw-r--r--hw/xwin/winmultiwindowwm.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/hw/xwin/winmultiwindowwm.c b/hw/xwin/winmultiwindowwm.c
index 36d8ed7e7..32d23973d 100644
--- a/hw/xwin/winmultiwindowwm.c
+++ b/hw/xwin/winmultiwindowwm.c
@@ -416,27 +416,39 @@ GetWindowName(WMInfoPtr pWMInfo, xcb_window_t iWin, char **ppWindowName)
xcb_icccm_get_text_property_reply_wipe(&reply);
}
+ /* return the window name, unless... */
+ *ppWindowName = pszWindowName;
+
if (g_fHostInTitle) {
- char *pszClientMachine;
- char hostname[HOST_NAME_MAX + 1];
xcb_get_property_cookie_t cookie;
xcb_icccm_get_text_property_reply_t reply;
/* Try to get client machine name */
cookie = xcb_icccm_get_wm_client_machine(conn, iWin);
if (xcb_icccm_get_wm_client_machine_reply(conn, cookie, &reply, NULL)) {
+ char *pszClientMachine;
+ char *pszClientHostname;
+ char *dot;
+ char hostname[HOST_NAME_MAX + 1];
+
pszClientMachine = Xutf8TextPropertyToString(pWMInfo, &reply);
xcb_icccm_get_text_property_reply_wipe(&reply);
+ /* If client machine name looks like a FQDN, find the hostname */
+ pszClientHostname = strdup(pszClientMachine);
+ dot = strchr(pszClientHostname, '.');
+ if (dot)
+ *dot = '\0';
+
/*
- If we have a client machine name
- and it's not the local host name
+ If we have a client machine hostname
+ and it's not the local hostname
and it's not already in the window title...
*/
- if (strlen(pszClientMachine) &&
+ if (strlen(pszClientHostname) &&
!gethostname(hostname, HOST_NAME_MAX + 1) &&
- strcmp(hostname, pszClientMachine) &&
- (strstr(pszWindowName, pszClientMachine) == 0)) {
+ strcmp(hostname, pszClientHostname) &&
+ (strstr(pszWindowName, pszClientHostname) == 0)) {
/* ... add '@<clientmachine>' to end of window name */
*ppWindowName =
malloc(strlen(pszWindowName) +
@@ -446,15 +458,12 @@ GetWindowName(WMInfoPtr pWMInfo, xcb_window_t iWin, char **ppWindowName)
strcat(*ppWindowName, pszClientMachine);
free(pszWindowName);
- free(pszClientMachine);
-
- return;
}
+
+ free(pszClientMachine);
+ free(pszClientHostname);
}
}
-
- /* otherwise just return the window name */
- *ppWindowName = pszWindowName;
}
/*