socket, awesome-client: fix computing if DISPLAY unset

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-08-28 19:50:04 +02:00
parent 99004c3799
commit fa57be9588
2 changed files with 7 additions and 4 deletions

View File

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

View File

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