From f28f0e74075254b4682434dfea2cf68f39e223ec Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 29 Oct 2007 17:29:58 +0100 Subject: [PATCH] add display name in socket path --- awesome-client-common.c | 10 +++++++--- awesome-client.c | 9 ++++++--- awesome-client.h | 2 +- awesome.c | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/awesome-client-common.c b/awesome-client-common.c index 3daa4d22c..900c95543 100644 --- a/awesome-client-common.c +++ b/awesome-client-common.c @@ -26,10 +26,10 @@ #include "awesome-client.h" #include "util.h" -#define CONTROL_UNIX_SOCKET_PATH ".awesome_so_ctl" +#define CONTROL_UNIX_SOCKET_PATH ".awesome_ctl." struct sockaddr_un * -get_client_addr(void) +get_client_addr(const char *display) { char *homedir; ssize_t path_len; @@ -37,7 +37,7 @@ get_client_addr(void) addr = p_new(struct sockaddr_un, 1); homedir = getenv("HOME"); - path_len = a_strlen(homedir) + a_strlen(CONTROL_UNIX_SOCKET_PATH) + 2; + path_len = a_strlen(homedir) + a_strlen(CONTROL_UNIX_SOCKET_PATH) + a_strlen(display) + 2; if(path_len >= ssizeof(addr->sun_path)) { fprintf(stderr, "error: path of control UNIX domain socket is too long"); @@ -46,6 +46,10 @@ get_client_addr(void) a_strcpy(addr->sun_path, path_len, homedir); a_strcat(addr->sun_path, path_len, "/"); a_strcat(addr->sun_path, path_len, CONTROL_UNIX_SOCKET_PATH); + if(display) + a_strcat(addr->sun_path, path_len, display + 1); + else + a_strcat(addr->sun_path, path_len, "0"); addr->sun_family = AF_UNIX; diff --git a/awesome-client.c b/awesome-client.c index f7498da33..ee945b5f1 100644 --- a/awesome-client.c +++ b/awesome-client.c @@ -30,14 +30,17 @@ #include "util.h" int -main() +main(int argc, char **argv) { struct sockaddr_un *addr; char buf[1024]; int csfd; - + csfd = get_client_socket(); - addr = get_client_addr(); + if(argc > 1) + addr = get_client_addr(argv[1]); + else + addr = get_client_addr(":0"); if(!addr || csfd < 0) return EXIT_FAILURE; diff --git a/awesome-client.h b/awesome-client.h index 1ea128cba..66673d6e8 100644 --- a/awesome-client.h +++ b/awesome-client.h @@ -22,7 +22,7 @@ #ifndef AWESOME_AWESOME_CLIENT_H #define AWESOME_AWESOME_CLIENT_H -struct sockaddr_un * get_client_addr(void); +struct sockaddr_un * get_client_addr(const char *); int get_client_socket(void); #endif diff --git a/awesome.c b/awesome.c index ca4779b5f..e5c4069a6 100644 --- a/awesome.c +++ b/awesome.c @@ -351,7 +351,7 @@ main(int argc, char *argv[]) /* get socket fd */ csfd = get_client_socket(); - addr = get_client_addr(); + addr = get_client_addr(getenv("DISPLAY")); if(bind(csfd, (const struct sockaddr *) addr, SUN_LEN(addr))) {