From f990dd936b5fd1a40290bb88cde517a0ac38f823 Mon Sep 17 00:00:00 2001 From: Jeremy Huddleston Sequoia Date: Wed, 31 Dec 2014 02:42:17 -0800 Subject: Update DISPLAY parsing to work with new launchd paths in Yosemite Signed-off-by: Jeremy Huddleston Sequoia --- parsedpy.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'parsedpy.c') diff --git a/parsedpy.c b/parsedpy.c index c591b77..7365224 100644 --- a/parsedpy.c +++ b/parsedpy.c @@ -42,6 +42,9 @@ in this Software without prior written authorization from The Open Group. #include /* for FamilyLocal */ #include +#include +#include + #if defined(UNIXCONN) || defined(LOCALCONN) #define UNIX_CONNECTION "unix" #define UNIX_CONNECTION_LENGTH 4 @@ -158,8 +161,32 @@ parse_displayname (const char *displayname, if (!host) return False; - if(strncmp (host, "/tmp/launch", 11) == 0) { - family = FamilyLocal; + { + /* + * If using launchd socket, remove the screen number from the end + * of $DISPLAY and check if it is a path to a socket. + */ + char path[PATH_MAX]; + struct stat sbuf; + +#ifdef HAVE_STRLCPY + strlcpy(path, displayname, sizeof(path)); +#else + strncpy(path, displayname, sizeof(path)); + buf[sizeof(path) - 1] = '\0'; +#endif + if (0 == stat(path, &sbuf)) { + family = FamilyLocal; + } else { + char *dot = strrchr(path, '.'); + if (dot) { + *dot = '\0'; + /* screen = atoi(dot + 1); */ + if (0 == stat(path, &sbuf)) { + family = FamilyLocal; + } + } + } } /* -- cgit v1.2.1