diff --git a/awesome-client.c b/awesome-client.c index c7c84fa5..b2282a0b 100644 --- a/awesome-client.c +++ b/awesome-client.c @@ -56,11 +56,16 @@ sockets_init(void) if((csfd = socket_getclient()) < 0) return false; - if(!(addr = socket_getaddr(display))) + if(!(addr = socket_getaddr(getenv("HOME"), display))) return false; if(connect(csfd, addr, sizeof(struct sockaddr_un)) == -1) - return false; + { + if(!(addr = socket_getaddr("/tmp", display))) + return false; + if(connect(csfd, addr, sizeof(struct sockaddr_un)) == -1) + return false; + } return true; } diff --git a/common/socket.c b/common/socket.c index ba89831c..3fb9b68e 100644 --- a/common/socket.c +++ b/common/socket.c @@ -34,20 +34,20 @@ /** Get a sockaddr_un struct with information feeded for opening a * communication to the awesome socket for given display + * \param directory Where socket is created. * \param display the display number * \return sockaddr_un struct ready to be used or NULL if a problem occured */ struct sockaddr_un * -socket_getaddr(const char *display) +socket_getaddr(const char *directory, const char *display) { - char *homedir, *host = NULL; + char *host = NULL; int screenp = 0, displayp = 0; ssize_t path_len, len; struct sockaddr_un *addr; addr = p_new(struct sockaddr_un, 1); - homedir = getenv("HOME"); - + xcb_parse_display(NULL, &host, &displayp, &screenp); len = a_strlen(host); @@ -55,7 +55,7 @@ socket_getaddr(const char *display) /* + 2 for / and . and \0 */ path_len = snprintf(addr->sun_path, sizeof(addr->sun_path), "%s/" CONTROL_UNIX_SOCKET_PATH "%s%s%d", - homedir, len ? host : "", len ? "." : "", + directory, len ? host : "", len ? "." : "", displayp); p_delete(&host); diff --git a/common/socket.h b/common/socket.h index df131c1e..55e11271 100644 --- a/common/socket.h +++ b/common/socket.h @@ -22,7 +22,7 @@ #ifndef AWESOME_COMMON_SOCKET_H #define AWESOME_COMMON_SOCKET_H -struct sockaddr_un * socket_getaddr(const char *); +struct sockaddr_un * socket_getaddr(const char *, const char *); int socket_getclient(void); #endif diff --git a/luaa.c b/luaa.c index 9ce3a8a0..87df9f23 100644 --- a/luaa.c +++ b/luaa.c @@ -1115,7 +1115,7 @@ luaA_cs_init(void) if (csfd < 0 || fcntl(csfd, F_SETFD, FD_CLOEXEC) == -1) return; - addr = socket_getaddr(getenv("DISPLAY")); + addr = socket_getaddr(getenv("HOME"), getenv("DISPLAY")); /* Needed for some OSes like Solaris */ #ifndef SUN_LEN @@ -1132,7 +1132,11 @@ luaA_cs_init(void) return warn("error binding UNIX domain socket: %s", strerror(errno)); } else - return warn("error binding UNIX domain socket: %s", strerror(errno)); + { + addr = socket_getaddr("/tmp", getenv("DISPLAY")); + if (bind(csfd, (const struct sockaddr *) addr, SUN_LEN(addr))) + return warn("error binding UNIX domain socket: %s", strerror(errno)); + } } listen(csfd, 10);