From 17c8bf348eea4f12ce7cb4ca7db0d0576e28c982 Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Tue, 28 Apr 2015 16:04:40 +0100 Subject: 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 Reviewed-by: Colin Harrison --- hw/xwin/winmultiwindowwm.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'hw/xwin') 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 '@' 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; } /* -- cgit v1.2.3