[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

xtrans: Changes to 'upstream-unstable'



 Xtrans.c     |   91 +++++++++++++++++++++++----
 Xtrans.h     |    6 -
 Xtransdnet.c |    6 -
 Xtransint.h  |   16 +---
 Xtranslcl.c  |    6 -
 Xtranssock.c |  198 +++++++++++++++++++++++++++++++++++++++++++++--------------
 Xtranstli.c  |    6 -
 Xtransutil.c |    8 --
 configure.ac |    5 -
 transport.c  |    6 -
 10 files changed, 248 insertions(+), 100 deletions(-)

New commits:
commit 662994b9096181117cec4cae88f24bf6da806159
Author: Adam Jackson <ajax@redhat.com>
Date:   Wed Mar 5 21:02:28 2008 -0500

    xtrans 1.1

diff --git a/configure.ac b/configure.ac
index c713be8..0846bf1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,6 +1,3 @@
-dnl 
-dnl  $Id$
-dnl 
 dnl  Copyright © 2003 Keith Packard, Noah Levitt
 dnl 
 dnl  Permission to use, copy, modify, distribute, and sell this software and its
@@ -24,7 +21,7 @@ dnl
 dnl Process this file with autoconf to create configure.
 
 AC_PREREQ([2.57])
-AC_INIT(xtrans, 1.0.4, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xtrans)
+AC_INIT(xtrans, 1.1, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xtrans)
 AM_INIT_AUTOMAKE([dist-bzip2])
 AM_MAINTAINER_MODE
 

commit 2afe206ec9569e0d62caa6d91c3fb057b0efa23d
Author: Adam Jackson <ajax@redhat.com>
Date:   Wed Mar 5 20:48:59 2008 -0500

    Add support for the abstract socket namespace under Linux.
    
    Unlike normal unix sockets, the abstract namespace is not bound to the
    filesystem.  This has some notable advantages; /tmp need not exist, the
    socket directory need not have magic permissions, etc.  xtrans servers
    will listen on both the normal and abstract socket endpoints; clients
    will attempt to connect to the abstract socket before connecting to the
    corresponding filesystem socket.
    
    Based on a patch by Bill Crawford.

diff --git a/Xtransint.h b/Xtransint.h
index 97e8a89..317dbf8 100644
--- a/Xtransint.h
+++ b/Xtransint.h
@@ -369,9 +369,10 @@ typedef struct _Xtransport_table {
 #define TRANS_DISABLED	(1<<2)	/* Don't open this one */
 #define TRANS_NOLISTEN  (1<<3)  /* Don't listen on this one */
 #define TRANS_NOUNLINK	(1<<4)	/* Dont unlink transport endpoints */
+#define TRANS_ABSTRACT	(1<<5)	/* Use abstract sockets if available */
 
 /* Flags to preserve when setting others */
-#define TRANS_KEEPFLAGS	(TRANS_NOUNLINK)
+#define TRANS_KEEPFLAGS	(TRANS_NOUNLINK|TRANS_ABSTRACT)
 
 /*
  * readv() and writev() don't exist or don't work correctly on some
diff --git a/Xtranssock.c b/Xtranssock.c
index 646d634..94b73e2 100644
--- a/Xtranssock.c
+++ b/Xtranssock.c
@@ -158,6 +158,10 @@ static int IBMsockInit = 0;
 #define SocketInitOnce() /**/
 #endif
 
+#ifdef linux
+#define HAVE_ABSTRACT_SOCKETS
+#endif
+
 #define MIN_BACKLOG 128
 #ifdef SOMAXCONN
 #if SOMAXCONN > MIN_BACKLOG
@@ -880,23 +884,28 @@ TRANS(SocketSetOption) (XtransConnInfo ciptr, int option, int arg)
 
 #ifdef UNIXCONN
 static int
-set_sun_path(const char *port, const char *upath, char *path)
+set_sun_path(const char *port, const char *upath, char *path, int abstract)
 {
     struct sockaddr_un s;
     int maxlen = sizeof(s.sun_path) - 1;
+    const char *at = "";
 
     if (!port || !*port || !path)
 	return -1;
 
-    if (*port == '/') { /* a full pathname */
-	if (strlen(port) > maxlen)
-	    return -1;
-	sprintf(path, "%s", port);
-    } else {
-	if (strlen(port) + strlen(upath) > maxlen)
-	    return -1;
-	sprintf(path, "%s%s", upath, port);
-    }
+#ifdef HAVE_ABSTRACT_SOCKETS
+    if (port[0] == '@')
+	upath = "";
+    else if (abstract)
+	at = "@";
+#endif
+
+    if (*port == '/') /* a full pathname */
+	upath = "";
+
+    if (strlen(port) + strlen(upath) > maxlen)
+	return -1;
+    sprintf(path, "%s%s%s", at, upath, port);
     return 0;
 }
 #endif
@@ -1119,6 +1128,12 @@ TRANS(SocketUNIXCreateListener) (XtransConnInfo ciptr, char *port,
     int			oldUmask;
     int			status;
     unsigned int	mode;
+    char		tmpport[108];
+
+    int			abstract = 0;
+#ifdef HAVE_ABSTRACT_SOCKETS
+    abstract = ciptr->transptr->flags & TRANS_ABSTRACT;
+#endif
 
     PRMSG (2, "SocketUNIXCreateListener(%s)\n",
 	port ? port : "NULL", 0, 0);
@@ -1141,16 +1156,16 @@ TRANS(SocketUNIXCreateListener) (XtransConnInfo ciptr, char *port,
     }
 #endif
 
+    memset(&sockname, 0, sizeof(sockname));
     sockname.sun_family = AF_UNIX;
 
-    if (port && *port) {
-	if (set_sun_path(port, UNIX_PATH, sockname.sun_path) != 0) {
-	    PRMSG (1, "SocketUNIXCreateListener: path too long\n", 0, 0, 0);
-	    return TRANS_CREATE_LISTENER_FAILED;
-	}
-    } else {
-	snprintf (sockname.sun_path, sizeof(sockname.sun_path),
-		  "%s%ld", UNIX_PATH, (long)getpid());
+    if (!(port && *port)) {
+	snprintf (tmpport, sizeof(tmpport), "%s%ld", UNIX_PATH, (long)getpid());
+	port = tmpport;
+    }
+    if (set_sun_path(port, UNIX_PATH, sockname.sun_path, abstract) != 0) {
+	PRMSG (1, "SocketUNIXCreateListener: path too long\n", 0, 0, 0);
+	return TRANS_CREATE_LISTENER_FAILED;
     }
 
 #if (defined(BSD44SOCKETS) || defined(__UNIXWARE__)) && !defined(Lynx)
@@ -1163,7 +1178,12 @@ TRANS(SocketUNIXCreateListener) (XtransConnInfo ciptr, char *port,
     namelen = strlen(sockname.sun_path) + offsetof(struct sockaddr_un, sun_path);
 #endif
 
-    unlink (sockname.sun_path);
+    if (abstract) {
+	sockname.sun_path[0] = '\0';
+	namelen = sizeof(sockname);
+    }
+    else
+	unlink (sockname.sun_path);
 
     if ((status = TRANS(SocketCreateListener) (ciptr,
 	(struct sockaddr *) &sockname, namelen, flags)) < 0)
@@ -1193,6 +1213,9 @@ TRANS(SocketUNIXCreateListener) (XtransConnInfo ciptr, char *port,
         return TRANS_CREATE_LISTENER_FAILED;
     }
 
+    if (abstract)
+	sockname.sun_path[0] = '@';
+
     ciptr->family = sockname.sun_family;
     ciptr->addrlen = namelen;
     memcpy (ciptr->addr, &sockname, ciptr->addrlen);
@@ -1215,16 +1238,22 @@ TRANS(SocketUNIXResetListener) (XtransConnInfo ciptr)
     struct stat		statb;
     int 		status = TRANS_RESET_NOOP;
     unsigned int	mode;
+    int abstract = 0;
+#ifdef HAVE_ABSTRACT_SOCKETS
+    abstract = ciptr->transptr->flags & TRANS_ABSTRACT;
+#endif
 
     PRMSG (3, "SocketUNIXResetListener(%p,%d)\n", ciptr, ciptr->fd, 0);
 
-    if (stat (unsock->sun_path, &statb) == -1 ||
+    if (!abstract && (
+	stat (unsock->sun_path, &statb) == -1 ||
         ((statb.st_mode & S_IFMT) !=
 #if (defined (sun) && defined(SVR4)) || defined(NCR) || defined(SCO325) || !defined(S_IFSOCK)
-	  		S_IFIFO))
+	  		S_IFIFO
 #else
-			S_IFSOCK))
+			S_IFSOCK
 #endif
+				)))
     {
 	int oldUmask = umask (0);
 
@@ -1407,6 +1436,10 @@ TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status)
         return NULL;
     }
 
+    /*
+     * if the socket is abstract, we already modified the address to have a
+     * @ instead of the initial NUL, so no need to do that again here.
+     */
 
     newciptr->addrlen = ciptr->addrlen;
     memcpy (newciptr->addr, ciptr->addr, newciptr->addrlen);
@@ -2005,6 +2038,10 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
     int			old_namelen;
 #endif
 
+    int abstract = 0;
+#ifdef HAVE_ABSTRACT_SOCKETS
+    abstract = ciptr->transptr->flags & TRANS_ABSTRACT;
+#endif
 
     PRMSG (2,"SocketUNIXConnect(%d,%s,%s)\n", ciptr->fd, host, port);
     
@@ -2042,7 +2079,7 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
     
     sockname.sun_family = AF_UNIX;
 
-    if (set_sun_path(port, UNIX_PATH, sockname.sun_path) != 0) {
+    if (set_sun_path(port, UNIX_PATH, sockname.sun_path, abstract) != 0) {
 	PRMSG (1, "SocketUNIXConnect: path too long\n", 0, 0, 0);
 	return TRANS_CONNECT_FAILED;
     }
@@ -2063,7 +2100,7 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
      * This is gross, but it was in Xlib
      */
     old_sockname.sun_family = AF_UNIX;
-    if (set_sun_path(port, OLD_UNIX_PATH, old_sockname.sun_path) != 0) {
+    if (set_sun_path(port, OLD_UNIX_PATH, old_sockname.sun_path, abstract) != 0) {
 	PRMSG (1, "SocketUNIXConnect: path too long\n", 0, 0, 0);
 	return TRANS_CONNECT_FAILED;
     }
@@ -2071,6 +2108,17 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
 	offsetof(struct sockaddr_un, sun_path);
 #endif
 
+    /*
+     * Adjust the socket path if using abstract sockets.
+     * Done here because otherwise all the strlen() calls above would fail.
+     */
+
+    if (abstract) {
+	sockname.sun_path[0] = '\0';
+#if defined(hpux) && defined(X11_t)
+	old_sockname.sun_path[0] = '\0';
+#endif
+    }
 
     /*
      * Do the connect()
@@ -2108,12 +2156,19 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
 	     * should try again.
 	     */
 
-	    if (olderrno == ENOENT || olderrno == EINTR)
-		return TRANS_TRY_CONNECT_AGAIN;
-	    else if (olderrno == EWOULDBLOCK || olderrno == EINPROGRESS)
+	    if (olderrno == EWOULDBLOCK || olderrno == EINPROGRESS)
 		return TRANS_IN_PROGRESS;
-	    else
-	    {
+	    else if (olderrno == EINTR)
+		return TRANS_TRY_CONNECT_AGAIN;
+	    else if (olderrno == ENOENT) {
+		/*
+		* If opening as abstract socket failed, try again "normally"
+		*/
+		if (abstract)
+		    ciptr->transptr->flags &= ~(TRANS_ABSTRACT);
+		return TRANS_TRY_CONNECT_AGAIN;
+	    }
+	    else {
 		PRMSG (2,"SocketUNIXConnect: Can't connect: errno = %d\n",
 		       EGET(),0, 0);
 
@@ -2136,12 +2191,15 @@ TRANS(SocketUNIXConnect) (XtransConnInfo ciptr, char *host, char *port)
         return TRANS_CONNECT_FAILED;
     }
 
+    if (abstract)
+	sockname.sun_path[0] = '@';
+
     ciptr->family = AF_UNIX;
     ciptr->addrlen = namelen;
     ciptr->peeraddrlen = namelen;
     memcpy (ciptr->addr, &sockname, ciptr->addrlen);
     memcpy (ciptr->peeraddr, &sockname, ciptr->peeraddrlen);
-    
+
     return 0;
 }
 
@@ -2281,7 +2339,6 @@ TRANS(SocketINETClose) (XtransConnInfo ciptr)
 #ifdef UNIXCONN
 static int
 TRANS(SocketUNIXClose) (XtransConnInfo ciptr)
-
 {
     /*
      * If this is the server side, then once the socket is closed,
@@ -2300,7 +2357,8 @@ TRANS(SocketUNIXClose) (XtransConnInfo ciptr)
        && sockname->sun_family == AF_UNIX
        && sockname->sun_path[0])
     {
-	if (!(ciptr->flags & TRANS_NOUNLINK))
+	if (!(ciptr->flags & TRANS_NOUNLINK
+	    || ciptr->transptr->flags & TRANS_ABSTRACT))
 		unlink (sockname->sun_path);
     }
 
@@ -2467,7 +2525,11 @@ Xtransport     TRANS(SocketINET6Funcs) = {
 Xtransport	TRANS(SocketLocalFuncs) = {
 	/* Socket Interface */
 	"local",
+#ifdef HAVE_ABSTRACT_SOCKETS
+	TRANS_ABSTRACT,
+#else
 	0,
+#endif
 #ifdef TRANS_CLIENT
 	TRANS(SocketOpenCOTSClient),
 #endif /* TRANS_CLIENT */
@@ -2513,7 +2575,7 @@ static char* unix_nolisten[] = { "local" , NULL };
 Xtransport	TRANS(SocketUNIXFuncs) = {
 	/* Socket Interface */
 	"unix",
-#if !defined(LOCALCONN)
+#if !defined(LOCALCONN) && !defined(HAVE_ABSTRACT_SOCKETS)
         TRANS_ALIAS,
 #else
 	0,

commit c8ed67f16f71042ef134a4d2189c20dd200a0648
Author: Jeremy Huddleston <jeremy@tifa.local>
Date:   Sun Feb 10 19:04:40 2008 -0800

    Fixed #ifdef checks that were using i386 to use __i386__
    
    """
    
    It's simply obsolete, sloppy, compiler namespace pollution.  The
    compiler is not allowed to predefine symbols that might conflict with
    ordinary identifiers.  For backwards compatibility gcc currently
    predefines i386 when compiling for x86 32-bit (but not 64-bit), but that
    will go away.  It is also not defined if you specify -ansi when invoking
    the compiler, because then it is seriously standards compliant.  Other
    compilers shouldn't define it either.  Correct code shouldn't rely on it
    being defined.  However __i386__ is safe and proper.
    
    """

diff --git a/Xtrans.c b/Xtrans.c
index 8ec2112..48b7497 100644
--- a/Xtrans.c
+++ b/Xtrans.c
@@ -1377,7 +1377,7 @@ static int TRANS(WriteV) (XtransConnInfo ciptr, struct iovec *iov, int iovcnt)
 
 #endif /* CRAY */
 
-#if (defined(SYSV) && defined(i386) && !defined(__SCO__) && !defined(sun)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__)
+#if (defined(SYSV) && defined(__i386__) && !defined(__SCO__) && !defined(sun)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__)
 
 /*
  * emulate readv
@@ -1407,9 +1407,9 @@ static int TRANS(ReadV) (XtransConnInfo ciptr, struct iovec *iov, int iovcnt)
     return total;
 }
 
-#endif /* SYSV && i386 || WIN32 || __sxg__ */
+#endif /* SYSV && __i386__ || WIN32 || __sxg__ */
 
-#if (defined(SYSV) && defined(i386) && !defined(__SCO__) && !defined(sun)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__)
+#if (defined(SYSV) && defined(__i386__) && !defined(__SCO__) && !defined(sun)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__)
 
 /*
  * emulate writev
@@ -1439,7 +1439,7 @@ static int TRANS(WriteV) (XtransConnInfo ciptr, struct iovec *iov, int iovcnt)
     return total;
 }
 
-#endif /* SYSV && i386 || WIN32 || __sxg__ */
+#endif /* SYSV && __i386__ || WIN32 || __sxg__ */
 
 
 #if (defined(_POSIX_SOURCE) && !defined(AIXV3) && !defined(__QNX__)) || defined(hpux) || defined(USG) || defined(SVR4) || defined(__SCO__)
diff --git a/Xtransint.h b/Xtransint.h
index 52d7d2c..97e8a89 100644
--- a/Xtransint.h
+++ b/Xtransint.h
@@ -378,7 +378,7 @@ typedef struct _Xtransport_table {
  * systems, so they may be emulated.
  */
 
-#if defined(CRAY) || (defined(SYSV) && defined(i386) && !defined(__SCO__) && !defined(sun)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__)
+#if defined(CRAY) || (defined(SYSV) && defined(__i386__) && !defined(__SCO__) && !defined(sun)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__)
 
 #define READV(ciptr, iov, iovcnt)	TRANS(ReadV)(ciptr, iov, iovcnt)
 
@@ -392,10 +392,10 @@ static	int TRANS(ReadV)(
 
 #define READV(ciptr, iov, iovcnt)	readv(ciptr->fd, iov, iovcnt)
 
-#endif /* CRAY || (SYSV && i386) || WIN32 || __sxg__ || */
+#endif /* CRAY || (SYSV && __i386__) || WIN32 || __sxg__ || */
 
 
-#if defined(CRAY) || (defined(SYSV) && defined(i386) && !defined(__SCO__) && !defined(sun)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__)
+#if defined(CRAY) || (defined(SYSV) && defined(__i386__) && !defined(__SCO__) && !defined(sun)) || defined(WIN32) || defined(__sxg__) || defined(__UNIXOS2__)
 
 #define WRITEV(ciptr, iov, iovcnt)	TRANS(WriteV)(ciptr, iov, iovcnt)
 
diff --git a/Xtranssock.c b/Xtranssock.c
index b7a601b..646d634 100644
--- a/Xtranssock.c
+++ b/Xtranssock.c
@@ -98,11 +98,11 @@ from the copyright holders.
 #include <sys/filio.h>
 #endif
 
-#if (defined(i386) && defined(SYSV)) && !defined(SCO325) && !defined(sun)
+#if (defined(__i386__) && defined(SYSV)) && !defined(SCO325) && !defined(sun)
 #include <net/errno.h>
 #endif 
 
-#if (defined(i386) && defined(SYSV)) && (!defined(ISC) || !defined(I_NREAD) || defined(SCO325)) || defined(_SEQUENT_)
+#if (defined(__i386__) && defined(SYSV)) && (!defined(ISC) || !defined(I_NREAD) || defined(SCO325)) || defined(_SEQUENT_)
 #include <sys/stropts.h>
 #endif 
 
@@ -2166,7 +2166,7 @@ TRANS(SocketBytesReadable) (XtransConnInfo ciptr, BytesReadable_t *pend)
 	return ret;
     }
 #else
-#if (defined(i386) && defined(SYSV) && !defined(SCO325)) || (defined(_SEQUENT_) && _SOCKET_VERSION == 1)
+#if (defined(__i386__) && defined(SYSV) && !defined(SCO325)) || (defined(_SEQUENT_) && _SOCKET_VERSION == 1)
     return ioctl (ciptr->fd, I_NREAD, (char *) pend);
 #else
 #if defined(__UNIXOS2__)
@@ -2174,7 +2174,7 @@ TRANS(SocketBytesReadable) (XtransConnInfo ciptr, BytesReadable_t *pend)
 #else
     return ioctl (ciptr->fd, FIONREAD, (char *) pend);
 #endif /* __UNIXOS2__ */
-#endif /* i386 && SYSV || _SEQUENT_ && _SOCKET_VERSION == 1 */
+#endif /* __i386__ && SYSV || _SEQUENT_ && _SOCKET_VERSION == 1 */
 #endif /* WIN32 */
 }
 

commit 9970b5b6f8237685267b7972282319cf266661ea
Author: Ben Byer <bbyer@bbyer.local>
Date:   Sun Dec 2 07:36:51 2007 -0800

    make launchd error messages less scary

diff --git a/Xtrans.c b/Xtrans.c
index 2bdbd06..8ec2112 100644
--- a/Xtrans.c
+++ b/Xtrans.c
@@ -1091,29 +1091,31 @@ TRANS(MakeAllCOTSServerListeners) (char *port, int *partial, int *count_ret,
 	}
 
     if (LAUNCH_DATA_ERRNO == launch_data_get_type(checkin_response)) {
-       fprintf(stderr,"Check-in failed: %s\n",strerror(launch_data_get_errno(checkin_response)));
+      // ignore EACCES, which is common if we weren't started by launchd
+      if (launch_data_get_errno(checkin_response) != EACCES)
+       fprintf(stderr,"launchd check-in failed: %s\n",strerror(launch_data_get_errno(checkin_response)));
 	   goto not_launchd;
 	} 
 
 	sockets_dict = launch_data_dict_lookup(checkin_response, LAUNCH_JOBKEY_SOCKETS);
     if (NULL == sockets_dict) {
-       fprintf(stderr,"No sockets found to answer requests on!\n");
+       fprintf(stderr,"launchd check-in: no sockets found to answer requests on!\n");
 	   goto not_launchd;
 	}
 
     if (launch_data_dict_get_count(sockets_dict) > 1) {
-       fprintf(stderr,"Some sockets will be ignored!\n");
+       fprintf(stderr,"launchd check-in: some sockets will be ignored!\n");
 	   goto not_launchd;
 	}
 
     listening_fd_array = launch_data_dict_lookup(sockets_dict, ":0");
     if (NULL == listening_fd_array) {
-       fprintf(stderr,"No known sockets found to answer requests on!\n");
+       fprintf(stderr,"launchd check-in: No known sockets found to answer requests on!\n");
 	   goto not_launchd;
 	}
 
     if (launch_data_array_get_count(listening_fd_array)!=1) {
-       fprintf(stderr,"Expected 1 socket from launchd, got %d)\n",
+       fprintf(stderr,"launchd check-in: Expected 1 socket from launchd, got %d)\n",
                        launch_data_array_get_count(listening_fd_array));
 	   goto not_launchd;
 	}

commit cd1da5cec49fb7fe6238a00d9ba550b3ed78fa08
Author: Ben Byer <bbyer@bbyer.local>
Date:   Wed Nov 14 03:57:57 2007 -0800

    Fix for incorrect processing of recycled launchd socket on OS X

diff --git a/Xtranssock.c b/Xtranssock.c
index 8b18f09..b7a601b 100644
--- a/Xtranssock.c
+++ b/Xtranssock.c
@@ -535,7 +535,7 @@ TRANS(SocketReopen) (int i, int type, int fd, char *port)
       return NULL;
     }
 
-    portlen = strlen(port);
+    portlen = strlen(port) + 1; // include space for trailing null
 #ifdef BSD44SOCKETS
     if (portlen < 0 || portlen > (SOCK_MAXADDRLEN + 2)) {
       PRMSG (1, "SocketReopen: invalid portlen %d\n", portlen, 0, 0);
@@ -572,7 +572,7 @@ TRANS(SocketReopen) (int i, int type, int fd, char *port)
     ciptr->peeraddrlen = portlen + 2;
 
     /* Initialize ciptr structure as if it were a normally-opened unix socket */
-    ciptr->flags = TRANS_LOCAL;
+    ciptr->flags = TRANS_LOCAL | TRANS_NOUNLINK;
 #ifdef BSD44SOCKETS
     addr->sa_len = portlen + 1;
 #endif

commit 3da4d6c1dc05f9e1291b023a97535eb67f0830e2
Author: Ben Byer <bbyer@bbyer.local>
Date:   Wed Nov 14 03:55:42 2007 -0800

    removed cvs tags

diff --git a/Xtrans.c b/Xtrans.c
index 4de9161..2bdbd06 100644
--- a/Xtrans.c
+++ b/Xtrans.c
@@ -1,5 +1,3 @@
-/* $XdotOrg: xc/lib/xtrans/Xtrans.c,v 1.4 2004/11/15 15:06:56 ago Exp $ */
-/* $Xorg: Xtrans.c,v 1.4 2001/02/09 02:04:06 xorgcvs Exp $ */
 /*
 
 Copyright 1993, 1994, 1998  The Open Group
@@ -26,10 +24,7 @@ not be used in advertising or otherwise to promote the sale, use or
 other dealings in this Software without prior written authorization
 from The Open Group.
 
-*/
-/* $XFree86: xc/lib/xtrans/Xtrans.c,v 3.33 2003/08/11 17:41:29 eich Exp $ */
-
-/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
  *
  * All Rights Reserved
  *
diff --git a/Xtrans.h b/Xtrans.h
index e8d4bdf..42def32 100644
--- a/Xtrans.h
+++ b/Xtrans.h
@@ -1,4 +1,3 @@
-/* $Xorg: Xtrans.h,v 1.4 2001/02/09 02:04:06 xorgcvs Exp $ */
 /*
 
 Copyright 1993, 1994, 1998  The Open Group
@@ -25,10 +24,7 @@ not be used in advertising or otherwise to promote the sale, use or
 other dealings in this Software without prior written authorization
 from The Open Group.
 
-*/
-/* $XFree86: xc/lib/xtrans/Xtrans.h,v 3.21 2003/07/20 16:12:15 tsi Exp $ */
-
-/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
  *
  * All Rights Reserved
  *
diff --git a/Xtransdnet.c b/Xtransdnet.c
index ac91695..5e8d008 100644
--- a/Xtransdnet.c
+++ b/Xtransdnet.c
@@ -1,4 +1,3 @@
-/* $Xorg: Xtransdnet.c,v 1.4 2001/02/09 02:04:06 xorgcvs Exp $ */
 /*
 
 Copyright 1993, 1994, 1998  The Open Group
@@ -25,10 +24,7 @@ not be used in advertising or otherwise to promote the sale, use or
 other dealings in this Software without prior written authorization
 from The Open Group.
 
-*/
-/* $XFree86: xc/lib/xtrans/Xtransdnet.c,v 3.7tsi Exp $ */
-
-/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
  *
  * All Rights Reserved
  *
diff --git a/Xtransint.h b/Xtransint.h
index 663c689..52d7d2c 100644
--- a/Xtransint.h
+++ b/Xtransint.h
@@ -1,5 +1,3 @@
-/* $XdotOrg: xc/lib/xtrans/Xtransint.h,v 1.2 2004/04/23 18:44:27 eich Exp $ */
-/* $Xorg: Xtransint.h,v 1.4 2001/02/09 02:04:06 xorgcvs Exp $ */
 /*
 
 Copyright 1993, 1994, 1998  The Open Group
@@ -26,10 +24,7 @@ not be used in advertising or otherwise to promote the sale, use or
 other dealings in this Software without prior written authorization
 from The Open Group.
 
-*/
-/* $XFree86: xc/lib/xtrans/Xtransint.h,v 3.41 2003/08/28 00:35:23 tsi Exp $ */
-
-/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
  *
  * All Rights Reserved
  *
diff --git a/Xtranslcl.c b/Xtranslcl.c
index 9b83bb3..0127d67 100644
--- a/Xtranslcl.c
+++ b/Xtranslcl.c
@@ -1,4 +1,3 @@
-/* $Xorg: Xtranslcl.c,v 1.6 2001/02/09 02:04:06 xorgcvs Exp $ */
 /*
 
 Copyright 1993, 1994, 1998  The Open Group
@@ -25,10 +24,7 @@ not be used in advertising or otherwise to promote the sale, use or
 other dealings in this Software without prior written authorization
 from The Open Group.
 
-*/
-/* $XFree86: xc/lib/xtrans/Xtranslcl.c,v 3.40tsi Exp $ */
-
-/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
  *
  * All Rights Reserved
  *
diff --git a/Xtranssock.c b/Xtranssock.c
index 33f0290..8b18f09 100644
--- a/Xtranssock.c
+++ b/Xtranssock.c
@@ -1,5 +1,3 @@
-/* $XdotOrg: lib/xtrans/Xtranssock.c,v 1.11 2005/11/08 06:33:26 jkj Exp $ */
-/* $Xorg: Xtranssock.c,v 1.11 2001/02/09 02:04:06 xorgcvs Exp $ */
 /*
 
 Copyright 1993, 1994, 1998  The Open Group
@@ -27,10 +25,7 @@ not be used in advertising or otherwise to promote the sale, use or
 other dealings in this Software without prior written authorization
 from the copyright holders.
 
-*/
-/* $XFree86: xc/lib/xtrans/Xtranssock.c,v 3.68 2004/01/07 04:28:02 dawes Exp $ */
-
-/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
  *
  * All Rights Reserved
  *
diff --git a/Xtranstli.c b/Xtranstli.c
index d8b5db8..a9dfc21 100644
--- a/Xtranstli.c
+++ b/Xtranstli.c
@@ -1,4 +1,3 @@
-/* $Xorg: Xtranstli.c,v 1.4 2001/02/09 02:04:07 xorgcvs Exp $ */
 /*
 
 Copyright 1993, 1994, 1998  The Open Group
@@ -25,10 +24,7 @@ not be used in advertising or otherwise to promote the sale, use or
 other dealings in this Software without prior written authorization
 from The Open Group.
 
-*/
-/* $XFree86: xc/lib/xtrans/Xtranstli.c,v 3.12tsi Exp $ */
-
-/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
  *
  * All Rights Reserved
  *
diff --git a/Xtransutil.c b/Xtransutil.c
index 4fa9cf8..a35c84b 100644
--- a/Xtransutil.c
+++ b/Xtransutil.c
@@ -1,4 +1,3 @@
-/* $Xorg: Xtransutil.c,v 1.4 2001/02/09 02:04:07 xorgcvs Exp $ */
 /*
 
 Copyright 1993, 1994, 1998  The Open Group
@@ -25,10 +24,7 @@ not be used in advertising or otherwise to promote the sale, use or
 other dealings in this Software without prior written authorization
 from The Open Group.
 
-*/
-/* $XFree86: xc/lib/xtrans/Xtransutil.c,v 3.26 2003/07/09 15:27:30 tsi Exp $ */
-
-/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
  *
  * All Rights Reserved
  *
diff --git a/transport.c b/transport.c
index ff460c2..0d1eaf9 100644
--- a/transport.c
+++ b/transport.c
@@ -1,4 +1,3 @@
-/* $Xorg: transport.c,v 1.4 2001/02/09 02:04:07 xorgcvs Exp $ */
 /*
 
 Copyright 1993, 1994, 1998  The Open Group
@@ -25,10 +24,7 @@ not be used in advertising or otherwise to promote the sale, use or
 other dealings in this Software without prior written authorization
 from The Open Group.
 
-*/
-/* $XFree86: xc/lib/xtrans/transport.c,v 3.9 2002/05/31 18:45:51 dawes Exp $ */
-
-/* Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
+ * Copyright 1993, 1994 NCR Corporation - Dayton, Ohio, USA
  *
  * All Rights Reserved
  *

commit 496cf2c46d2123c3bed3e6878f8f9a62e87ce559
Author: Dodji Seketeli <dodji@seketeli.org>
Date:   Tue Sep 11 12:52:44 2007 +0200

    libxtrans: fixed a typo in my last commit
    
            * Xtranssock.c: (SocketReopen): oops fix a typo in my last commit.

diff --git a/Xtranssock.c b/Xtranssock.c
index 52f9aa1..33f0290 100644
--- a/Xtranssock.c
+++ b/Xtranssock.c
@@ -582,7 +582,7 @@ TRANS(SocketReopen) (int i, int type, int fd, char *port)
     addr->sa_len = portlen + 1;
 #endif
     addr->sa_family = AF_UNIX;
-#ifdef HAVE_STRLCPY
+#ifdef HAS_STRLCPY
     strlcpy(addr->sa_data, port, portlen);
 #else
     strncpy(addr->sa_data, port, portlen);

commit 88e141225113fcc4ebe5e8fe361e75673cdbf9ff
Author: Dodji Seketeli <dodji@seketeli.org>
Date:   Tue Sep 11 08:48:03 2007 +0200

    libxtrans: fix linux compilation breakage
    
            * Xtranssock.c:
              (SocketReopen): protect use of BSD4.4 socket with BSD44SOCKETS macro.
              protect use of strlcnpy with HAVE_STRLCPY macro.
              That one is defined (or not) by the xserver configure.

diff --git a/Xtranssock.c b/Xtranssock.c
index e989b42..52f9aa1 100644
--- a/Xtranssock.c
+++ b/Xtranssock.c
@@ -172,6 +172,7 @@ static int IBMsockInit = 0;
 #ifndef BACKLOG
 #define BACKLOG MIN_BACKLOG
 #endif
+
 /*
  * This is the Socket implementation of the X Transport service layer
  *
@@ -540,12 +541,18 @@ TRANS(SocketReopen) (int i, int type, int fd, char *port)
     }
 
     portlen = strlen(port);
+#ifdef BSD44SOCKETS
     if (portlen < 0 || portlen > (SOCK_MAXADDRLEN + 2)) {
       PRMSG (1, "SocketReopen: invalid portlen %d\n", portlen, 0, 0);
       return NULL;
     }
-    
     if (portlen < 14) portlen = 14;
+#else
+    if (portlen < 0 || portlen > 14) {
+      PRMSG (1, "SocketReopen: invalid portlen %d\n", portlen, 0, 0);
+      return NULL;
+    }
+#endif /*BSD44SOCKETS*/
 
     if ((ciptr = (XtransConnInfo) xcalloc (
 	1, sizeof(struct _XtransConnInfo))) == NULL)
@@ -571,9 +578,15 @@ TRANS(SocketReopen) (int i, int type, int fd, char *port)
 
     /* Initialize ciptr structure as if it were a normally-opened unix socket */
     ciptr->flags = TRANS_LOCAL;
+#ifdef BSD44SOCKETS
     addr->sa_len = portlen + 1;
+#endif
     addr->sa_family = AF_UNIX;
+#ifdef HAVE_STRLCPY
     strlcpy(addr->sa_data, port, portlen);
+#else
+    strncpy(addr->sa_data, port, portlen);
+#endif
     ciptr->family = AF_UNIX;
     memcpy(ciptr->peeraddr, ciptr->addr, sizeof(struct sockaddr));
     ciptr->port = rindex(addr->sa_data, ':');

commit 6217f34977bfa17b66b89df5d45420774abedcb3
Author: Ben Byer <bbyer@bbyer.apple.com>
Date:   Wed Sep 5 18:29:44 2007 -0700

    changes to support launchd on OS X

diff --git a/Xtrans.c b/Xtrans.c
index 00391a0..4de9161 100644
--- a/Xtrans.c
+++ b/Xtrans.c
@@ -53,6 +53,9 @@ from The Open Group.
  */
 
 #include <ctype.h>
+#ifdef HAVE_LAUNCHD
+#include <launch.h>
+#endif
 
 /*
  * The transport table contains a definition for every transport (protocol)
@@ -360,6 +363,15 @@ TRANS(ParseAddress) (char *address, char **protocol, char **host, char **port)
      */
 #endif
 
+#ifdef HAVE_LAUNCHD
+    /* launchd sockets will look like 'local//tmp/launch-XgkNns/:0' */
+    if(address != NULL && strlen(address)>8 && (!strncmp(address,"local//",7))) {
+      _protocol="local";
+      _host="";
+      _port=address+6;
+    }
+#endif
+
     /*
      * Now that we have all of the components, allocate new
      * string space for them.
@@ -858,6 +870,10 @@ TRANS(Connect) (XtransConnInfo ciptr, char *address)
 	return -1;
     }
 
+#ifdef HAVE_LAUNCHD
+    if (!host || !*host) host=strdup("");
+#endif
+
     if (!port || !*port)
     {
 	PRMSG (1,"Connect: Missing port specification in %s\n",
@@ -1053,15 +1069,71 @@ TRANS(MakeAllCOTSServerListeners) (char *port, int *partial, int *count_ret,
     char		buffer[256]; /* ??? What size ?? */
     XtransConnInfo	ciptr, temp_ciptrs[NUMTRANS];
     int			status, i, j;
+#ifdef HAVE_LAUNCHD
+    int                 launchd_fd;
+    launch_data_t       sockets_dict, checkin_request, checkin_response;
+    launch_data_t       listening_fd_array, listening_fd;
+#endif
+
 #if defined(IPv6) && defined(AF_INET6)
     int		ipv6_succ = 0;
 #endif
-
     PRMSG (2,"MakeAllCOTSServerListeners(%s,%p)\n",
 	   port ? port : "NULL", ciptrs_ret, 0);
 
     *count_ret = 0;
 
+#ifdef HAVE_LAUNCHD
+    /* Get launchd fd */
+    if ((checkin_request = launch_data_new_string(LAUNCH_KEY_CHECKIN)) == NULL) {
+      fprintf(stderr,"launch_data_new_string(\"" LAUNCH_KEY_CHECKIN "\") Unable to create string.\n");
+	  goto not_launchd;
+	  }
+
+    if ((checkin_response = launch_msg(checkin_request)) == NULL) {
+       fprintf(stderr,"launch_msg(\"" LAUNCH_KEY_CHECKIN "\") IPC failure: %s\n",strerror(errno));
+	   goto not_launchd;
+	}
+
+    if (LAUNCH_DATA_ERRNO == launch_data_get_type(checkin_response)) {
+       fprintf(stderr,"Check-in failed: %s\n",strerror(launch_data_get_errno(checkin_response)));
+	   goto not_launchd;
+	} 
+
+	sockets_dict = launch_data_dict_lookup(checkin_response, LAUNCH_JOBKEY_SOCKETS);
+    if (NULL == sockets_dict) {
+       fprintf(stderr,"No sockets found to answer requests on!\n");
+	   goto not_launchd;
+	}
+
+    if (launch_data_dict_get_count(sockets_dict) > 1) {
+       fprintf(stderr,"Some sockets will be ignored!\n");
+	   goto not_launchd;
+	}
+
+    listening_fd_array = launch_data_dict_lookup(sockets_dict, ":0");
+    if (NULL == listening_fd_array) {
+       fprintf(stderr,"No known sockets found to answer requests on!\n");
+	   goto not_launchd;
+	}
+
+    if (launch_data_array_get_count(listening_fd_array)!=1) {
+       fprintf(stderr,"Expected 1 socket from launchd, got %d)\n",
+                       launch_data_array_get_count(listening_fd_array));
+	   goto not_launchd;
+	}
+
+    listening_fd=launch_data_array_get_index(listening_fd_array, 0);
+    launchd_fd=launch_data_get_fd(listening_fd);
+    fprintf(stderr,"Xquartz: run by launchd for fd %d\n",launchd_fd);
+    if((ciptr = TRANS(ReopenCOTSServer(TRANS_SOCKET_LOCAL_INDEX,
+                                       launchd_fd, getenv("DISPLAY"))))==NULL)
+        fprintf(stderr,"Got NULL while trying to Reopen launchd port\n");
+        else temp_ciptrs[(*count_ret)++] = ciptr;
+
+not_launchd:
+#endif
+
     for (i = 0; i < NUMTRANS; i++)
     {
 	Xtransport *trans = Xtransports[i].transport;
diff --git a/Xtranssock.c b/Xtranssock.c
index 65d4beb..e989b42 100644
--- a/Xtranssock.c
+++ b/Xtranssock.c
@@ -529,18 +529,55 @@ TRANS(SocketReopen) (int i, int type, int fd, char *port)
 
 {
     XtransConnInfo	ciptr;
+    int portlen;
+    struct sockaddr *addr;
 
     PRMSG (3,"SocketReopen(%d,%d,%s)\n", type, fd, port);
 
+    if (port == NULL) {
+      PRMSG (1, "SocketReopen: port was null!\n", 0, 0, 0);
+      return NULL;
+    }
+
+    portlen = strlen(port);
+    if (portlen < 0 || portlen > (SOCK_MAXADDRLEN + 2)) {
+      PRMSG (1, "SocketReopen: invalid portlen %d\n", portlen, 0, 0);
+      return NULL;
+    }
+    
+    if (portlen < 14) portlen = 14;
+
     if ((ciptr = (XtransConnInfo) xcalloc (
 	1, sizeof(struct _XtransConnInfo))) == NULL)
     {
-	PRMSG (1, "SocketReopen: malloc failed\n", 0, 0, 0);
+	PRMSG (1, "SocketReopen: malloc(ciptr) failed\n", 0, 0, 0);
 	return NULL;
     }
 
     ciptr->fd = fd;
 
+    if ((addr = (struct sockaddr *) xcalloc (1, portlen + 2)) == NULL) {
+	PRMSG (1, "SocketReopen: malloc(addr) failed\n", 0, 0, 0);
+	return NULL;
+    }
+    ciptr->addr = addr;
+    ciptr->addrlen = portlen + 2;
+
+    if ((ciptr->peeraddr = (struct sockaddr *) xcalloc (1, portlen + 2)) == NULL) {
+	PRMSG (1, "SocketReopen: malloc(portaddr) failed\n", 0, 0, 0);
+	return NULL;
+    }
+    ciptr->peeraddrlen = portlen + 2;
+
+    /* Initialize ciptr structure as if it were a normally-opened unix socket */
+    ciptr->flags = TRANS_LOCAL;
+    addr->sa_len = portlen + 1;
+    addr->sa_family = AF_UNIX;


Reply to: