On 9 October 2016 at 20:51, Jeremy Huddleston Sequoia <jerem...@apple.com> wrote: > This changes away from hard-coding the /tmp/launch-* path to now > supporting a generic <absolute path to unix socket>[.<screen>] > format for $DISPLAY. > > cf-libxcb: d978a4f69b30b630f28d07f1003cf290284d24d8 > > Signed-off-by: Jeremy Huddleston Sequoia <jerem...@apple.com> > CC: Adam Jackson <a...@kemper.freedesktop.org> > --- > os/connection.c | 31 ++++++++++++++++++++++++++----- > 1 file changed, 26 insertions(+), 5 deletions(-) > > diff --git a/os/connection.c b/os/connection.c > index a901ebf..0d42184 100644 > --- a/os/connection.c > +++ b/os/connection.c > @@ -79,6 +79,8 @@ SOFTWARE. > #include <stdio.h> > #include <stdlib.h> > > +#include <sys/stat.h> > + > #ifndef WIN32 > #include <sys/socket.h> > > @@ -1112,15 +1114,34 @@ MakeClientGrabPervious(ClientPtr client) > void > ListenOnOpenFD(int fd, int noxauth) > { > - char port[256]; > + char port[PATH_MAX]; ... = {0, }; // or port[0] = 0;
> XtransConnInfo ciptr; > const char *display_env = getenv("DISPLAY"); > > - if (display_env && (strncmp(display_env, "/tmp/launch", 11) == 0)) { > - /* Make the path the launchd socket if our DISPLAY is set right */ > - strcpy(port, display_env); > + /* First check if display_env matches a <absolute path to unix > socket>[.<screen number>] scheme (eg: launchd) */ > + if (display_env && display_env[0] == '/') { As-is the patch will accept badly formed DISPLAY and port will end up garbage. Might be better to keep track of/override port instead. > + struct stat sbuf; > + > + strlcpy(port, display_env, sizeof(port)); > + > + /* If the path exists, we don't have do do anything else. > + * If it doesn't, we need to check for a .<screen number> to strip > off and recheck. > + */ > + if (0 != stat(port, &sbuf)) { Nit: !stat(...) > + char *dot = strrchr(port, '.'); > + if (dot) { > + *dot = '\0'; > + > + if (0 != stat(port, &sbuf)) { Ditto > + display_env = NULL; port[0] = 0; > + } > + } else { > + display_env = NULL; Ditto. > + } > + } > } > - else { > + > + if (!display_env) { if (!port[0]) { Regards, Emil _______________________________________________ xorg-devel@lists.x.org: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: https://lists.x.org/mailman/listinfo/xorg-devel