View | Details | Raw Unified | Return to bug 2341 | Differences between
and this patch

Collapse All | Expand All

(-)a/channels.c (-7 / +39 lines)
Lines 4354-4359 connect_local_xsocket(u_int dnr) Link Here
4354
	return connect_local_xsocket_path(buf);
4354
	return connect_local_xsocket_path(buf);
4355
}
4355
}
4356
4356
4357
static int
4358
is_path_to_xsocket(const char *display, char *path, size_t pathlen)
4359
{
4360
	struct stat sbuf;
4361
4362
	if (strlcpy(path, display, pathlen) >= pathlen) {
4363
		error("%s: display path too long", __func__);
4364
		return 0;
4365
	}
4366
	if (stat(path, &sbuf) == 0) {
4367
		return 1;
4368
	} else {
4369
		char *dot = strrchr(path, '.');
4370
		if (dot != NULL) {
4371
			*dot = '\0';
4372
			if (stat(path, &sbuf) == 0) {
4373
				return 1;
4374
			}
4375
		}
4376
	}
4377
4378
	return 0;
4379
}
4380
4357
int
4381
int
4358
x11_connect_display(void)
4382
x11_connect_display(void)
4359
{
4383
{
Lines 4375-4391 x11_connect_display(void) Link Here
4375
	 * connection to the real X server.
4399
	 * connection to the real X server.
4376
	 */
4400
	 */
4377
4401
4378
	/* Check if the display is from launchd. */
4379
#ifdef __APPLE__
4402
#ifdef __APPLE__
4380
	if (strncmp(display, "/tmp/launch", 11) == 0) {
4403
	/* Check if display is a path to a socket (as set by launchd). */
4381
		sock = connect_local_xsocket_path(display);
4404
	{
4382
		if (sock < 0)
4405
		char path[PATH_MAX];
4383
			return -1;
4384
4406
4385
		/* OK, we now have a connection to the display. */
4407
		if (is_path_to_xsocket(display, path, sizeof(path))) {
4386
		return sock;
4408
			debug("x11_connect_display: $DISPLAY is launchd");
4409
4410
			/* Create a socket. */
4411
			sock = connect_local_xsocket_path(path);
4412
			if (sock < 0)
4413
				return -1;
4414
4415
			/* OK, we now have a connection to the display. */
4416
			return sock;
4417
		}
4387
	}
4418
	}
4388
#endif
4419
#endif
4420
4389
	/*
4421
	/*
4390
	 * Check if it is a unix domain socket.  Unix domain displays are in
4422
	 * Check if it is a unix domain socket.  Unix domain displays are in
4391
	 * one of the following formats: unix:d[.s], :d[.s], ::d[.s]
4423
	 * one of the following formats: unix:d[.s], :d[.s], ::d[.s]

Return to bug 2341