diff options
author | S. Christoffer Eliesen <christoffer@eliesen.no> | 2015-11-13 17:53:46 +0100 |
---|---|---|
committer | S. Christoffer Eliesen <christoffer@eliesen.no> | 2015-11-13 18:18:52 +0100 |
commit | f64b7e71d4ad23c6aca2038cacd196ce94493748 (patch) | |
tree | 9fafb4aeeac5b792372a4b964c5bdac8de561f6a /sway | |
parent | New screenshot for README (diff) | |
download | sway-f64b7e71d4ad23c6aca2038cacd196ce94493748.tar.gz sway-f64b7e71d4ad23c6aca2038cacd196ce94493748.tar.zst sway-f64b7e71d4ad23c6aca2038cacd196ce94493748.zip |
ipc: Store socketname in SWAYSOCK. Fixes `--get-socketpath`.
After adding pid to the socket path the `--get-socketpath` command broke
because it doesn't know the pid of the running instance. Fix this by
setting and querying `SWAYSOCK`.
Also ignore `SWAYSOCK` upon normal startup if a socket exists at that
location (ie. from another sway instance), and don't overwrite `I3SOCK`
if it exists either.
Diffstat (limited to 'sway')
-rw-r--r-- | sway/ipc.c | 10 | ||||
-rw-r--r-- | sway/main.c | 11 |
2 files changed, 15 insertions, 6 deletions
@@ -52,7 +52,8 @@ void ipc_init(void) { | |||
52 | 52 | ||
53 | ipc_sockaddr = ipc_user_sockaddr(); | 53 | ipc_sockaddr = ipc_user_sockaddr(); |
54 | 54 | ||
55 | if (getenv("SWAYSOCK") != NULL) { | 55 | // We want to use socket name set by user, not existing socket from another sway instance. |
56 | if (getenv("SWAYSOCK") != NULL && access(getenv("SWAYSOCK"), F_OK) == -1) { | ||
56 | strncpy(ipc_sockaddr->sun_path, getenv("SWAYSOCK"), sizeof(ipc_sockaddr->sun_path)); | 57 | strncpy(ipc_sockaddr->sun_path, getenv("SWAYSOCK"), sizeof(ipc_sockaddr->sun_path)); |
57 | } | 58 | } |
58 | 59 | ||
@@ -66,7 +67,12 @@ void ipc_init(void) { | |||
66 | } | 67 | } |
67 | 68 | ||
68 | // Set i3 IPC socket path so that i3-msg works out of the box | 69 | // Set i3 IPC socket path so that i3-msg works out of the box |
69 | setenv("I3SOCK", ipc_sockaddr->sun_path, 1); | 70 | if (!getenv("I3SOCK")) { |
71 | setenv("I3SOCK", ipc_sockaddr->sun_path, 1); | ||
72 | } | ||
73 | if (!getenv("SWAYSOCK")) { | ||
74 | setenv("SWAYSOCK", ipc_sockaddr->sun_path, 1); | ||
75 | } | ||
70 | 76 | ||
71 | ipc_client_list = create_list(); | 77 | ipc_client_list = create_list(); |
72 | 78 | ||
diff --git a/sway/main.c b/sway/main.c index a4fe5823..4afbccbd 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -107,10 +107,13 @@ int main(int argc, char **argv) { | |||
107 | verbose = 1; | 107 | verbose = 1; |
108 | break; | 108 | break; |
109 | case 'p': ; // --get-socketpath | 109 | case 'p': ; // --get-socketpath |
110 | struct sockaddr_un *ipc_sockaddr = ipc_user_sockaddr(); | 110 | if (getenv("SWAYSOCK")) { |
111 | fprintf(stdout, "%s\n", ipc_sockaddr->sun_path); | 111 | fprintf(stdout, "%s\n", getenv("SWAYSOCK")); |
112 | free(ipc_sockaddr); | 112 | exit(0); |
113 | exit(0); | 113 | } else { |
114 | fprintf(stderr, "sway socket not detected.\n"); | ||
115 | exit(1); | ||
116 | } | ||
114 | break; | 117 | break; |
115 | } | 118 | } |
116 | } | 119 | } |