add display name in socket path
This commit is contained in:
parent
0c826b8ab3
commit
f28f0e7407
|
@ -26,10 +26,10 @@
|
||||||
#include "awesome-client.h"
|
#include "awesome-client.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#define CONTROL_UNIX_SOCKET_PATH ".awesome_so_ctl"
|
#define CONTROL_UNIX_SOCKET_PATH ".awesome_ctl."
|
||||||
|
|
||||||
struct sockaddr_un *
|
struct sockaddr_un *
|
||||||
get_client_addr(void)
|
get_client_addr(const char *display)
|
||||||
{
|
{
|
||||||
char *homedir;
|
char *homedir;
|
||||||
ssize_t path_len;
|
ssize_t path_len;
|
||||||
|
@ -37,7 +37,7 @@ get_client_addr(void)
|
||||||
|
|
||||||
addr = p_new(struct sockaddr_un, 1);
|
addr = p_new(struct sockaddr_un, 1);
|
||||||
homedir = getenv("HOME");
|
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))
|
if(path_len >= ssizeof(addr->sun_path))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "error: path of control UNIX domain socket is too long");
|
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_strcpy(addr->sun_path, path_len, homedir);
|
||||||
a_strcat(addr->sun_path, path_len, "/");
|
a_strcat(addr->sun_path, path_len, "/");
|
||||||
a_strcat(addr->sun_path, path_len, CONTROL_UNIX_SOCKET_PATH);
|
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;
|
addr->sun_family = AF_UNIX;
|
||||||
|
|
||||||
|
|
|
@ -30,14 +30,17 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
main()
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct sockaddr_un *addr;
|
struct sockaddr_un *addr;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
int csfd;
|
int csfd;
|
||||||
|
|
||||||
csfd = get_client_socket();
|
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)
|
if(!addr || csfd < 0)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#ifndef AWESOME_AWESOME_CLIENT_H
|
#ifndef AWESOME_AWESOME_CLIENT_H
|
||||||
#define 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);
|
int get_client_socket(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -351,7 +351,7 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
/* get socket fd */
|
/* get socket fd */
|
||||||
csfd = get_client_socket();
|
csfd = get_client_socket();
|
||||||
addr = get_client_addr();
|
addr = get_client_addr(getenv("DISPLAY"));
|
||||||
|
|
||||||
if(bind(csfd, (const struct sockaddr *) addr, SUN_LEN(addr)))
|
if(bind(csfd, (const struct sockaddr *) addr, SUN_LEN(addr)))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue