shm.patch revision 1276
943N/A# Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
366N/A#
366N/A# Permission is hereby granted, free of charge, to any person obtaining a
919N/A# copy of this software and associated documentation files (the "Software"),
919N/A# to deal in the Software without restriction, including without limitation
919N/A# the rights to use, copy, modify, merge, publish, distribute, sublicense,
919N/A# and/or sell copies of the Software, and to permit persons to whom the
919N/A# Software is furnished to do so, subject to the following conditions:
919N/A#
919N/A# The above copyright notice and this permission notice (including the next
919N/A# paragraph) shall be included in all copies or substantial portions of the
919N/A# Software.
919N/A#
919N/A# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
919N/A# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
919N/A# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
919N/A# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
919N/A# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
919N/A# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
919N/A# DEALINGS IN THE SOFTWARE.
366N/A#
366N/A
1276N/Adiff --git a/src/XShm.c b/src/XShm.c
1276N/Aindex f82455c..d21f380 100644
1276N/A--- a/src/XShm.c
1276N/A+++ b/src/XShm.c
1276N/A@@ -38,6 +38,13 @@ in this Software without prior written authorization from The Open Group.
366N/A #include <X11/extensions/Xext.h>
366N/A #include <X11/extensions/extutil.h>
366N/A
366N/A+#ifdef SUNSOFT
366N/A+#include <fcntl.h>
366N/A+#include <sys/types.h>
366N/A+#include <sys/stat.h>
366N/A+#include <ucred.h>
366N/A+#endif
366N/A+
366N/A static XExtensionInfo _shm_info_data;
366N/A static XExtensionInfo *shm_info = &_shm_info_data;
1276N/A static const char *shm_extension_name = SHMNAME;
1276N/A@@ -135,6 +142,46 @@ event_to_wire (Display *dpy, XEvent *re, xEvent *event)
366N/A return False;
366N/A }
366N/A
366N/A+#ifdef SUNSOFT
366N/A+/*
366N/A+ * Function to determine if a connection is local or not.
366N/A+ * Returns: 0 for remote, 1 for local
366N/A+ */
366N/A+
366N/A+static int
366N/A+LocalConnection(Display *dpy)
366N/A+{
366N/A+ int c = ConnectionNumber(dpy);
366N/A+ int rv = 0;
366N/A+ struct stat statbuf;
366N/A+ ucred_t *ucred = NULL;
366N/A+
366N/A+ if (c >= 0) {
366N/A+ /*
366N/A+ * First stat the connection fd. If we succeed and the type of file
366N/A+ * is a FIFO, then we must be local.
366N/A+ */
366N/A+ if ((fstat(c, &statbuf) >= 0) && S_ISFIFO(statbuf.st_mode)) {
366N/A+ return 1;
366N/A+ }
366N/A+
366N/A+ /*
366N/A+ * Then call getpeerucred - if it succeeds, the other end of the
366N/A+ * connection must be on the same machine (though possibly in a
366N/A+ * different zone).
366N/A+ */
366N/A+ if (getpeerucred(c, &ucred) == 0) {
366N/A+ if (ucred_getzoneid(ucred) != -1) {
366N/A+ rv = 1;
366N/A+ }
366N/A+ ucred_free(ucred);
366N/A+ }
366N/A+ }
366N/A+
366N/A+ return rv;
366N/A+}
366N/A+#endif /* SUNSOFT */
366N/A+
366N/A /*****************************************************************************
366N/A * *
366N/A * public Shared Memory Extension routines *
1276N/A@@ -144,6 +191,15 @@ event_to_wire (Display *dpy, XEvent *re, xEvent *event)
366N/A Bool XShmQueryExtension (Display *dpy /* int *event_basep, *error_basep */)
366N/A {
366N/A XExtDisplayInfo *info = find_display (dpy);
366N/A+#ifdef SUNSOFT
366N/A+ /*
366N/A+ * Sun Mod -- if we're dealing with a remote connection, then the
366N/A+ * shared memory extension is not valid. Sigh -- this should really
366N/A+ * be in the server somewhere... Required for pipe transport PIPECONN
366N/A+ */
366N/A+ if(!LocalConnection(dpy))
366N/A+ return False;
366N/A+#endif /* SUNSOFT */
366N/A
366N/A if (XextHasExtension(info)) {
366N/A /* *event_basep = info->codes->first_event;
1072N/A@@ -176,6 +232,15 @@ Bool XShmQueryVersion(
366N/A XExtDisplayInfo *info = find_display (dpy);
366N/A xShmQueryVersionReply rep;
366N/A register xShmQueryVersionReq *req;
366N/A+#ifdef SUNSOFT
366N/A+ /*
366N/A+ * Sun Mod -- if we're dealing with a remote connection, then the
366N/A+ * shared memory extension is not valid. Sigh -- this should really
366N/A+ * be in the server somewhere...
366N/A+ */
366N/A+ if(!LocalConnection(dpy))
366N/A+ return False;
366N/A+#endif /* SUNSOFT */
366N/A
366N/A ShmCheckExtension (dpy, info, False);
366N/A