shm.patch revision 851
352N/A# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
352N/A# Use is subject to license terms.
352N/A#
352N/A# Permission is hereby granted, free of charge, to any person obtaining a
352N/A# copy of this software and associated documentation files (the
352N/A# "Software"), to deal in the Software without restriction, including
352N/A# without limitation the rights to use, copy, modify, merge, publish,
352N/A# distribute, and/or sell copies of the Software, and to permit persons
352N/A# to whom the Software is furnished to do so, provided that the above
352N/A# copyright notice(s) and this permission notice appear in all copies of
352N/A# the Software and that both the above copyright notice(s) and this
352N/A# permission notice appear in supporting documentation.
352N/A#
352N/A# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
352N/A# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
352N/A# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
352N/A# OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
352N/A# HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
352N/A# INDIRECT OR CONSEQUENTIAL EXTS, OR ANY EXTS WHATSOEVER RESULTING
352N/A# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
352N/A# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
352N/A# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
352N/A#
352N/A# Except as contained in this notice, the name of a copyright holder
352N/A# shall not be used in advertising or otherwise to promote the sale, use
560N/A# or other dealings in this Software without prior written authorization
560N/A# of the copyright holder.
352N/A#
560N/A
560N/Adiff -urp -x '*~' -x '*.orig' src/XShm.c src/XShm.c
480N/A--- src/XShm.c 2009-10-16 14:26:30.000000000 -0700
480N/A+++ src/XShm.c 2009-11-02 15:45:20.940394110 -0800
352N/A@@ -43,6 +43,13 @@ in this Software without prior written a
352N/A #include <X11/extensions/Xext.h>
352N/A #include <X11/extensions/extutil.h>
352N/A
352N/A+#ifdef SUNSOFT
560N/A+#include <fcntl.h>
560N/A+#include <sys/types.h>
480N/A+#include <sys/stat.h>
352N/A+#include <ucred.h>
480N/A+#endif
592N/A+
665N/A static XExtensionInfo _shm_info_data;
665N/A static XExtensionInfo *shm_info = &_shm_info_data;
876N/A static /* const */ char *shm_extension_name = SHMNAME;
560N/A@@ -140,6 +147,46 @@ event_to_wire (Display *dpy, XEvent *re,
377N/A return False;
480N/A }
352N/A
352N/A+#ifdef SUNSOFT
352N/A+/*
352N/A+ * Function to determine if a connection is local or not.
352N/A+ * Returns: 0 for remote, 1 for local
352N/A+ */
377N/A+
352N/A+static int
352N/A+LocalConnection(Display *dpy)
352N/A+{
352N/A+ int c = ConnectionNumber(dpy);
352N/A+ int rv = 0;
352N/A+ struct stat statbuf;
861N/A+ ucred_t *ucred = NULL;
861N/A+
352N/A+ if (c >= 0) {
352N/A+ /*
352N/A+ * First stat the connection fd. If we succeed and the type of file
352N/A+ * is a FIFO, then we must be local.
352N/A+ */
352N/A+ if ((fstat(c, &statbuf) >= 0) && S_ISFIFO(statbuf.st_mode)) {
352N/A+ return 1;
367N/A+ }
377N/A+
377N/A+ /*
352N/A+ * Then call getpeerucred - if it succeeds, the other end of the
352N/A+ * connection must be on the same machine (though possibly in a
352N/A+ * different zone).
352N/A+ */
377N/A+ if (getpeerucred(c, &ucred) == 0) {
352N/A+ if (ucred_getzoneid(ucred) != -1) {
352N/A+ rv = 1;
352N/A+ }
352N/A+ ucred_free(ucred);
352N/A+ }
352N/A+ }
352N/A+
365N/A+ return rv;
352N/A+}
352N/A+#endif /* SUNSOFT */
352N/A+
489N/A /*****************************************************************************
377N/A * *
352N/A * public Shared Memory Extension routines *
352N/A@@ -149,6 +196,15 @@ event_to_wire (Display *dpy, XEvent *re,
352N/A Bool XShmQueryExtension (Display *dpy /* int *event_basep, *error_basep */)
352N/A {
352N/A XExtDisplayInfo *info = find_display (dpy);
352N/A+#ifdef SUNSOFT
352N/A+ /*
352N/A+ * Sun Mod -- if we're dealing with a remote connection, then the
365N/A+ * shared memory extension is not valid. Sigh -- this should really
365N/A+ * be in the server somewhere... Required for pipe transport PIPECONN
365N/A+ */
365N/A+ if(!LocalConnection(dpy))
365N/A+ return False;
365N/A+#endif /* SUNSOFT */
365N/A
365N/A if (XextHasExtension(info)) {
365N/A /* *event_basep = info->codes->first_event;
489N/A@@ -181,6 +237,15 @@ Bool XShmQueryVersion(
365N/A XExtDisplayInfo *info = find_display (dpy);
365N/A xShmQueryVersionReply rep;
365N/A register xShmQueryVersionReq *req;
365N/A+#ifdef SUNSOFT
365N/A+ /*
480N/A+ * Sun Mod -- if we're dealing with a remote connection, then the
480N/A+ * shared memory extension is not valid. Sigh -- this should really
480N/A+ * be in the server somewhere...
480N/A+ */
480N/A+ if(!LocalConnection(dpy))
480N/A+ return False;
480N/A+#endif /* SUNSOFT */
480N/A
480N/A ShmCheckExtension (dpy, info, False);
480N/A
480N/A