From fa57be95886dbffd3e8915f2b03e9d9e4354efdb Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 28 Aug 2008 19:50:04 +0200 Subject: [PATCH] socket, awesome-client: fix computing if DISPLAY unset Signed-off-by: Julien Danjou --- awesome-client.c | 3 ++- common/socket.c | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/awesome-client.c b/awesome-client.c index ee6e163b..3af9c87b 100644 --- a/awesome-client.c +++ b/awesome-client.c @@ -116,7 +116,8 @@ main(int argc, char **argv) if(isatty(STDIN_FILENO)) { - asprintf(&prompt, "awesome@%s%% ", getenv("DISPLAY")); + char *display = getenv("DISPLAY"); + asprintf(&prompt, "awesome@%s%% ", display ? display : "unknown"); while((msg = readline(prompt))) if((msg_len = a_strlen(msg))) { diff --git a/common/socket.c b/common/socket.c index 9ca424a9..c44bbc10 100644 --- a/common/socket.c +++ b/common/socket.c @@ -41,8 +41,8 @@ struct sockaddr_un * socket_getaddr(const char *display) { char *homedir, *host = NULL; - int screenp, displayp; - ssize_t path_len; + int screenp = 0, displayp = 0; + ssize_t path_len, len; struct sockaddr_un *addr; addr = p_new(struct sockaddr_un, 1); @@ -50,10 +50,12 @@ socket_getaddr(const char *display) xcb_parse_display(NULL, &host, &displayp, &screenp); + len = a_strlen(host); + /* + 2 for / and . and \0 */ path_len = snprintf(addr->sun_path, sizeof(addr->sun_path), "%s/" CONTROL_UNIX_SOCKET_PATH "%s%s%d", - homedir, host, a_strlen(host) ? "." : "", + homedir, len ? host : "", len ? "." : "", displayp); p_delete(&host);