diff options
Diffstat (limited to 'channels.c')
-rw-r--r-- | channels.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/channels.c b/channels.c index 5b7d6d649..8fcba783e 100644 --- a/channels.c +++ b/channels.c | |||
@@ -3078,7 +3078,7 @@ x11_create_display_inet(int x11_display_offset, int x11_use_localhost, | |||
3078 | } | 3078 | } |
3079 | 3079 | ||
3080 | static int | 3080 | static int |
3081 | connect_local_xsocket(u_int dnr) | 3081 | connect_local_xsocket_path(const char *pathname) |
3082 | { | 3082 | { |
3083 | int sock; | 3083 | int sock; |
3084 | struct sockaddr_un addr; | 3084 | struct sockaddr_un addr; |
@@ -3088,7 +3088,7 @@ connect_local_xsocket(u_int dnr) | |||
3088 | error("socket: %.100s", strerror(errno)); | 3088 | error("socket: %.100s", strerror(errno)); |
3089 | memset(&addr, 0, sizeof(addr)); | 3089 | memset(&addr, 0, sizeof(addr)); |
3090 | addr.sun_family = AF_UNIX; | 3090 | addr.sun_family = AF_UNIX; |
3091 | snprintf(addr.sun_path, sizeof addr.sun_path, _PATH_UNIX_X, dnr); | 3091 | strlcpy(addr.sun_path, pathname, sizeof addr.sun_path); |
3092 | if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == 0) | 3092 | if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == 0) |
3093 | return sock; | 3093 | return sock; |
3094 | close(sock); | 3094 | close(sock); |
@@ -3096,6 +3096,14 @@ connect_local_xsocket(u_int dnr) | |||
3096 | return -1; | 3096 | return -1; |
3097 | } | 3097 | } |
3098 | 3098 | ||
3099 | static int | ||
3100 | connect_local_xsocket(u_int dnr) | ||
3101 | { | ||
3102 | char buf[1024]; | ||
3103 | snprintf(buf, sizeof buf, _PATH_UNIX_X, dnr); | ||
3104 | return connect_local_xsocket_path(buf); | ||
3105 | } | ||
3106 | |||
3099 | int | 3107 | int |
3100 | x11_connect_display(void) | 3108 | x11_connect_display(void) |
3101 | { | 3109 | { |
@@ -3117,6 +3125,17 @@ x11_connect_display(void) | |||
3117 | * connection to the real X server. | 3125 | * connection to the real X server. |
3118 | */ | 3126 | */ |
3119 | 3127 | ||
3128 | /* Check if the display is from launchd. */ | ||
3129 | #ifdef __APPLE__ | ||
3130 | if (strncmp(display, "/tmp/launch", 11) == 0) { | ||
3131 | sock = connect_local_xsocket_path(display); | ||
3132 | if (sock < 0) | ||
3133 | return -1; | ||
3134 | |||
3135 | /* OK, we now have a connection to the display. */ | ||
3136 | return sock; | ||
3137 | } | ||
3138 | #endif | ||
3120 | /* | 3139 | /* |
3121 | * Check if it is a unix domain socket. Unix domain displays are in | 3140 | * Check if it is a unix domain socket. Unix domain displays are in |
3122 | * one of the following formats: unix:d[.s], :d[.s], ::d[.s] | 3141 | * one of the following formats: unix:d[.s], :d[.s], ::d[.s] |