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.
This commit is contained in:
Nikos Ntarmos 2007-11-27 14:37:32 +02:00 committed by Julien Danjou
parent ece6bb27f3
commit 963bef908e
2 changed files with 5 additions and 7 deletions

View File

@ -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))
{

View File

@ -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;
}