open-src/lib/libXext/shm.patch
author X gate hg captive account <xhg@xserver.sfbay.sun.com>
Fri, 23 Sep 2011 15:47:54 -0700
changeset 1216 3838ec082c2e
parent 1072 88d1d779286d
permissions -rw-r--r--
Added tag nv_175a for changeset 924b7feb31b8

# Copyright (c) 2008, 2009, Oracle and/or its affiliates. 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, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice (including the next
# paragraph) shall be included in all copies or substantial portions of the
# Software.
#
# 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.  IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#

diff -urp -x '*~' -x '*.orig' src/XShm.c src/XShm.c
--- src/XShm.c	2010-10-06 21:11:53.000000000 -0700
+++ src/XShm.c	2011-01-14 07:43:31.157693442 -0800
@@ -38,6 +38,13 @@ in this Software without prior written a
 #include <X11/extensions/Xext.h>
 #include <X11/extensions/extutil.h>
 
+#ifdef SUNSOFT
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <ucred.h>
+#endif
+
 static XExtensionInfo _shm_info_data;
 static XExtensionInfo *shm_info = &_shm_info_data;
 static /* const */ char *shm_extension_name = SHMNAME;
@@ -135,6 +142,46 @@ event_to_wire (Display *dpy, XEvent *re,
     return False;
 }
 
+#ifdef SUNSOFT
+/*
+ * Function to determine if a connection is local or not.
+ * Returns: 0 for remote, 1 for local
+ */
+
+static int
+LocalConnection(Display *dpy)
+{
+    int c = ConnectionNumber(dpy);
+    int rv = 0;
+    struct stat statbuf;
+    ucred_t *ucred = NULL;
+
+    if (c >= 0) {
+	/*
+	 * First stat the connection fd.  If we succeed and the type of file
+	 * is a FIFO, then we must be local.
+	 */
+	if ((fstat(c, &statbuf) >= 0) && S_ISFIFO(statbuf.st_mode)) {
+	    return 1;
+	}
+
+	/*
+	 * Then call getpeerucred - if it succeeds, the other end of the
+	 * connection must be on the same machine (though possibly in a
+	 * different zone).
+	 */
+	if (getpeerucred(c, &ucred) == 0) {
+	    if (ucred_getzoneid(ucred) != -1) {
+		rv = 1;
+	    }
+	    ucred_free(ucred);
+	}
+    }
+
+    return rv;
+}
+#endif /* SUNSOFT */
+
 /*****************************************************************************
  *                                                                           *
  *		    public Shared Memory Extension routines                  *
@@ -144,6 +191,15 @@ event_to_wire (Display *dpy, XEvent *re,
 Bool XShmQueryExtension (Display *dpy /*  int *event_basep, *error_basep */)
 {
     XExtDisplayInfo *info = find_display (dpy);
+#ifdef SUNSOFT
+    /*
+     * Sun Mod -- if we're dealing with a remote connection, then the 
+     * shared memory extension is not valid. Sigh -- this should really
+     * be in the server somewhere... Required for pipe transport PIPECONN
+     */
+    if(!LocalConnection(dpy))
+	return False;
+#endif /* SUNSOFT */
 
     if (XextHasExtension(info)) {
 /*	*event_basep = info->codes->first_event;
@@ -176,6 +232,15 @@ Bool XShmQueryVersion(
     XExtDisplayInfo *info = find_display (dpy);
     xShmQueryVersionReply rep;
     register xShmQueryVersionReq *req;
+#ifdef SUNSOFT
+    /*
+     * Sun Mod -- if we're dealing with a remote connection, then the
+     * shared memory extension is not valid. Sigh -- this should really
+     * be in the server somewhere...
+     */  
+    if(!LocalConnection(dpy))
+        return False;
+#endif /* SUNSOFT */
 
     ShmCheckExtension (dpy, info, False);