Xserver dtrace provider 0.1 for Xorg 6.8.2 - initial release: July 4, 2005

/* Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, and/or sell copies of the Software, and to permit persons
 * to whom the Software is furnished to do so, provided that the above
 * copyright notice(s) and this permission notice appear in all copies of
 * the Software and that both the above copyright notice(s) and this
 * permission notice appear in supporting documentation.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
 * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
 * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 * 
 * Except as contained in this notice, the name of a copyright holder
 * shall not be used in advertising or otherwise to promote the sale, use
 * or other dealings in this Software without prior written authorization
 * of the copyright holder.
 */

This patch is built against the Xorg 6.8.2 release (aka X11R6.8.2).
Download the base source from http://www.x.org/download.cgi?rel=6.8.2
To build, do:
	bzcat X11R6.8.2-src.tar.bz2 | tar -xf -
	gpatch -p1 < 6.8.2-dtrace.patch
	cd xc
	make World

Once you're done, you should be able to drop in xc/programs/Xserver/Xorg
as a replacement for /usr/X11/bin/Xorg on a Solaris 10 or Nevada/Express
system.   (Sorry, x86 only for now, unless you've got Xorg drivers for a 
SPARC graphics card somewhere.)

diff -Nur -x CVS orig-6.8.2/xc/config/cf/sun.cf 6.8.2/xc/config/cf/sun.cf
--- orig-6.8.2/xc/config/cf/sun.cf	2005-01-12 23:00:10.568810000 -0800
+++ 6.8.2/xc/config/cf/sun.cf	2005-06-22 18:54:13.274512000 -0700
@@ -711,3 +711,12 @@
 DlModuleTarget(Concat3(lib,module,.so), deplist, objects)
 
 #endif
+
+#ifndef BuildDTraceSupport
+# if (OSMajorVersion == 5) && (OSMinorVersion >= 10) /* Solaris 10 and later */
+#  define BuildDTraceSupport YES
+# else
+#  define BuildDTraceSupport NO
+# endif
+#endif
+
diff -Nur -x CVS orig-6.8.2/xc/programs/Xserver/Imakefile 6.8.2/xc/programs/Xserver/Imakefile
--- orig-6.8.2/xc/programs/Xserver/Imakefile	2004-12-17 09:44:23.986731000 -0800
+++ 6.8.2/xc/programs/Xserver/Imakefile	2005-06-22 19:19:25.644096000 -0700
@@ -5,6 +5,11 @@
  */
 XCOMM $XFree86: xc/programs/Xserver/Imakefile,v 3.296 2003/11/23 06:47:00 torrey Exp $
 
+#if BuildDTraceSupport
+DTRACE_OBJ = Xserver-dtrace.o
+SITEEXTS = $(DTRACE_OBJ)
+#endif
+
 #ifndef InstallXserverSetUID
 #define InstallXserverSetUID NO
 #endif
@@ -215,7 +220,7 @@
 #if BuildLBX || GzipFontCompression
            ZLIB = GzipLibrary
 #endif
-             OS = os/LibraryTargetName(os)
+             OS = os/os.Osuf
         BSDEMUL = $(DEPXBSDLIB)
 #if DoLoadableServer
             MFB = mfb/ModuleLibraryTargetName(mfb)
@@ -263,7 +268,7 @@
 #endif
              MI = mi/LibraryTargetName(mi)
    MIINITEXTOBJ = mi/miinitext.o
-            DIX = dix/LibraryTargetName(dix)
+            DIX = dix/dix.Osuf
        FONTBASE = $(FONTLIBSRC)/fontbase.o \
 		  $(FONTLIBSRC)/LibraryTargetName(fontbase)
 #if XserverStaticFontLib
@@ -1207,3 +1212,14 @@
                 MakeNamedTargetSubdir($$i,NullParameter,all) ; \
         done
 #endif
+
+#if BuildDTraceSupport
+XCOMM DTrace magic
+
+DTRACE_SRC = Xserver.d
+DTRACE_MODULES = $(DIX) $(OS)
+
+$(DTRACE_OBJ): $(DTRACE_SRC) $(DTRACE_MODULES)
+        dtrace -G -C -32 -s $(DTRACE_SRC) -o $(DTRACE_OBJ) $(DTRACE_MODULES)
+
+#endif
diff -Nur -x CVS orig-6.8.2/xc/programs/Xserver/Xserver.d 6.8.2/xc/programs/Xserver/Xserver.d
--- orig-6.8.2/xc/programs/Xserver/Xserver.d	1969-12-31 16:00:00.000000000 -0800
+++ 6.8.2/xc/programs/Xserver/Xserver.d	2005-07-04 11:09:17.267106000 -0700
@@ -0,0 +1,60 @@
+/* Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
+ * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * 
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+#pragma ident   "%Z%%M% %I%     %E% SMI"
+
+/*
+ * Xserver dtrace provider definition
+ */
+
+#include <sys/types.h>
+
+/*
+#pragma D attributes Unstable/Unstable/Common provider Xserver provider
+#pragma D attributes Private/Private/Unknown provider Xserver module
+#pragma D attributes Private/Private/Unknown provider Xserver function
+#pragma D attributes Unstable/Unstable/Common provider Xserver name
+#pragma D attributes Unstable/Unstable/Common provider Xserver args
+*/
+
+provider Xserver {
+	/* reqType, data, length, client id, request buffer */
+	probe request__start(string, uint8_t, uint16_t, int, uintptr_t);
+	/* reqType, data, length, client id, result */
+	probe request__done(string, uint8_t, uint16_t, int, int);
+	/* client id */
+	probe client__connect(int, int);
+	/* client auth */
+	probe client__auth(int, string, pid_t, zoneid_t);
+	/* client id */
+	probe client__disconnect(int);
+	/* resource id, resource type, value, resource type name */
+	probe resource__alloc(uint32_t, uint32_t, uintptr_t, string);
+	/* resource id, resource type, value, resource type name */
+	probe resource__free(uint32_t, uint32_t, uintptr_t, string);
+};
diff -Nur -x CVS orig-6.8.2/xc/programs/Xserver/dix/Imakefile 6.8.2/xc/programs/Xserver/dix/Imakefile
--- orig-6.8.2/xc/programs/Xserver/dix/Imakefile	2004-12-17 09:44:34.064515000 -0800
+++ 6.8.2/xc/programs/Xserver/dix/Imakefile	2005-06-22 19:08:18.626532000 -0700
@@ -77,12 +77,20 @@
 #endif
 #endif
 
+#if BuildDTraceSupport
+XCOMM LIBDIR is path to find XErrorDB, which is still under /usr/openwin
+XCOMM on Solaris, even though Xorg is not.
+DTRACE_DEFINES = -DXSERVER_DTRACE -DLIBDIR=\"/usr/openwin/lib/X11\"
+#endif
+
+DEFINES = $(DTRACE_DEFINES)
+
 SITE_DEFINES = $(SITE_FONT_PATH) $(SITE_RGB_DB) $(SITE_DISPLAY_CLASS)
 
 VENDOR_DEFINES = $(VENDOR_STRING) $(VENDOR_RELEASE) $(QUARTZ_DEFINES)
 
 NormalLibraryObjectRule()
-NormalLibraryTarget(dix,$(OBJS))
+NormalRelocatableTarget(dix,$(OBJS))
 LintLibraryTarget(dix,$(SRCS) $(XPSRC))
 NormalLintTarget($(SRCS) $(XPSRC))
 
diff -Nur -x CVS orig-6.8.2/xc/programs/Xserver/dix/dispatch.c 6.8.2/xc/programs/Xserver/dix/dispatch.c
--- orig-6.8.2/xc/programs/Xserver/dix/dispatch.c	2004-12-17 09:44:34.182064000 -0800
+++ 6.8.2/xc/programs/Xserver/dix/dispatch.c	2005-06-22 19:02:26.205320000 -0700
@@ -76,6 +76,36 @@
 
 ******************************************************************/
 
+/* XSERVER_DTRACE additions:
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
+ * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * 
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
+
+
 /* $XFree86: xc/programs/Xserver/dix/dispatch.c,v 3.32 2003/11/10 18:21:45 tsi Exp $ */
 
 #ifdef PANORAMIX_DEBUG
@@ -119,6 +149,15 @@
 #include "lbxserve.h"
 #endif
 
+#ifdef XSERVER_DTRACE
+#include <sys/sdt.h>
+
+char *RequestNames[256];
+static void LoadRequestNames(void);
+static void FreeRequestNames(void);
+#define GetRequestName(i) (RequestNames[i])
+#endif
+
 #define mskcnt ((MAXCLIENTS + 31) / 32)
 #define BITMASK(i) (1U << ((i) & 31))
 #define MASKIDX(i) ((i) >> 5)
@@ -373,6 +412,10 @@
     if (!clientReady)
 	return;
 
+#ifdef XSERVER_DTRACE
+    LoadRequestNames();
+#endif
+
     while (!dispatchException)
     {
         if (*icheck[0] != *icheck[1])
@@ -449,11 +492,22 @@
 		client->requestLog[client->requestLogIndex] = MAJOROP;
 		client->requestLogIndex++;
 #endif
+#ifdef XSERVER_DTRACE
+		DTRACE_PROBE5(Xserver, request__start, GetRequestName(MAJOROP),
+			      MAJOROP,
+			      ((xReq *)client->requestBuffer)->length,
+			      client->index, client->requestBuffer);
+#endif	
 		if (result > (maxBigRequestSize << 2))
 		    result = BadLength;
 		else
 		    result = (* client->requestVector[MAJOROP])(client);
-	    
+#ifdef XSERVER_DTRACE
+		DTRACE_PROBE5(Xserver, request__done, GetRequestName(MAJOROP), 
+			      MAJOROP,
+			      ((xReq *)client->requestBuffer)->length, 
+			      client->index, /* client->sequence, */ result);
+#endif	    
 		if (result != Success) 
 		{
 		    if (client->noClientException != Success)
@@ -484,6 +538,9 @@
     KillAllClients();
     DEALLOCATE_LOCAL(clientReady);
     dispatchException &= ~DE_RESET;
+#ifdef XSERVER_DTRACE
+    FreeRequestNames();
+#endif
 }
 
 #undef MAJOROP
@@ -3667,6 +3724,9 @@
 	    CallCallbacks((&ClientStateCallback), (pointer)&clientinfo);
 	} 	    
 	FreeClientResources(client);
+#ifdef XSERVER_DTRACE
+	DTRACE_PROBE1(Xserver, client__disconnect, client->index);
+#endif	
 	if (client->index < nextFreeClientID)
 	    nextFreeClientID = client->index;
 	clients[client->index] = NullClient;
@@ -4114,3 +4174,60 @@
 {
     client->noClientException = -1;
 }
+
+#ifdef XSERVER_DTRACE
+#include <ctype.h>
+
+/* Load table of request names for dtrace probes */
+static void LoadRequestNames(void)
+{
+    int i;
+    FILE *xedb;
+    extern void LoadExtensionNames(char **RequestNames);
+
+    bzero(RequestNames, 256 * sizeof(char *));
+
+    xedb = fopen(LIBDIR "/XErrorDB", "r");
+    if (xedb != NULL) {
+	char buf[256];
+	while (fgets(buf, sizeof(buf), xedb)) {
+	    if ((strncmp("XRequest.", buf, 9) == 0) && (isdigit(buf[9]))) {
+		char *name;
+		i = strtol(buf + 9, &name, 10);
+		if (RequestNames[i] == 0) {
+		    char *end = strchr(name, '\n');
+		    if (end) { *end = '\0'; }
+		    RequestNames[i] = strdup(name + 1);
+		}
+	    }
+	}
+	fclose(xedb);
+    }
+
+    LoadExtensionNames(RequestNames);
+
+    for (i = 0; i < 256; i++) {
+	if (RequestNames[i] == 0) {
+#define RN_SIZE 12 /* "Request#' + up to 3 digits + \0 */
+	    RequestNames[i] = xalloc(RN_SIZE);
+	    if (RequestNames[i]) {
+		snprintf(RequestNames[i], RN_SIZE, "Request#%d", i);
+	    }
+	}
+	/* fprintf(stderr, "%d: %s\n", i, RequestNames[i]); */
+    }
+}
+
+static void FreeRequestNames(void)
+{
+    int i;
+
+    for (i = 0; i < 256; i++) {
+	if (RequestNames[i] != 0) {
+	    free(RequestNames[i]);
+	    RequestNames[i] = 0;
+	}
+    }
+}
+
+#endif
diff -Nur -x CVS orig-6.8.2/xc/programs/Xserver/dix/extension.c 6.8.2/xc/programs/Xserver/dix/extension.c
--- orig-6.8.2/xc/programs/Xserver/dix/extension.c	2004-04-23 12:04:44.000000000 -0700
+++ 6.8.2/xc/programs/Xserver/dix/extension.c	2005-06-22 18:49:47.306774000 -0700
@@ -484,3 +484,17 @@
     }
     return TRUE;
 }
+
+#ifdef XSERVER_DTRACE
+void LoadExtensionNames(char **RequestNames) {
+    int i;
+
+    for (i=0; i<NumExtensions; i++) {
+	int r = extensions[i]->base;
+
+	if (RequestNames[r] == NULL) {
+	    RequestNames[r] = strdup(extensions[i]->name);
+	}
+    }
+}
+#endif
diff -Nur -x CVS orig-6.8.2/xc/programs/Xserver/dix/resource.c 6.8.2/xc/programs/Xserver/dix/resource.c
--- orig-6.8.2/xc/programs/Xserver/dix/resource.c	2004-04-25 15:42:09.000000000 -0700
+++ 6.8.2/xc/programs/Xserver/dix/resource.c	2005-06-23 09:57:35.693290000 -0700
@@ -72,6 +72,34 @@
 Equipment Corporation.
 
 ******************************************************************/
+/* XSERVER_DTRACE additions:
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, and/or sell copies of the Software, and to permit persons
+ * to whom the Software is furnished to do so, provided that the above
+ * copyright notice(s) and this permission notice appear in all copies of
+ * the Software and that both the above copyright notice(s) and this
+ * permission notice appear in supporting documentation.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+ * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
+ * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ * 
+ * Except as contained in this notice, the name of a copyright holder
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * of the copyright holder.
+ */
 
 /* $Xorg: resource.c,v 1.5 2001/02/09 02:04:40 xorgcvs Exp $ */
 /* $XdotOrg: xc/programs/Xserver/dix/resource.c,v 1.3 2004/04/25 22:42:09 gisburn Exp $ */
@@ -121,6 +149,12 @@
 #endif
 #include <assert.h>
 
+#ifdef XSERVER_DTRACE
+#include <sys/sdt.h>
+
+#define TypeNameString(t) NameForAtom(ResourceNames[t & TypeMask])
+#endif
+
 static void RebuildTable(
     int /*client*/
 );
@@ -436,6 +470,10 @@
     register ClientResourceRec *rrec;
     register ResourcePtr res, *head;
     	
+#ifdef XSERVER_DTRACE
+    DTRACE_PROBE4(Xserver, resource__alloc,
+		  id, type, value, TypeNameString(type));
+#endif
     client = CLIENT_ID(id);
     rrec = &clientTable[client];
     if (!rrec->buckets)
@@ -538,6 +576,11 @@
 	    if (res->id == id)
 	    {
 		RESTYPE rtype = res->type;
+#ifdef XSERVER_DTRACE
+		DTRACE_PROBE4(Xserver, resource__free, res->id, res->type,
+			      res->value, TypeNameString(res->type));
+#endif		    
+
 		*prev = res->next;
 		elements = --*eltptr;
 		if (rtype & RC_CACHED)
@@ -582,6 +625,10 @@
 	{
 	    if (res->id == id && res->type == type)
 	    {
+#ifdef XSERVER_DTRACE
+		DTRACE_PROBE4(Xserver, resource__free, res->id, res->type,
+			      res->value, TypeNameString(res->type));
+#endif		    		    
 		*prev = res->next;
 		if (type & RC_CACHED)
 		    FlushClientCaches(res->id);
@@ -747,6 +794,10 @@
 	    RESTYPE rtype = this->type;
 	    if (rtype & RC_NEVERRETAIN)
 	    {
+#ifdef XSERVER_DTRACE
+		DTRACE_PROBE4(Xserver, resource__free, this->id, this->type,
+			      this->value, TypeNameString(this->type));
+#endif		    
 		*prev = this->next;
 		if (rtype & RC_CACHED)
 		    FlushClientCaches(this->id);
@@ -794,6 +845,10 @@
         for (this = *head; this; this = *head)
 	{
 	    RESTYPE rtype = this->type;
+#ifdef XSERVER_DTRACE
+	    DTRACE_PROBE4(Xserver, resource__free, this->id, this->type,
+			  this->value, TypeNameString(this->type));
+#endif		    
 	    *head = this->next;
 	    if (rtype & RC_CACHED)
 		FlushClientCaches(this->id);
diff -Nur -x CVS orig-6.8.2/xc/programs/Xserver/os/Imakefile 6.8.2/xc/programs/Xserver/os/Imakefile
--- orig-6.8.2/xc/programs/Xserver/os/Imakefile	2004-08-27 15:47:46.000000000 -0700
+++ 6.8.2/xc/programs/Xserver/os/Imakefile	2005-06-22 19:22:27.492216000 -0700
@@ -130,10 +130,16 @@
 #if HasPam && HasPamMisc
     PAM_DEFINES = -DUSE_PAM
 #endif
+
+#if BuildDTraceSupport
+ DTRACE_DEFINES = -DXSERVER_DTRACE
+#endif
+
         DEFINES = -DXSERV_t -DTRANS_SERVER $(CONNECTION_FLAGS) $(MEM_DEFINES) \
 		  $(XDMAUTHDEFS) $(RPCDEFS) $(SIGNAL_DEFINES) $(OS_DEFINES) \
 		  $(KRB5_DEFINES) $(RGB_DEFINES) $(GETPEER_DEFINES) \
-		  $(RANDOM_DEFINES) $(BUGMSG) $(XTRANS_FAILDEFINES)
+		  $(RANDOM_DEFINES) $(BUGMSG) $(XTRANS_FAILDEFINES) \
+		  $(DTRACE_DEFINES)
        INCLUDES = -I. -I../include -I$(XINCLUDESRC) -I$(EXTINCSRC) \
 		  -I$(SERVERSRC)/Xext -I$(FONTINCSRC) -I$(SERVERSRC)/render \
 		  -I$(TOP)/lib/Xau -I../lbx Krb5Includes
@@ -147,7 +153,7 @@
 #endif /* NEED_ALLOCA_FROM_LIBPW */
 
 NormalLibraryObjectRule()
-NormalLibraryTarget(os,$(OBJS))
+NormalRelocatableTarget(os,$(OBJS))
 LintLibraryTarget(os,$(SRCS))
 NormalLintTarget($(SRCS))
 
diff -Nur -x CVS orig-6.8.2/xc/programs/Xserver/os/connection.c 6.8.2/xc/programs/Xserver/os/connection.c
--- orig-6.8.2/xc/programs/Xserver/os/connection.c	2004-04-23 12:54:28.000000000 -0700
+++ 6.8.2/xc/programs/Xserver/os/connection.c	2005-06-22 19:21:11.481384000 -0700
@@ -170,6 +170,15 @@
 #include <netdnet/dn.h>
 #endif /* DNETCONN */
 
+#ifdef XSERVER_DTRACE
+# include <sys/sdt.h>
+# include <ucred.h>
+#endif
+
+#ifdef SUNSOFT
+extern void DtloginInit(void);
+#endif /* SUNSOFT */
+
 int lastfdesc;			/* maximum file descriptor */
 
 fd_set WellKnownConnections;	/* Listener mask */
@@ -392,6 +401,11 @@
      */
     ParentProcess = GetPPID (ParentProcess);
 #endif /* __UNIXOS2__ */
+#ifdef SUNSOFT
+    /* Create pipe for dtlogin authentication info before we tell dtlogin 
+       we're done and ready for it to run. */
+    DtloginInit ();
+#endif
     if (RunFromSmartParent) {
 	if (ParentProcess > 1) {
 	    kill (ParentProcess, SIGUSR1);
@@ -530,6 +544,10 @@
 	default:
 	    strcpy(out, "unknown address");
 	}
+
+#ifdef XSERVER_DTRACE
+  if (auditTrailLevel > 1) {
+#endif
     
     if (proto_n)
 	AuditF("client %d %s from %s\n  Auth name: %.*s ID: %d\n", 
@@ -538,6 +556,23 @@
     else 
 	AuditF("client %d %s from %s\n", 
 	       client->index, letin ? "connected" : "rejected", addr);
+#ifdef XSERVER_DTRACE
+  }
+  {
+      ucred_t *peercred = NULL;
+      pid_t pid = -1;
+      zoneid_t zid = -1;
+      
+      if (getpeerucred(((OsCommPtr)client->osPrivate)->fd, &peercred) >= 0) {
+	  pid = ucred_getpid(peercred);
+	  zid = ucred_getzoneid(peercred);
+	  ucred_free(peercred);
+      }
+    
+      DTRACE_PROBE4(Xserver, client__auth, client->index, addr, pid, zid);
+  }
+#endif	
+
 }
 
 XID
@@ -667,7 +702,9 @@
 	    else
 	    {
 		auth_id = (XID) 0;
+#ifndef XSERVER_DTRACE
 		if (auditTrailLevel > 1)
+#endif
 		    AuthAudit(client, TRUE,
 			(struct sockaddr *) from, fromlen,
 			proto_n, auth_proto, auth_id);
@@ -691,7 +728,11 @@
 		return "Client is not authorized to connect to Server";
 	}
     }
+#ifdef XSERVER_DTRACE
+    else
+#else
     else if (auditTrailLevel > 1)
+#endif
     {
 	if (_XSERVTransGetPeerAddr (trans_conn,
 	    &family, &fromlen, &from) != -1)
@@ -795,6 +836,9 @@
     ErrorF("AllocNewConnection: client index = %d, socket fd = %d\n",
 	   client->index, fd);
 #endif
+#ifdef XSERVER_DTRACE
+    DTRACE_PROBE2(Xserver, client__connect, client->index, fd);
+#endif	
 
     return client;
 }
