From 963bef908ea6c973d7a739b5752c8da6efa1b925 Mon Sep 17 00:00:00 2001 From: Nikos Ntarmos Date: Tue, 27 Nov 2007 14:37:32 +0200 Subject: [PATCH] Move string manipulation of the DISPLAY env var into get_client_addr awesome-client.c manipulates the string returned from getenv("DISPLAY"), removing anything after the first dot ('.'). awesome.c however has no such thing, leading to awesome listening on a '...0.0' socket. Anyway, this seems like something that should be in get_client_addr as opposed to hardwired in awesome-client.c or awesome.c. The attached patch moves it into awesome-client-common.c:get_client_addr() and teaches awesome-client.c of the change. --- awesome-client-common.c | 4 +++- awesome-client.c | 8 ++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/awesome-client-common.c b/awesome-client-common.c index 0086e803..7c843746 100644 --- a/awesome-client-common.c +++ b/awesome-client-common.c @@ -31,7 +31,7 @@ struct sockaddr_un * get_client_addr(const char *display) { - char *homedir; + char *homedir, *tmp; ssize_t path_len; struct sockaddr_un *addr; @@ -39,6 +39,8 @@ get_client_addr(const char *display) homedir = getenv("HOME"); /* (a_strlen(display) - 1) because we strcat on display + 1 and * + 3 for /, \0 and possibly 0 if display is NULL */ + if(display && (tmp = strrchr(display, '.'))) + *tmp = '\0'; path_len = a_strlen(homedir) + a_strlen(CONTROL_UNIX_SOCKET_PATH) + (a_strlen(display) - 1) + 3; if(path_len >= ssizeof(addr->sun_path)) { diff --git a/awesome-client.c b/awesome-client.c index 9fa1a616..5a3c019c 100644 --- a/awesome-client.c +++ b/awesome-client.c @@ -38,14 +38,11 @@ int main(void) { struct sockaddr_un *addr; - char buf[1024], *display, *tmp; + char buf[1024]; int csfd, ret_value = EXIT_SUCCESS; csfd = get_client_socket(); - display = a_strdup(getenv("DISPLAY")); - if(display && (tmp = strrchr(display, '.'))) - *tmp = '\0'; - addr = get_client_addr(display); + addr = get_client_addr(getenv("DISPLAY")); if(!addr || csfd < 0) return EXIT_FAILURE; @@ -69,7 +66,6 @@ main(void) close(csfd); p_delete(&addr); - p_delete(&display); return ret_value; }