rename uicb_toggletag to uicb_client_toggletag
[awesome.git] / awesome-client-common.c
blob900c955430654410c7f66634ec042024321ee43b
1 /*
2 * awesome-client-common.c - awesome client, communicate with socket, common functions
4 * Copyright © 2007 Julien Danjou <julien@danjou.info>
5 * Copyright © 2007 daniel@brinkers.de
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <sys/socket.h>
24 #include <sys/un.h>
26 #include "awesome-client.h"
27 #include "util.h"
29 #define CONTROL_UNIX_SOCKET_PATH ".awesome_ctl."
31 struct sockaddr_un *
32 get_client_addr(const char *display)
34 char *homedir;
35 ssize_t path_len;
36 struct sockaddr_un *addr;
38 addr = p_new(struct sockaddr_un, 1);
39 homedir = getenv("HOME");
40 path_len = a_strlen(homedir) + a_strlen(CONTROL_UNIX_SOCKET_PATH) + a_strlen(display) + 2;
41 if(path_len >= ssizeof(addr->sun_path))
43 fprintf(stderr, "error: path of control UNIX domain socket is too long");
44 return NULL;
46 a_strcpy(addr->sun_path, path_len, homedir);
47 a_strcat(addr->sun_path, path_len, "/");
48 a_strcat(addr->sun_path, path_len, CONTROL_UNIX_SOCKET_PATH);
49 if(display)
50 a_strcat(addr->sun_path, path_len, display + 1);
51 else
52 a_strcat(addr->sun_path, path_len, "0");
54 addr->sun_family = AF_UNIX;
56 return addr;
59 int
60 get_client_socket(void)
62 int csfd;
64 csfd = socket(AF_UNIX, SOCK_DGRAM, 0);
66 if(csfd < 0)
67 perror("error opening UNIX domain socket");
69 return csfd;