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