summaryrefslogtreecommitdiff
path: root/channels.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2017-03-10 13:22:32 +1100
committerDarren Tucker <dtucker@zip.com.au>2017-03-10 13:22:32 +1100
commitda39b09d43b137a5a3d071b51589e3efb3701238 (patch)
tree8e78d302fe7ba24d43e01113dcc8cd107ac8ecec /channels.c
parent8fb15311a011517eb2394bb95a467c209b8b336c (diff)
If OSX is using launchd, remove screen no.
Check for socket with and without screen number. From Apple and Jakob Schlyter via bz#2341, with contributions from Ron Frederick, ok djm@
Diffstat (limited to 'channels.c')
-rw-r--r--channels.c48
1 files changed, 41 insertions, 7 deletions
diff --git a/channels.c b/channels.c
index 398da9a89..d030fcdd9 100644
--- a/channels.c
+++ b/channels.c
@@ -4373,6 +4373,33 @@ connect_local_xsocket(u_int dnr)
4373 return connect_local_xsocket_path(buf); 4373 return connect_local_xsocket_path(buf);
4374} 4374}
4375 4375
4376#ifdef __APPLE__
4377static int
4378is_path_to_xsocket(const char *display, char *path, size_t pathlen)
4379{
4380 struct stat sbuf;
4381
4382 if (strlcpy(path, display, pathlen) >= pathlen) {
4383 error("%s: display path too long", __func__);
4384 return 0;
4385 }
4386 if (display[0] != '/')
4387 return 0;
4388 if (stat(path, &sbuf) == 0) {
4389 return 1;
4390 } else {
4391 char *dot = strrchr(path, '.');
4392 if (dot != NULL) {
4393 *dot = '\0';
4394 if (stat(path, &sbuf) == 0) {
4395 return 1;
4396 }
4397 }
4398 }
4399 return 0;
4400}
4401#endif
4402
4376int 4403int
4377x11_connect_display(void) 4404x11_connect_display(void)
4378{ 4405{
@@ -4394,15 +4421,22 @@ x11_connect_display(void)
4394 * connection to the real X server. 4421 * connection to the real X server.
4395 */ 4422 */
4396 4423
4397 /* Check if the display is from launchd. */
4398#ifdef __APPLE__ 4424#ifdef __APPLE__
4399 if (strncmp(display, "/tmp/launch", 11) == 0) { 4425 /* Check if display is a path to a socket (as set by launchd). */
4400 sock = connect_local_xsocket_path(display); 4426 {
4401 if (sock < 0) 4427 char path[PATH_MAX];
4402 return -1;
4403 4428
4404 /* OK, we now have a connection to the display. */ 4429 if (is_path_to_xsocket(display, path, sizeof(path))) {
4405 return sock; 4430 debug("x11_connect_display: $DISPLAY is launchd");
4431
4432 /* Create a socket. */
4433 sock = connect_local_xsocket_path(path);
4434 if (sock < 0)
4435 return -1;
4436
4437 /* OK, we now have a connection to the display. */
4438 return sock;
4439 }
4406 } 4440 }
4407#endif 4441#endif
4408 /* 4442 /*