2003-11-14 16:54:54 +01:00
|
|
|
/***********************************************************
|
|
|
|
|
|
|
|
Copyright 1987, 1989, 1998 The Open Group
|
|
|
|
|
|
|
|
Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
the above copyright notice appear in all copies and that both that
|
|
|
|
copyright notice and this permission notice appear in supporting
|
|
|
|
documentation.
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice 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
|
|
|
|
OPEN GROUP 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.
|
|
|
|
|
|
|
|
Except as contained in this notice, the name of The Open Group shall not be
|
|
|
|
used in advertising or otherwise to promote the sale, use or other dealings
|
|
|
|
in this Software without prior written authorization from The Open Group.
|
|
|
|
|
|
|
|
Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
|
|
|
|
|
|
|
|
All Rights Reserved
|
|
|
|
|
2014-10-31 00:45:12 +01:00
|
|
|
Permission to use, copy, modify, and distribute this software and its
|
|
|
|
documentation for any purpose and without fee is hereby granted,
|
2003-11-14 16:54:54 +01:00
|
|
|
provided that the above copyright notice appear in all copies and that
|
2014-10-31 00:45:12 +01:00
|
|
|
both that copyright notice and this permission notice appear in
|
2003-11-14 16:54:54 +01:00
|
|
|
supporting documentation, and that the name of Digital not be
|
|
|
|
used in advertising or publicity pertaining to distribution of the
|
2014-10-31 00:45:12 +01:00
|
|
|
software without specific, written prior permission.
|
2003-11-14 16:54:54 +01:00
|
|
|
|
|
|
|
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
|
|
|
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
|
|
|
DIGITAL BE LIABLE FOR 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.
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
/*****************************************************************
|
|
|
|
* Stuff to create connections --- OS dependent
|
|
|
|
*
|
|
|
|
* EstablishNewConnections, CreateWellKnownSockets, ResetWellKnownSockets,
|
|
|
|
* CloseDownConnection, CheckConnections, AddEnabledDevice,
|
|
|
|
* RemoveEnabledDevice, OnlyListToOneClient,
|
|
|
|
* ListenToAllClients,
|
|
|
|
*
|
|
|
|
* (WaitForSomething is in its own file)
|
|
|
|
*
|
|
|
|
* In this implementation, a client socket table is not kept.
|
|
|
|
* Instead, what would be the index into the table is just the
|
|
|
|
* file descriptor of the socket. This won't work for if the
|
|
|
|
* socket ids aren't small nums (0 - 2^8)
|
|
|
|
*
|
|
|
|
*****************************************************************/
|
|
|
|
|
2005-07-03 09:02:09 +02:00
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <X11/Xwinsock.h>
|
|
|
|
#endif
|
2005-04-20 14:25:48 +02:00
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xproto.h>
|
2005-07-03 09:02:09 +02:00
|
|
|
#define XSERV_t
|
|
|
|
#define TRANS_SERVER
|
|
|
|
#define TRANS_REOPEN
|
2005-04-20 14:25:48 +02:00
|
|
|
#include <X11/Xtrans/Xtrans.h>
|
2007-09-06 05:33:43 +02:00
|
|
|
#include <X11/Xtrans/Xtransint.h>
|
2003-11-14 16:54:54 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
2003-11-25 20:29:01 +01:00
|
|
|
#include <stdlib.h>
|
2003-11-14 16:54:54 +01:00
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
2016-02-08 23:36:03 +01:00
|
|
|
#if defined(TCPCONN)
|
2012-03-21 20:55:09 +01:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#ifdef apollo
|
|
|
|
#ifndef NO_TCP_H
|
|
|
|
#include <netinet/tcp.h>
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#ifdef CSRG_BASED
|
|
|
|
#include <sys/param.h>
|
|
|
|
#endif
|
|
|
|
#include <netinet/tcp.h>
|
|
|
|
#endif
|
|
|
|
#include <arpa/inet.h>
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/uio.h>
|
2008-07-17 17:59:24 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
#endif /* WIN32 */
|
|
|
|
#include "misc.h" /* for typedef of pointer */
|
2003-11-14 16:54:54 +01:00
|
|
|
#include "osdep.h"
|
2003-11-14 17:49:22 +01:00
|
|
|
#include <X11/Xpoll.h>
|
2003-11-14 16:54:54 +01:00
|
|
|
#include "opaque.h"
|
|
|
|
#include "dixstruct.h"
|
2004-05-05 22:04:52 +02:00
|
|
|
#include "xace.h"
|
2003-11-14 16:54:54 +01:00
|
|
|
|
|
|
|
#define Pid_t pid_t
|
|
|
|
|
2011-12-01 07:20:09 +01:00
|
|
|
#ifdef HAVE_GETPEERUCRED
|
2012-03-21 20:55:09 +01:00
|
|
|
#include <ucred.h>
|
|
|
|
#include <zone.h>
|
2014-12-10 03:27:11 +01:00
|
|
|
#else
|
2012-03-21 20:55:09 +01:00
|
|
|
#define zoneid_t int
|
|
|
|
#endif
|
2014-12-10 03:27:11 +01:00
|
|
|
|
|
|
|
#include "probes.h"
|
2006-11-03 21:54:43 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
static int lastfdesc; /* maximum file descriptor */
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
fd_set EnabledDevices; /* mask for input devices that are on */
|
2015-11-12 07:02:02 +01:00
|
|
|
fd_set NotifyReadFds; /* mask for other file descriptors */
|
2015-11-12 07:02:03 +01:00
|
|
|
fd_set NotifyWriteFds; /* mask for other write file descriptors */
|
2012-03-21 20:55:09 +01:00
|
|
|
fd_set AllSockets; /* select on this */
|
|
|
|
fd_set AllClients; /* available clients */
|
|
|
|
fd_set LastSelectMask; /* mask returned from last select call */
|
2015-11-12 07:02:03 +01:00
|
|
|
fd_set LastSelectWriteMask; /* mask returned from last select call */
|
2012-03-21 20:55:09 +01:00
|
|
|
fd_set ClientsWithInput; /* clients with FULL requests in buffer */
|
|
|
|
fd_set ClientsWriteBlocked; /* clients who cannot receive output */
|
|
|
|
fd_set OutputPending; /* clients with reply/event data ready to go */
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
int MaxClients = 0;
|
2015-11-12 07:02:03 +01:00
|
|
|
int NumNotifyWriteFd; /* Number of NotifyFd members with write set */
|
2012-03-21 20:55:09 +01:00
|
|
|
Bool NewOutputPending; /* not yet attempted to write some new output */
|
2015-11-12 07:02:03 +01:00
|
|
|
Bool AnyWritesPending; /* true if some client blocked on write or NotifyFd with write */
|
2014-03-19 22:03:13 +01:00
|
|
|
Bool NoListenAll; /* Don't establish any listening sockets */
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
static Bool RunFromSmartParent; /* send SIGUSR1 to parent process */
|
|
|
|
Bool RunFromSigStopParent; /* send SIGSTOP to our own process; Upstart (or
|
|
|
|
equivalent) will send SIGCONT back. */
|
2012-04-05 00:29:42 +02:00
|
|
|
static char dynamic_display[7]; /* display name */
|
2012-03-21 20:55:09 +01:00
|
|
|
Bool PartialNetwork; /* continue even if unable to bind all addrs */
|
2003-11-14 16:54:54 +01:00
|
|
|
static Pid_t ParentProcess;
|
|
|
|
|
|
|
|
static Bool debug_conns = FALSE;
|
|
|
|
|
|
|
|
fd_set IgnoredClientsWithInput;
|
|
|
|
static fd_set GrabImperviousClients;
|
|
|
|
static fd_set SavedAllClients;
|
|
|
|
static fd_set SavedAllSockets;
|
|
|
|
static fd_set SavedClientsWithInput;
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
int GrabInProgress = 0;
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2015-11-12 07:02:17 +01:00
|
|
|
static void
|
|
|
|
QueueNewConnections(int curconn, int ready, void *data);
|
|
|
|
|
2004-11-22 14:23:25 +01:00
|
|
|
#if !defined(WIN32)
|
2003-11-14 17:49:22 +01:00
|
|
|
int *ConnectionTranslation = NULL;
|
2004-11-22 14:23:25 +01:00
|
|
|
#else
|
|
|
|
/*
|
2003-11-14 16:54:54 +01:00
|
|
|
* On NT fds are not between 0 and MAXSOCKS, they are unrelated, and there is
|
|
|
|
* not even a known maximum value, so use something quite arbitrary for now.
|
2004-11-22 14:23:25 +01:00
|
|
|
* Do storage is a hash table of size 256. Collisions are handled in a linked
|
|
|
|
* list.
|
2003-11-14 16:54:54 +01:00
|
|
|
*/
|
2004-11-22 14:23:25 +01:00
|
|
|
|
2004-11-15 16:06:51 +01:00
|
|
|
#undef MAXSOCKS
|
2015-07-07 18:19:50 +02:00
|
|
|
#define MAXSOCKS 512
|
2004-11-15 16:06:51 +01:00
|
|
|
#undef MAXSELECT
|
2015-07-07 18:19:50 +02:00
|
|
|
#define MAXSELECT 512
|
2004-11-22 14:23:25 +01:00
|
|
|
|
|
|
|
struct _ct_node {
|
|
|
|
struct _ct_node *next;
|
|
|
|
int key;
|
|
|
|
int value;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _ct_node *ct_head[256];
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
void
|
|
|
|
InitConnectionTranslation(void)
|
2004-11-22 14:23:25 +01:00
|
|
|
{
|
2010-06-04 10:35:31 +02:00
|
|
|
memset(ct_head, 0, sizeof(ct_head));
|
2004-11-22 14:23:25 +01:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
int
|
|
|
|
GetConnectionTranslation(int conn)
|
2004-11-22 14:23:25 +01:00
|
|
|
{
|
|
|
|
struct _ct_node *node = ct_head[conn & 0xff];
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
while (node != NULL) {
|
2004-11-22 14:23:25 +01:00
|
|
|
if (node->key == conn)
|
|
|
|
return node->value;
|
|
|
|
node = node->next;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
void
|
|
|
|
SetConnectionTranslation(int conn, int client)
|
2004-11-22 14:23:25 +01:00
|
|
|
{
|
|
|
|
struct _ct_node **node = ct_head + (conn & 0xff);
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
if (client == 0) { /* remove entry */
|
|
|
|
while (*node != NULL) {
|
|
|
|
if ((*node)->key == conn) {
|
2004-11-22 14:23:25 +01:00
|
|
|
struct _ct_node *temp = *node;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2004-11-22 14:23:25 +01:00
|
|
|
*node = (*node)->next;
|
|
|
|
free(temp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
node = &((*node)->next);
|
|
|
|
}
|
|
|
|
return;
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
while (*node != NULL) {
|
|
|
|
if ((*node)->key == conn) {
|
2004-11-22 14:23:25 +01:00
|
|
|
(*node)->value = client;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
node = &((*node)->next);
|
|
|
|
}
|
2010-05-05 20:44:06 +02:00
|
|
|
*node = malloc(sizeof(struct _ct_node));
|
2004-11-22 14:23:25 +01:00
|
|
|
(*node)->next = NULL;
|
|
|
|
(*node)->key = conn;
|
|
|
|
(*node)->value = client;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
void
|
|
|
|
ClearConnectionTranslation(void)
|
2004-11-22 14:23:25 +01:00
|
|
|
{
|
|
|
|
unsigned i;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
for (i = 0; i < 256; i++) {
|
2004-11-22 14:23:25 +01:00
|
|
|
struct _ct_node *node = ct_head[i];
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
while (node != NULL) {
|
2004-11-22 14:23:25 +01:00
|
|
|
struct _ct_node *temp = node;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2004-11-22 14:23:25 +01:00
|
|
|
node = node->next;
|
2010-05-05 20:44:06 +02:00
|
|
|
free(temp);
|
2004-11-22 14:23:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
static XtransConnInfo *ListenTransConns = NULL;
|
|
|
|
static int *ListenTransFds = NULL;
|
|
|
|
static int ListenTransCount;
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
static void ErrorConnMax(XtransConnInfo /* trans_conn */ );
|
2003-11-14 16:54:54 +01:00
|
|
|
|
|
|
|
static XtransConnInfo
|
2012-03-21 20:55:09 +01:00
|
|
|
lookup_trans_conn(int fd)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
if (ListenTransFds) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ListenTransCount; i++)
|
|
|
|
if (ListenTransFds[i] == fd)
|
|
|
|
return ListenTransConns[i];
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
2010-06-06 16:18:40 +02:00
|
|
|
return NULL;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
2003-11-14 17:49:22 +01:00
|
|
|
/* Set MaxClients and lastfdesc, and allocate ConnectionTranslation */
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2003-11-25 20:29:01 +01:00
|
|
|
InitConnectionLimits(void)
|
2003-11-14 17:49:22 +01:00
|
|
|
{
|
|
|
|
lastfdesc = -1;
|
|
|
|
|
|
|
|
#ifndef __CYGWIN__
|
|
|
|
|
|
|
|
#if !defined(XNO_SYSCONF) && defined(_SC_OPEN_MAX)
|
|
|
|
lastfdesc = sysconf(_SC_OPEN_MAX) - 1;
|
|
|
|
#endif
|
|
|
|
|
2011-12-01 07:20:09 +01:00
|
|
|
#ifdef HAVE_GETDTABLESIZE
|
2003-11-14 17:49:22 +01:00
|
|
|
if (lastfdesc < 0)
|
2012-03-21 20:55:09 +01:00
|
|
|
lastfdesc = getdtablesize() - 1;
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif
|
|
|
|
|
2003-11-14 17:49:22 +01:00
|
|
|
#ifdef _NFILE
|
|
|
|
if (lastfdesc < 0)
|
2012-03-21 20:55:09 +01:00
|
|
|
lastfdesc = _NFILE - 1;
|
2003-11-14 17:49:22 +01:00
|
|
|
#endif
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
#endif /* __CYGWIN__ */
|
2003-11-14 17:49:22 +01:00
|
|
|
|
|
|
|
/* This is the fallback */
|
|
|
|
if (lastfdesc < 0)
|
2012-03-21 20:55:09 +01:00
|
|
|
lastfdesc = MAXSOCKS;
|
2003-11-14 17:49:22 +01:00
|
|
|
|
|
|
|
if (lastfdesc > MAXSELECT)
|
2012-03-21 20:55:09 +01:00
|
|
|
lastfdesc = MAXSELECT;
|
2003-11-14 17:49:22 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
if (lastfdesc > MAXCLIENTS) {
|
|
|
|
lastfdesc = MAXCLIENTS;
|
|
|
|
if (debug_conns)
|
2015-07-07 18:19:50 +02:00
|
|
|
ErrorF("REACHED MAXIMUM CLIENTS LIMIT %d\n", LimitClients);
|
2003-11-14 17:49:22 +01:00
|
|
|
}
|
|
|
|
MaxClients = lastfdesc;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
ErrorF("InitConnectionLimits: MaxClients = %d\n", MaxClients);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(WIN32)
|
2007-12-28 14:48:25 +01:00
|
|
|
if (!ConnectionTranslation)
|
2015-03-21 18:08:25 +01:00
|
|
|
ConnectionTranslation = xnfallocarray(lastfdesc + 1, sizeof(int));
|
2003-11-14 17:49:22 +01:00
|
|
|
#else
|
2004-11-22 14:23:25 +01:00
|
|
|
InitConnectionTranslation();
|
2003-11-14 17:49:22 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-11-01 20:41:11 +01:00
|
|
|
/*
|
|
|
|
* If SIGUSR1 was set to SIG_IGN when the server started, assume that either
|
|
|
|
*
|
|
|
|
* a- The parent process is ignoring SIGUSR1
|
|
|
|
*
|
|
|
|
* or
|
|
|
|
*
|
|
|
|
* b- The parent process is expecting a SIGUSR1
|
|
|
|
* when the server is ready to accept connections
|
|
|
|
*
|
|
|
|
* In the first case, the signal will be harmless, in the second case,
|
|
|
|
* the signal will be quite useful.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
InitParentProcess(void)
|
|
|
|
{
|
|
|
|
#if !defined(WIN32)
|
|
|
|
OsSigHandlerPtr handler;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
handler = OsSignal(SIGUSR1, SIG_IGN);
|
|
|
|
if (handler == SIG_IGN)
|
|
|
|
RunFromSmartParent = TRUE;
|
2007-11-01 20:41:11 +01:00
|
|
|
OsSignal(SIGUSR1, handler);
|
2012-03-21 20:55:09 +01:00
|
|
|
ParentProcess = getppid();
|
2007-11-01 20:41:11 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2007-11-01 20:41:11 +01:00
|
|
|
NotifyParentProcess(void)
|
|
|
|
{
|
|
|
|
#if !defined(WIN32)
|
2013-03-11 15:34:32 +01:00
|
|
|
if (displayfd >= 0) {
|
2014-04-19 00:00:30 +02:00
|
|
|
if (write(displayfd, display, strlen(display)) != strlen(display))
|
|
|
|
FatalError("Cannot write display number to fd %d\n", displayfd);
|
|
|
|
if (write(displayfd, "\n", 1) != 1)
|
|
|
|
FatalError("Cannot write display number to fd %d\n", displayfd);
|
2012-04-05 00:29:42 +02:00
|
|
|
close(displayfd);
|
2014-04-19 00:00:35 +02:00
|
|
|
displayfd = -1;
|
2012-04-05 00:29:42 +02:00
|
|
|
}
|
2007-11-01 20:41:11 +01:00
|
|
|
if (RunFromSmartParent) {
|
2012-03-21 20:55:09 +01:00
|
|
|
if (ParentProcess > 1) {
|
|
|
|
kill(ParentProcess, SIGUSR1);
|
|
|
|
}
|
2007-11-01 20:41:11 +01:00
|
|
|
}
|
2010-08-30 20:24:30 +02:00
|
|
|
if (RunFromSigStopParent)
|
2012-03-21 20:55:09 +01:00
|
|
|
raise(SIGSTOP);
|
2007-11-01 20:41:11 +01:00
|
|
|
#endif
|
|
|
|
}
|
2003-11-14 17:49:22 +01:00
|
|
|
|
2012-04-05 00:29:42 +02:00
|
|
|
static Bool
|
|
|
|
TryCreateSocket(int num, int *partial)
|
|
|
|
{
|
|
|
|
char port[20];
|
|
|
|
|
|
|
|
snprintf(port, sizeof(port), "%d", num);
|
|
|
|
|
|
|
|
return (_XSERVTransMakeAllCOTSServerListeners(port, partial,
|
|
|
|
&ListenTransCount,
|
|
|
|
&ListenTransConns) >= 0);
|
|
|
|
}
|
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
/*****************
|
|
|
|
* CreateWellKnownSockets
|
|
|
|
* At initialization, create the sockets to listen on for new clients.
|
|
|
|
*****************/
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2003-11-25 20:29:01 +01:00
|
|
|
CreateWellKnownSockets(void)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
int i;
|
|
|
|
int partial;
|
2003-11-14 16:54:54 +01:00
|
|
|
|
|
|
|
FD_ZERO(&AllSockets);
|
|
|
|
FD_ZERO(&AllClients);
|
|
|
|
FD_ZERO(&LastSelectMask);
|
|
|
|
FD_ZERO(&ClientsWithInput);
|
|
|
|
|
2003-11-14 17:49:22 +01:00
|
|
|
#if !defined(WIN32)
|
2012-03-21 20:55:09 +01:00
|
|
|
for (i = 0; i < MaxClients; i++)
|
|
|
|
ConnectionTranslation[i] = 0;
|
2003-11-14 16:54:54 +01:00
|
|
|
#else
|
2004-11-22 14:23:25 +01:00
|
|
|
ClearConnectionTranslation();
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif
|
|
|
|
|
2012-04-05 00:29:42 +02:00
|
|
|
/* display is initialized to "0" by main(). It is then set to the display
|
2013-03-11 15:34:32 +01:00
|
|
|
* number if specified on the command line. */
|
|
|
|
|
2014-03-19 22:03:13 +01:00
|
|
|
if (NoListenAll) {
|
|
|
|
ListenTransCount = 0;
|
|
|
|
}
|
2013-03-11 15:34:32 +01:00
|
|
|
else if ((displayfd < 0) || explicit_display) {
|
2012-04-05 00:29:42 +02:00
|
|
|
if (TryCreateSocket(atoi(display), &partial) &&
|
|
|
|
ListenTransCount >= 1)
|
|
|
|
if (!PartialNetwork && partial)
|
|
|
|
FatalError ("Failed to establish all listening sockets");
|
|
|
|
}
|
2013-03-11 15:34:32 +01:00
|
|
|
else { /* -displayfd and no explicit display number */
|
2012-04-05 00:29:42 +02:00
|
|
|
Bool found = 0;
|
2014-10-21 16:03:55 +02:00
|
|
|
for (i = 0; i < 65536 - X_TCP_PORT; i++) {
|
2012-04-05 00:29:42 +02:00
|
|
|
if (TryCreateSocket(i, &partial) && !partial) {
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
CloseWellKnownConnections();
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
2012-04-05 00:29:42 +02:00
|
|
|
if (!found)
|
|
|
|
FatalError("Failed to find a socket to listen on");
|
|
|
|
snprintf(dynamic_display, sizeof(dynamic_display), "%d", i);
|
|
|
|
display = dynamic_display;
|
2016-01-02 03:11:14 +01:00
|
|
|
LogSetDisplay();
|
2012-04-05 00:29:42 +02:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2015-03-21 18:08:25 +01:00
|
|
|
ListenTransFds = xallocarray(ListenTransCount, sizeof (int));
|
|
|
|
if (ListenTransFds == NULL)
|
|
|
|
FatalError ("Failed to create listening socket array");
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2012-04-05 00:29:42 +02:00
|
|
|
for (i = 0; i < ListenTransCount; i++) {
|
|
|
|
int fd = _XSERVTransGetConnectionNumber(ListenTransConns[i]);
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2012-04-05 00:29:42 +02:00
|
|
|
ListenTransFds[i] = fd;
|
2015-11-12 07:02:17 +01:00
|
|
|
SetNotifyFd(fd, QueueNewConnections, X_NOTIFY_READ, NULL);
|
2012-04-05 00:29:42 +02:00
|
|
|
|
|
|
|
if (!_XSERVTransIsLocal(ListenTransConns[i]))
|
|
|
|
DefineSelf (fd);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
2015-11-12 07:02:17 +01:00
|
|
|
if (ListenTransCount == 0 && !NoListenAll)
|
2012-03-21 20:55:09 +01:00
|
|
|
FatalError
|
|
|
|
("Cannot establish any listening sockets - Make sure an X server isn't already running");
|
2014-03-19 22:03:13 +01:00
|
|
|
|
2003-11-14 17:49:22 +01:00
|
|
|
#if !defined(WIN32)
|
2012-03-21 20:55:09 +01:00
|
|
|
OsSignal(SIGPIPE, SIG_IGN);
|
|
|
|
OsSignal(SIGHUP, AutoResetServer);
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif
|
2012-03-21 20:55:09 +01:00
|
|
|
OsSignal(SIGINT, GiveUp);
|
|
|
|
OsSignal(SIGTERM, GiveUp);
|
2003-11-14 16:54:54 +01:00
|
|
|
ResetHosts(display);
|
2007-11-01 20:41:11 +01:00
|
|
|
|
|
|
|
InitParentProcess();
|
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
#ifdef XDMCP
|
2012-03-21 20:55:09 +01:00
|
|
|
XdmcpInit();
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2012-03-21 20:55:09 +01:00
|
|
|
ResetWellKnownSockets(void)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ResetOsBuffers();
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
for (i = 0; i < ListenTransCount; i++) {
|
|
|
|
int status = _XSERVTransResetListener(ListenTransConns[i]);
|
|
|
|
|
|
|
|
if (status != TRANS_RESET_NOOP) {
|
|
|
|
if (status == TRANS_RESET_FAILURE) {
|
|
|
|
/*
|
|
|
|
* ListenTransConns[i] freed by xtrans.
|
|
|
|
* Remove it from out list.
|
|
|
|
*/
|
|
|
|
|
2015-11-12 07:02:17 +01:00
|
|
|
RemoveNotifyFd(ListenTransFds[i]);
|
2012-03-21 20:55:09 +01:00
|
|
|
ListenTransFds[i] = ListenTransFds[ListenTransCount - 1];
|
|
|
|
ListenTransConns[i] = ListenTransConns[ListenTransCount - 1];
|
|
|
|
ListenTransCount -= 1;
|
|
|
|
i -= 1;
|
|
|
|
}
|
|
|
|
else if (status == TRANS_RESET_NEW_FD) {
|
|
|
|
/*
|
|
|
|
* A new file descriptor was allocated (the old one was closed)
|
|
|
|
*/
|
|
|
|
|
|
|
|
int newfd = _XSERVTransGetConnectionNumber(ListenTransConns[i]);
|
|
|
|
|
|
|
|
ListenTransFds[i] = newfd;
|
|
|
|
}
|
|
|
|
}
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
2015-11-12 07:02:17 +01:00
|
|
|
for (i = 0; i < ListenTransCount; i++)
|
|
|
|
SetNotifyFd(ListenTransFds[i], QueueNewConnections, X_NOTIFY_READ, NULL);
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
ResetAuthorization();
|
2003-11-14 16:54:54 +01:00
|
|
|
ResetHosts(display);
|
|
|
|
/*
|
|
|
|
* restart XDMCP
|
|
|
|
*/
|
|
|
|
#ifdef XDMCP
|
2012-03-21 20:55:09 +01:00
|
|
|
XdmcpReset();
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2003-11-25 20:29:01 +01:00
|
|
|
CloseWellKnownConnections(void)
|
2003-11-14 17:49:22 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2015-03-09 17:55:57 +01:00
|
|
|
for (i = 0; i < ListenTransCount; i++) {
|
|
|
|
if (ListenTransConns[i] != NULL) {
|
|
|
|
_XSERVTransClose(ListenTransConns[i]);
|
|
|
|
ListenTransConns[i] = NULL;
|
2016-01-02 02:34:41 +01:00
|
|
|
if (ListenTransFds != NULL)
|
|
|
|
RemoveNotifyFd(ListenTransFds[i]);
|
2015-03-09 17:55:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ListenTransCount = 0;
|
2003-11-14 17:49:22 +01:00
|
|
|
}
|
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
static void
|
2012-03-21 20:55:09 +01:00
|
|
|
AuthAudit(ClientPtr client, Bool letin,
|
|
|
|
struct sockaddr *saddr, int len,
|
|
|
|
unsigned int proto_n, char *auth_proto, int auth_id)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
char addr[128];
|
2006-11-02 01:17:49 +01:00
|
|
|
char client_uid_string[64];
|
2007-09-28 01:47:06 +02:00
|
|
|
LocalClientCredRec *lcc;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2007-09-28 01:47:06 +02:00
|
|
|
#ifdef XSERVER_DTRACE
|
2006-11-02 01:17:49 +01:00
|
|
|
pid_t client_pid = -1;
|
|
|
|
zoneid_t client_zid = -1;
|
|
|
|
#endif
|
2003-11-14 16:54:54 +01:00
|
|
|
|
|
|
|
if (!len)
|
2011-10-29 20:13:32 +02:00
|
|
|
strlcpy(addr, "local host", sizeof(addr));
|
2003-11-14 16:54:54 +01:00
|
|
|
else
|
2012-03-21 20:55:09 +01:00
|
|
|
switch (saddr->sa_family) {
|
|
|
|
case AF_UNSPEC:
|
2007-06-29 00:59:05 +02:00
|
|
|
#if defined(UNIXCONN) || defined(LOCALCONN)
|
2012-03-21 20:55:09 +01:00
|
|
|
case AF_UNIX:
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif
|
2012-03-21 20:55:09 +01:00
|
|
|
strlcpy(addr, "local host", sizeof(addr));
|
|
|
|
break;
|
2016-02-08 23:36:03 +01:00
|
|
|
#if defined(TCPCONN)
|
2012-03-21 20:55:09 +01:00
|
|
|
case AF_INET:
|
|
|
|
snprintf(addr, sizeof(addr), "IP %s",
|
|
|
|
inet_ntoa(((struct sockaddr_in *) saddr)->sin_addr));
|
|
|
|
break;
|
2003-11-25 20:29:01 +01:00
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
2012-03-21 20:55:09 +01:00
|
|
|
case AF_INET6:{
|
|
|
|
char ipaddr[INET6_ADDRSTRLEN];
|
|
|
|
|
|
|
|
inet_ntop(AF_INET6, &((struct sockaddr_in6 *) saddr)->sin6_addr,
|
|
|
|
ipaddr, sizeof(ipaddr));
|
|
|
|
snprintf(addr, sizeof(addr), "IP %s", ipaddr);
|
|
|
|
}
|
|
|
|
break;
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2012-03-21 20:55:09 +01:00
|
|
|
default:
|
|
|
|
strlcpy(addr, "unknown address", sizeof(addr));
|
|
|
|
}
|
2006-11-02 00:11:48 +01:00
|
|
|
|
2007-09-28 01:47:06 +02:00
|
|
|
if (GetLocalClientCreds(client, &lcc) != -1) {
|
2012-03-21 20:55:09 +01:00
|
|
|
int slen; /* length written to client_uid_string */
|
|
|
|
|
|
|
|
strcpy(client_uid_string, " ( ");
|
|
|
|
slen = 3;
|
|
|
|
|
|
|
|
if (lcc->fieldsSet & LCC_UID_SET) {
|
|
|
|
snprintf(client_uid_string + slen,
|
|
|
|
sizeof(client_uid_string) - slen,
|
|
|
|
"uid=%ld ", (long) lcc->euid);
|
|
|
|
slen = strlen(client_uid_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lcc->fieldsSet & LCC_GID_SET) {
|
|
|
|
snprintf(client_uid_string + slen,
|
|
|
|
sizeof(client_uid_string) - slen,
|
|
|
|
"gid=%ld ", (long) lcc->egid);
|
|
|
|
slen = strlen(client_uid_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lcc->fieldsSet & LCC_PID_SET) {
|
|
|
|
#ifdef XSERVER_DTRACE
|
|
|
|
client_pid = lcc->pid;
|
2006-11-02 01:17:49 +01:00
|
|
|
#endif
|
2012-03-21 20:55:09 +01:00
|
|
|
snprintf(client_uid_string + slen,
|
|
|
|
sizeof(client_uid_string) - slen,
|
|
|
|
"pid=%ld ", (long) lcc->pid);
|
|
|
|
slen = strlen(client_uid_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lcc->fieldsSet & LCC_ZID_SET) {
|
2007-09-28 01:47:06 +02:00
|
|
|
#ifdef XSERVER_DTRACE
|
2012-03-21 20:55:09 +01:00
|
|
|
client_zid = lcc->zoneid;
|
|
|
|
#endif
|
|
|
|
snprintf(client_uid_string + slen,
|
|
|
|
sizeof(client_uid_string) - slen,
|
|
|
|
"zoneid=%ld ", (long) lcc->zoneid);
|
|
|
|
slen = strlen(client_uid_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(client_uid_string + slen, sizeof(client_uid_string) - slen,
|
|
|
|
")");
|
|
|
|
FreeLocalClientCreds(lcc);
|
2007-09-28 01:47:06 +02:00
|
|
|
}
|
2006-11-02 01:17:49 +01:00
|
|
|
else {
|
2012-03-21 20:55:09 +01:00
|
|
|
client_uid_string[0] = '\0';
|
2006-11-02 00:11:48 +01:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2006-11-03 21:54:43 +01:00
|
|
|
#ifdef XSERVER_DTRACE
|
|
|
|
XSERVER_CLIENT_AUTH(client->index, addr, client_pid, client_zid);
|
|
|
|
#endif
|
2008-12-17 08:49:39 +01:00
|
|
|
if (auditTrailLevel > 1) {
|
2012-03-21 20:55:09 +01:00
|
|
|
if (proto_n)
|
|
|
|
AuditF("client %d %s from %s%s\n Auth name: %.*s ID: %d\n",
|
|
|
|
client->index, letin ? "connected" : "rejected", addr,
|
|
|
|
client_uid_string, (int) proto_n, auth_proto, auth_id);
|
|
|
|
else
|
|
|
|
AuditF("client %d %s from %s%s\n",
|
|
|
|
client->index, letin ? "connected" : "rejected", addr,
|
|
|
|
client_uid_string);
|
2006-11-03 21:54:43 +01:00
|
|
|
|
|
|
|
}
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
XID
|
2003-11-25 20:29:01 +01:00
|
|
|
AuthorizationIDOfClient(ClientPtr client)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
if (client->osPrivate)
|
2012-03-21 20:55:09 +01:00
|
|
|
return ((OsCommPtr) client->osPrivate)->auth_id;
|
2003-11-14 16:54:54 +01:00
|
|
|
else
|
2012-03-21 20:55:09 +01:00
|
|
|
return None;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* ClientAuthorized
|
|
|
|
*
|
|
|
|
* Sent by the client at connection setup:
|
|
|
|
* typedef struct _xConnClientPrefix {
|
|
|
|
* CARD8 byteOrder;
|
|
|
|
* BYTE pad;
|
|
|
|
* CARD16 majorVersion, minorVersion;
|
2014-10-31 00:45:12 +01:00
|
|
|
* CARD16 nbytesAuthProto;
|
|
|
|
* CARD16 nbytesAuthString;
|
2003-11-14 16:54:54 +01:00
|
|
|
* } xConnClientPrefix;
|
|
|
|
*
|
|
|
|
* It is hoped that eventually one protocol will be agreed upon. In the
|
|
|
|
* mean time, a server that implements a different protocol than the
|
|
|
|
* client expects, or a server that only implements the host-based
|
|
|
|
* mechanism, will simply ignore this information.
|
|
|
|
*
|
|
|
|
*****************************************************************/
|
|
|
|
|
2011-12-13 01:49:33 +01:00
|
|
|
const char *
|
2012-03-21 20:55:09 +01:00
|
|
|
ClientAuthorized(ClientPtr client,
|
|
|
|
unsigned int proto_n, char *auth_proto,
|
|
|
|
unsigned int string_n, char *auth_string)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
OsCommPtr priv;
|
|
|
|
Xtransaddr *from = NULL;
|
|
|
|
int family;
|
|
|
|
int fromlen;
|
|
|
|
XID auth_id;
|
|
|
|
const char *reason = NULL;
|
|
|
|
XtransConnInfo trans_conn;
|
|
|
|
|
|
|
|
priv = (OsCommPtr) client->osPrivate;
|
2003-11-14 16:54:54 +01:00
|
|
|
trans_conn = priv->trans_conn;
|
|
|
|
|
2008-08-06 19:23:31 +02:00
|
|
|
/* Allow any client to connect without authorization on a launchd socket,
|
|
|
|
because it is securely created -- this prevents a race condition on launch */
|
2012-03-21 20:55:09 +01:00
|
|
|
if (trans_conn->flags & TRANS_NOXAUTH) {
|
2008-08-06 19:23:31 +02:00
|
|
|
auth_id = (XID) 0L;
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
auth_id =
|
|
|
|
CheckAuthorization(proto_n, auth_proto, string_n, auth_string,
|
|
|
|
client, &reason);
|
2008-08-06 19:23:31 +02:00
|
|
|
}
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
if (auth_id == (XID) ~0L) {
|
|
|
|
if (_XSERVTransGetPeerAddr(trans_conn, &family, &fromlen, &from) != -1) {
|
|
|
|
if (InvalidHost((struct sockaddr *) from, fromlen, client))
|
|
|
|
AuthAudit(client, FALSE, (struct sockaddr *) from,
|
|
|
|
fromlen, proto_n, auth_proto, auth_id);
|
|
|
|
else {
|
|
|
|
auth_id = (XID) 0;
|
2006-11-03 21:54:43 +01:00
|
|
|
#ifdef XSERVER_DTRACE
|
2012-03-21 20:55:09 +01:00
|
|
|
if ((auditTrailLevel > 1) || XSERVER_CLIENT_AUTH_ENABLED())
|
2006-11-03 21:54:43 +01:00
|
|
|
#else
|
2012-03-21 20:55:09 +01:00
|
|
|
if (auditTrailLevel > 1)
|
2006-11-03 21:54:43 +01:00
|
|
|
#endif
|
2012-03-21 20:55:09 +01:00
|
|
|
AuthAudit(client, TRUE,
|
|
|
|
(struct sockaddr *) from, fromlen,
|
|
|
|
proto_n, auth_proto, auth_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(from);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auth_id == (XID) ~0L) {
|
|
|
|
if (reason)
|
|
|
|
return reason;
|
|
|
|
else
|
|
|
|
return "Client is not authorized to connect to Server";
|
|
|
|
}
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
2006-11-03 21:54:43 +01:00
|
|
|
#ifdef XSERVER_DTRACE
|
|
|
|
else if ((auditTrailLevel > 1) || XSERVER_CLIENT_AUTH_ENABLED())
|
|
|
|
#else
|
2003-11-14 16:54:54 +01:00
|
|
|
else if (auditTrailLevel > 1)
|
2006-11-03 21:54:43 +01:00
|
|
|
#endif
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
if (_XSERVTransGetPeerAddr(trans_conn, &family, &fromlen, &from) != -1) {
|
|
|
|
AuthAudit(client, TRUE, (struct sockaddr *) from, fromlen,
|
|
|
|
proto_n, auth_proto, auth_id);
|
|
|
|
|
|
|
|
free(from);
|
|
|
|
}
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
priv->auth_id = auth_id;
|
|
|
|
priv->conn_time = 0;
|
|
|
|
|
|
|
|
#ifdef XDMCP
|
|
|
|
/* indicate to Xdmcp protocol that we've opened new client */
|
|
|
|
XdmcpOpenDisplay(priv->fd);
|
2012-03-21 20:55:09 +01:00
|
|
|
#endif /* XDMCP */
|
2006-12-02 02:48:15 +01:00
|
|
|
|
2004-05-05 22:04:52 +02:00
|
|
|
XaceHook(XACE_AUTH_AVAIL, client, auth_id);
|
2006-12-02 02:48:15 +01:00
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
/* At this point, if the client is authorized to change the access control
|
|
|
|
* list, we should getpeername() information, and add the client to
|
|
|
|
* the selfhosts list. It's not really the host machine, but the
|
|
|
|
* true purpose of the selfhosts list is to see who may change the
|
|
|
|
* access control list.
|
|
|
|
*/
|
2012-03-21 20:55:09 +01:00
|
|
|
return ((char *) NULL);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ClientPtr
|
2012-03-21 20:55:09 +01:00
|
|
|
AllocNewConnection(XtransConnInfo trans_conn, int fd, CARD32 conn_time)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
OsCommPtr oc;
|
|
|
|
ClientPtr client;
|
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
if (
|
|
|
|
#ifndef WIN32
|
2012-03-21 20:55:09 +01:00
|
|
|
fd >= lastfdesc
|
2003-11-14 16:54:54 +01:00
|
|
|
#else
|
2012-03-21 20:55:09 +01:00
|
|
|
XFD_SETCOUNT(&AllClients) >= MaxClients
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif
|
2012-03-21 20:55:09 +01:00
|
|
|
)
|
|
|
|
return NullClient;
|
2010-05-05 20:44:06 +02:00
|
|
|
oc = malloc(sizeof(OsCommRec));
|
2003-11-14 16:54:54 +01:00
|
|
|
if (!oc)
|
2012-03-21 20:55:09 +01:00
|
|
|
return NullClient;
|
2003-11-14 16:54:54 +01:00
|
|
|
oc->trans_conn = trans_conn;
|
|
|
|
oc->fd = fd;
|
2012-03-21 20:55:09 +01:00
|
|
|
oc->input = (ConnectionInputPtr) NULL;
|
|
|
|
oc->output = (ConnectionOutputPtr) NULL;
|
2003-11-14 16:54:54 +01:00
|
|
|
oc->auth_id = None;
|
|
|
|
oc->conn_time = conn_time;
|
2013-12-15 10:05:51 +01:00
|
|
|
if (!(client = NextAvailableClient((void *) oc))) {
|
2012-03-21 20:55:09 +01:00
|
|
|
free(oc);
|
|
|
|
return NullClient;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
2012-09-20 19:16:59 +02:00
|
|
|
client->local = ComputeLocalClient(client);
|
2004-11-22 14:23:25 +01:00
|
|
|
#if !defined(WIN32)
|
2006-06-02 00:06:41 +02:00
|
|
|
ConnectionTranslation[fd] = client->index;
|
2004-11-22 14:23:25 +01:00
|
|
|
#else
|
2006-06-02 00:06:41 +02:00
|
|
|
SetConnectionTranslation(fd, client->index);
|
2004-11-22 14:23:25 +01:00
|
|
|
#endif
|
2012-03-21 20:55:09 +01:00
|
|
|
if (GrabInProgress) {
|
2006-06-02 00:06:41 +02:00
|
|
|
FD_SET(fd, &SavedAllClients);
|
|
|
|
FD_SET(fd, &SavedAllSockets);
|
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
else {
|
2006-06-02 00:06:41 +02:00
|
|
|
FD_SET(fd, &AllClients);
|
|
|
|
FD_SET(fd, &AllSockets);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
2003-11-14 17:49:22 +01:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
ErrorF("AllocNewConnection: client index = %d, socket fd = %d\n",
|
2012-03-21 20:55:09 +01:00
|
|
|
client->index, fd);
|
2003-11-14 17:49:22 +01:00
|
|
|
#endif
|
2006-11-03 21:54:43 +01:00
|
|
|
#ifdef XSERVER_DTRACE
|
|
|
|
XSERVER_CLIENT_CONNECT(client->index, fd);
|
2012-03-21 20:55:09 +01:00
|
|
|
#endif
|
2003-11-14 17:49:22 +01:00
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
return client;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************
|
|
|
|
* EstablishNewConnections
|
|
|
|
* If anyone is waiting on listened sockets, accept them.
|
|
|
|
* Returns a mask with indices of new clients. Updates AllClients
|
|
|
|
* and AllSockets.
|
|
|
|
*****************/
|
|
|
|
|
2015-11-12 07:02:17 +01:00
|
|
|
static Bool
|
2013-12-15 10:05:51 +01:00
|
|
|
EstablishNewConnections(ClientPtr clientUnused, void *closure)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2015-11-12 07:02:17 +01:00
|
|
|
int curconn = (int) (intptr_t) closure;
|
|
|
|
int newconn; /* fd of new client */
|
2003-11-14 16:54:54 +01:00
|
|
|
CARD32 connect_time;
|
2015-11-12 07:02:17 +01:00
|
|
|
int i;
|
|
|
|
ClientPtr client;
|
|
|
|
OsCommPtr oc;
|
|
|
|
XtransConnInfo trans_conn, new_trans_conn;
|
|
|
|
int status;
|
2003-11-14 16:54:54 +01:00
|
|
|
|
|
|
|
connect_time = GetTimeInMillis();
|
|
|
|
/* kill off stragglers */
|
2012-03-21 20:55:09 +01:00
|
|
|
for (i = 1; i < currentMaxClients; i++) {
|
|
|
|
if ((client = clients[i])) {
|
|
|
|
oc = (OsCommPtr) (client->osPrivate);
|
|
|
|
if ((oc && (oc->conn_time != 0) &&
|
|
|
|
(connect_time - oc->conn_time) >= TimeOutValue) ||
|
|
|
|
(client->noClientException != Success && !client->clientGone))
|
|
|
|
CloseDownClient(client);
|
|
|
|
}
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
2015-11-12 07:02:17 +01:00
|
|
|
if ((trans_conn = lookup_trans_conn(curconn)) == NULL)
|
|
|
|
return TRUE;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2015-11-12 07:02:17 +01:00
|
|
|
if ((new_trans_conn = _XSERVTransAccept(trans_conn, &status)) == NULL)
|
|
|
|
return TRUE;
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2015-11-12 07:02:17 +01:00
|
|
|
newconn = _XSERVTransGetConnectionNumber(new_trans_conn);
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2015-11-12 07:02:17 +01:00
|
|
|
if (newconn < lastfdesc) {
|
|
|
|
int clientid;
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2004-11-22 14:23:25 +01:00
|
|
|
#if !defined(WIN32)
|
2015-11-12 07:02:17 +01:00
|
|
|
clientid = ConnectionTranslation[newconn];
|
2004-11-22 14:23:25 +01:00
|
|
|
#else
|
2015-11-12 07:02:17 +01:00
|
|
|
clientid = GetConnectionTranslation(newconn);
|
2004-11-22 14:23:25 +01:00
|
|
|
#endif
|
2015-11-12 07:02:17 +01:00
|
|
|
if (clientid && (client = clients[clientid]))
|
|
|
|
CloseDownClient(client);
|
|
|
|
}
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2015-11-12 07:02:17 +01:00
|
|
|
_XSERVTransSetOption(new_trans_conn, TRANS_NONBLOCKING, 1);
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2015-11-12 07:02:17 +01:00
|
|
|
if (trans_conn->flags & TRANS_NOXAUTH)
|
|
|
|
new_trans_conn->flags = new_trans_conn->flags | TRANS_NOXAUTH;
|
2011-04-04 20:40:06 +02:00
|
|
|
|
2015-11-12 07:02:17 +01:00
|
|
|
if (!AllocNewConnection(new_trans_conn, newconn, connect_time)) {
|
|
|
|
ErrorConnMax(new_trans_conn);
|
|
|
|
_XSERVTransClose(new_trans_conn);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
2015-11-12 07:02:17 +01:00
|
|
|
return TRUE;
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
2015-11-12 07:02:17 +01:00
|
|
|
|
|
|
|
static void
|
|
|
|
QueueNewConnections(int fd, int ready, void *data)
|
|
|
|
{
|
|
|
|
QueueWorkProc(EstablishNewConnections, NULL, (void *) (intptr_t) fd);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define NOROOM "Maximum number of clients reached"
|
|
|
|
|
|
|
|
/************
|
|
|
|
* ErrorConnMax
|
|
|
|
* Fail a connection due to lack of client or file descriptor space
|
|
|
|
************/
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
#define BOTIMEOUT 200 /* in milliseconds */
|
2011-06-17 20:17:09 +02:00
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
static void
|
2003-11-25 20:29:01 +01:00
|
|
|
ErrorConnMax(XtransConnInfo trans_conn)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
int fd = _XSERVTransGetConnectionNumber(trans_conn);
|
2003-11-14 16:54:54 +01:00
|
|
|
xConnSetupPrefix csp;
|
2012-07-10 04:12:44 +02:00
|
|
|
char pad[3] = { 0, 0, 0 };
|
2003-11-14 16:54:54 +01:00
|
|
|
struct iovec iov[3];
|
2011-06-17 19:43:38 +02:00
|
|
|
char order = 0;
|
2003-11-14 16:54:54 +01:00
|
|
|
int whichbyte = 1;
|
|
|
|
struct timeval waittime;
|
|
|
|
fd_set mask;
|
|
|
|
|
|
|
|
/* if these seems like a lot of trouble to go to, it probably is */
|
|
|
|
waittime.tv_sec = BOTIMEOUT / MILLI_PER_SECOND;
|
|
|
|
waittime.tv_usec = (BOTIMEOUT % MILLI_PER_SECOND) *
|
2012-03-21 20:55:09 +01:00
|
|
|
(1000000 / MILLI_PER_SECOND);
|
2003-11-14 16:54:54 +01:00
|
|
|
FD_ZERO(&mask);
|
|
|
|
FD_SET(fd, &mask);
|
2012-03-21 20:55:09 +01:00
|
|
|
(void) Select(fd + 1, &mask, NULL, NULL, &waittime);
|
2003-11-14 16:54:54 +01:00
|
|
|
/* try to read the byte-order of the connection */
|
2011-06-17 19:43:38 +02:00
|
|
|
(void) _XSERVTransRead(trans_conn, &order, 1);
|
|
|
|
if (order == 'l' || order == 'B' || order == 'r' || order == 'R') {
|
2012-03-21 20:55:09 +01:00
|
|
|
csp.success = xFalse;
|
|
|
|
csp.lengthReason = sizeof(NOROOM) - 1;
|
|
|
|
csp.length = (sizeof(NOROOM) + 2) >> 2;
|
|
|
|
csp.majorVersion = X_PROTOCOL;
|
|
|
|
csp.minorVersion = X_PROTOCOL_REVISION;
|
2011-06-17 19:43:38 +02:00
|
|
|
if (((*(char *) &whichbyte) && (order == 'B' || order == 'R')) ||
|
|
|
|
(!(*(char *) &whichbyte) && (order == 'l' || order == 'r'))) {
|
2012-03-21 20:55:09 +01:00
|
|
|
swaps(&csp.majorVersion);
|
|
|
|
swaps(&csp.minorVersion);
|
|
|
|
swaps(&csp.length);
|
|
|
|
}
|
|
|
|
iov[0].iov_len = sz_xConnSetupPrefix;
|
|
|
|
iov[0].iov_base = (char *) &csp;
|
|
|
|
iov[1].iov_len = csp.lengthReason;
|
2013-01-14 23:24:36 +01:00
|
|
|
iov[1].iov_base = (void *) NOROOM;
|
2012-03-21 20:55:09 +01:00
|
|
|
iov[2].iov_len = (4 - (csp.lengthReason & 3)) & 3;
|
|
|
|
iov[2].iov_base = pad;
|
|
|
|
(void) _XSERVTransWritev(trans_conn, iov, 3);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/************
|
|
|
|
* CloseDownFileDescriptor:
|
|
|
|
* Remove this file descriptor and it's I/O buffers, etc.
|
|
|
|
************/
|
|
|
|
|
|
|
|
static void
|
2003-11-25 20:29:01 +01:00
|
|
|
CloseDownFileDescriptor(OsCommPtr oc)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
int connection = oc->fd;
|
|
|
|
|
|
|
|
if (oc->trans_conn) {
|
2012-03-21 20:55:09 +01:00
|
|
|
_XSERVTransDisconnect(oc->trans_conn);
|
|
|
|
_XSERVTransClose(oc->trans_conn);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
2004-11-22 14:23:25 +01:00
|
|
|
#ifndef WIN32
|
2003-11-14 17:49:22 +01:00
|
|
|
ConnectionTranslation[connection] = 0;
|
2004-11-22 14:23:25 +01:00
|
|
|
#else
|
|
|
|
SetConnectionTranslation(connection, 0);
|
2012-03-21 20:55:09 +01:00
|
|
|
#endif
|
2003-11-14 16:54:54 +01:00
|
|
|
FD_CLR(connection, &AllSockets);
|
|
|
|
FD_CLR(connection, &AllClients);
|
|
|
|
FD_CLR(connection, &ClientsWithInput);
|
|
|
|
FD_CLR(connection, &GrabImperviousClients);
|
2012-03-21 20:55:09 +01:00
|
|
|
if (GrabInProgress) {
|
|
|
|
FD_CLR(connection, &SavedAllSockets);
|
|
|
|
FD_CLR(connection, &SavedAllClients);
|
|
|
|
FD_CLR(connection, &SavedClientsWithInput);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
FD_CLR(connection, &ClientsWriteBlocked);
|
2015-11-12 07:02:03 +01:00
|
|
|
if (!XFD_ANYSET(&ClientsWriteBlocked) && NumNotifyWriteFd == 0)
|
|
|
|
AnyWritesPending = FALSE;
|
2003-11-14 16:54:54 +01:00
|
|
|
FD_CLR(connection, &OutputPending);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************
|
2003-11-14 17:49:22 +01:00
|
|
|
* CheckConnections
|
2014-10-31 00:45:12 +01:00
|
|
|
* Some connection has died, go find which one and shut it down
|
2003-11-14 16:54:54 +01:00
|
|
|
* The file descriptor has been closed, but is still in AllClients.
|
|
|
|
* If would truly be wonderful if select() would put the bogus
|
|
|
|
* file descriptors in the exception mask, but nooooo. So we have
|
|
|
|
* to check each and every socket individually.
|
|
|
|
*****************/
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2003-11-25 20:29:01 +01:00
|
|
|
CheckConnections(void)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
#ifndef WIN32
|
2012-03-21 20:55:09 +01:00
|
|
|
fd_mask mask;
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif
|
2012-03-21 20:55:09 +01:00
|
|
|
fd_set tmask;
|
|
|
|
int curclient, curoff;
|
|
|
|
int i;
|
|
|
|
struct timeval notime;
|
2003-11-14 16:54:54 +01:00
|
|
|
int r;
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
#ifdef WIN32
|
|
|
|
fd_set savedAllClients;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
notime.tv_sec = 0;
|
|
|
|
notime.tv_usec = 0;
|
|
|
|
|
|
|
|
#ifndef WIN32
|
2012-03-21 20:55:09 +01:00
|
|
|
for (i = 0; i < howmany(XFD_SETSIZE, NFDBITS); i++) {
|
|
|
|
mask = AllClients.fds_bits[i];
|
|
|
|
while (mask) {
|
|
|
|
curoff = mffs(mask) - 1;
|
|
|
|
curclient = curoff + (i * (sizeof(fd_mask) * 8));
|
2003-11-14 16:54:54 +01:00
|
|
|
FD_ZERO(&tmask);
|
|
|
|
FD_SET(curclient, &tmask);
|
2007-12-05 20:36:37 +01:00
|
|
|
do {
|
2012-03-21 20:55:09 +01:00
|
|
|
r = Select(curclient + 1, &tmask, NULL, NULL, ¬ime);
|
2007-12-05 20:36:37 +01:00
|
|
|
} while (r < 0 && (errno == EINTR || errno == EAGAIN));
|
2003-11-14 16:54:54 +01:00
|
|
|
if (r < 0)
|
2007-12-05 20:31:07 +01:00
|
|
|
if (ConnectionTranslation[curclient] > 0)
|
|
|
|
CloseDownClient(clients[ConnectionTranslation[curclient]]);
|
2012-03-21 20:55:09 +01:00
|
|
|
mask &= ~((fd_mask) 1 << curoff);
|
|
|
|
}
|
|
|
|
}
|
2003-11-14 16:54:54 +01:00
|
|
|
#else
|
|
|
|
XFD_COPYSET(&AllClients, &savedAllClients);
|
2012-03-21 20:55:09 +01:00
|
|
|
for (i = 0; i < XFD_SETCOUNT(&savedAllClients); i++) {
|
|
|
|
curclient = XFD_FD(&savedAllClients, i);
|
|
|
|
FD_ZERO(&tmask);
|
|
|
|
FD_SET(curclient, &tmask);
|
2007-12-05 20:36:37 +01:00
|
|
|
do {
|
2012-03-21 20:55:09 +01:00
|
|
|
r = Select(curclient + 1, &tmask, NULL, NULL, ¬ime);
|
2007-12-05 20:36:37 +01:00
|
|
|
} while (r < 0 && (errno == EINTR || errno == EAGAIN));
|
2012-03-21 20:55:09 +01:00
|
|
|
if (r < 0)
|
2007-12-05 20:36:37 +01:00
|
|
|
if (GetConnectionTranslation(curclient) > 0)
|
|
|
|
CloseDownClient(clients[GetConnectionTranslation(curclient)]);
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************
|
|
|
|
* CloseDownConnection
|
2014-10-31 00:45:12 +01:00
|
|
|
* Delete client from AllClients and free resources
|
2003-11-14 16:54:54 +01:00
|
|
|
*****************/
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2003-11-25 20:29:01 +01:00
|
|
|
CloseDownConnection(ClientPtr client)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
OsCommPtr oc = (OsCommPtr) client->osPrivate;
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2010-07-30 00:52:35 +02:00
|
|
|
if (FlushCallback)
|
2012-03-21 20:55:09 +01:00
|
|
|
CallCallbacks(&FlushCallback, NULL);
|
2010-07-30 00:52:35 +02:00
|
|
|
|
2011-06-17 20:03:01 +02:00
|
|
|
if (oc->output)
|
|
|
|
FlushClient(client, oc, (char *) NULL, 0);
|
2003-11-14 16:54:54 +01:00
|
|
|
#ifdef XDMCP
|
|
|
|
XdmcpCloseDisplay(oc->fd);
|
|
|
|
#endif
|
|
|
|
CloseDownFileDescriptor(oc);
|
2007-02-15 18:09:00 +01:00
|
|
|
FreeOsBuffers(oc);
|
2010-05-05 20:44:06 +02:00
|
|
|
free(client->osPrivate);
|
2013-12-15 10:05:51 +01:00
|
|
|
client->osPrivate = (void *) NULL;
|
2003-11-14 16:54:54 +01:00
|
|
|
if (auditTrailLevel > 1)
|
2012-03-21 20:55:09 +01:00
|
|
|
AuditF("client %d disconnected\n", client->index);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2006-07-19 16:05:12 +02:00
|
|
|
AddGeneralSocket(int fd)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
FD_SET(fd, &AllSockets);
|
2003-11-14 17:49:22 +01:00
|
|
|
if (GrabInProgress)
|
2012-03-21 20:55:09 +01:00
|
|
|
FD_SET(fd, &SavedAllSockets);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2006-07-19 16:05:12 +02:00
|
|
|
AddEnabledDevice(int fd)
|
|
|
|
{
|
|
|
|
FD_SET(fd, &EnabledDevices);
|
|
|
|
AddGeneralSocket(fd);
|
|
|
|
}
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2006-07-19 16:05:12 +02:00
|
|
|
RemoveGeneralSocket(int fd)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
FD_CLR(fd, &AllSockets);
|
2003-11-14 17:49:22 +01:00
|
|
|
if (GrabInProgress)
|
2012-03-21 20:55:09 +01:00
|
|
|
FD_CLR(fd, &SavedAllSockets);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2006-07-19 16:05:12 +02:00
|
|
|
RemoveEnabledDevice(int fd)
|
|
|
|
{
|
|
|
|
FD_CLR(fd, &EnabledDevices);
|
|
|
|
RemoveGeneralSocket(fd);
|
|
|
|
}
|
|
|
|
|
2015-11-12 07:02:02 +01:00
|
|
|
struct notify_fd {
|
|
|
|
struct xorg_list list;
|
|
|
|
int fd;
|
|
|
|
int mask;
|
|
|
|
NotifyFdProcPtr notify;
|
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct xorg_list notify_fds;
|
|
|
|
|
|
|
|
void
|
|
|
|
InitNotifyFds(void)
|
|
|
|
{
|
|
|
|
struct notify_fd *s, *next;
|
|
|
|
static int been_here;
|
|
|
|
|
|
|
|
if (been_here)
|
|
|
|
xorg_list_for_each_entry_safe(s, next, ¬ify_fds, list)
|
|
|
|
RemoveNotifyFd(s->fd);
|
|
|
|
|
|
|
|
xorg_list_init(¬ify_fds);
|
2015-11-12 07:02:03 +01:00
|
|
|
NumNotifyWriteFd = 0;
|
2015-11-12 07:02:02 +01:00
|
|
|
been_here = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************
|
|
|
|
* SetNotifyFd
|
|
|
|
* Registers a callback to be invoked when the specified
|
|
|
|
* file descriptor becomes readable.
|
|
|
|
*****************/
|
|
|
|
|
|
|
|
Bool
|
|
|
|
SetNotifyFd(int fd, NotifyFdProcPtr notify, int mask, void *data)
|
|
|
|
{
|
|
|
|
struct notify_fd *n;
|
|
|
|
int changes;
|
|
|
|
|
|
|
|
xorg_list_for_each_entry(n, ¬ify_fds, list)
|
|
|
|
if (n->fd == fd)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (&n->list == ¬ify_fds) {
|
|
|
|
if (mask == 0)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
n = calloc(1, sizeof (struct notify_fd));
|
|
|
|
if (!n)
|
|
|
|
return FALSE;
|
|
|
|
n->fd = fd;
|
|
|
|
xorg_list_add(&n->list, ¬ify_fds);
|
|
|
|
}
|
|
|
|
|
|
|
|
changes = n->mask ^ mask;
|
|
|
|
|
|
|
|
if (changes & X_NOTIFY_READ) {
|
|
|
|
if (mask & X_NOTIFY_READ) {
|
|
|
|
FD_SET(fd, &NotifyReadFds);
|
|
|
|
AddGeneralSocket(fd);
|
|
|
|
} else {
|
|
|
|
RemoveGeneralSocket(fd);
|
|
|
|
FD_CLR(fd, &NotifyReadFds);
|
|
|
|
}
|
|
|
|
}
|
2015-11-12 07:02:03 +01:00
|
|
|
|
|
|
|
if (changes & X_NOTIFY_WRITE) {
|
|
|
|
if (mask & X_NOTIFY_WRITE) {
|
|
|
|
FD_SET(fd, &NotifyWriteFds);
|
|
|
|
if (!NumNotifyWriteFd++)
|
|
|
|
AnyWritesPending = TRUE;
|
|
|
|
} else {
|
|
|
|
FD_CLR(fd, &NotifyWriteFds);
|
|
|
|
if (!--NumNotifyWriteFd)
|
|
|
|
if (!XFD_ANYSET(&ClientsWriteBlocked))
|
|
|
|
AnyWritesPending = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-12 07:02:02 +01:00
|
|
|
if (mask == 0) {
|
|
|
|
xorg_list_del(&n->list);
|
|
|
|
free(n);
|
|
|
|
} else {
|
|
|
|
n->mask = mask;
|
|
|
|
n->data = data;
|
|
|
|
n->notify = notify;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************
|
|
|
|
* HandlNotifyFds
|
|
|
|
* A WorkProc to be called when any of the registered
|
|
|
|
* file descriptors are readable.
|
|
|
|
*****************/
|
|
|
|
|
|
|
|
void
|
|
|
|
HandleNotifyFds(void)
|
|
|
|
{
|
2015-11-12 07:02:03 +01:00
|
|
|
struct notify_fd *n, *next;
|
|
|
|
|
|
|
|
xorg_list_for_each_entry_safe(n, next, ¬ify_fds, list) {
|
|
|
|
int ready = 0;
|
|
|
|
if ((n->mask & X_NOTIFY_READ) && FD_ISSET(n->fd, &LastSelectMask))
|
|
|
|
ready |= X_NOTIFY_READ;
|
|
|
|
if ((n->mask & X_NOTIFY_WRITE) & FD_ISSET(n->fd, &LastSelectWriteMask))
|
|
|
|
ready |= X_NOTIFY_WRITE;
|
|
|
|
if (ready != 0)
|
|
|
|
n->notify(n->fd, ready, n->data);
|
2015-11-12 07:02:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
/*****************
|
|
|
|
* OnlyListenToOneClient:
|
|
|
|
* Only accept requests from one client. Continue to handle new
|
|
|
|
* connections, but don't take any protocol requests from the new
|
|
|
|
* ones. Note that if GrabInProgress is set, EstablishNewConnections
|
|
|
|
* needs to put new clients into SavedAllSockets and SavedAllClients.
|
|
|
|
* Note also that there is no timeout for this in the protocol.
|
|
|
|
* This routine is "undone" by ListenToAllClients()
|
|
|
|
*****************/
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
int
|
2003-11-25 20:29:01 +01:00
|
|
|
OnlyListenToOneClient(ClientPtr client)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
OsCommPtr oc = (OsCommPtr) client->osPrivate;
|
2007-08-15 20:14:45 +02:00
|
|
|
int rc, connection = oc->fd;
|
|
|
|
|
|
|
|
rc = XaceHook(XACE_SERVER_ACCESS, client, DixGrabAccess);
|
|
|
|
if (rc != Success)
|
2012-03-21 20:55:09 +01:00
|
|
|
return rc;
|
|
|
|
|
|
|
|
if (!GrabInProgress) {
|
|
|
|
XFD_COPYSET(&ClientsWithInput, &SavedClientsWithInput);
|
|
|
|
XFD_ANDSET(&ClientsWithInput,
|
|
|
|
&ClientsWithInput, &GrabImperviousClients);
|
|
|
|
if (FD_ISSET(connection, &SavedClientsWithInput)) {
|
|
|
|
FD_CLR(connection, &SavedClientsWithInput);
|
|
|
|
FD_SET(connection, &ClientsWithInput);
|
|
|
|
}
|
|
|
|
XFD_UNSET(&SavedClientsWithInput, &GrabImperviousClients);
|
|
|
|
XFD_COPYSET(&AllSockets, &SavedAllSockets);
|
|
|
|
XFD_COPYSET(&AllClients, &SavedAllClients);
|
|
|
|
XFD_UNSET(&AllSockets, &AllClients);
|
|
|
|
XFD_ANDSET(&AllClients, &AllClients, &GrabImperviousClients);
|
|
|
|
FD_SET(connection, &AllClients);
|
|
|
|
XFD_ORSET(&AllSockets, &AllSockets, &AllClients);
|
|
|
|
GrabInProgress = client->index;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
2007-08-15 20:14:45 +02:00
|
|
|
return rc;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************
|
|
|
|
* ListenToAllClients:
|
|
|
|
* Undoes OnlyListentToOneClient()
|
|
|
|
****************/
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2003-11-25 20:29:01 +01:00
|
|
|
ListenToAllClients(void)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
if (GrabInProgress) {
|
|
|
|
XFD_ORSET(&AllSockets, &AllSockets, &SavedAllSockets);
|
|
|
|
XFD_ORSET(&AllClients, &AllClients, &SavedAllClients);
|
|
|
|
XFD_ORSET(&ClientsWithInput, &ClientsWithInput, &SavedClientsWithInput);
|
|
|
|
GrabInProgress = 0;
|
|
|
|
}
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************
|
|
|
|
* IgnoreClient
|
|
|
|
* Removes one client from input masks.
|
|
|
|
* Must have cooresponding call to AttendClient.
|
|
|
|
****************/
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2012-03-21 20:55:09 +01:00
|
|
|
IgnoreClient(ClientPtr client)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
OsCommPtr oc = (OsCommPtr) client->osPrivate;
|
2003-11-14 16:54:54 +01:00
|
|
|
int connection = oc->fd;
|
|
|
|
|
2010-06-30 16:59:04 +02:00
|
|
|
client->ignoreCount++;
|
|
|
|
if (client->ignoreCount > 1)
|
2012-03-21 20:55:09 +01:00
|
|
|
return;
|
2010-06-30 16:59:04 +02:00
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
isItTimeToYield = TRUE;
|
2012-03-21 20:55:09 +01:00
|
|
|
if (!GrabInProgress || FD_ISSET(connection, &AllClients)) {
|
|
|
|
if (FD_ISSET(connection, &ClientsWithInput))
|
|
|
|
FD_SET(connection, &IgnoredClientsWithInput);
|
|
|
|
else
|
|
|
|
FD_CLR(connection, &IgnoredClientsWithInput);
|
|
|
|
FD_CLR(connection, &ClientsWithInput);
|
|
|
|
FD_CLR(connection, &AllSockets);
|
|
|
|
FD_CLR(connection, &AllClients);
|
|
|
|
FD_CLR(connection, &LastSelectMask);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
else {
|
|
|
|
if (FD_ISSET(connection, &SavedClientsWithInput))
|
|
|
|
FD_SET(connection, &IgnoredClientsWithInput);
|
|
|
|
else
|
|
|
|
FD_CLR(connection, &IgnoredClientsWithInput);
|
|
|
|
FD_CLR(connection, &SavedClientsWithInput);
|
|
|
|
FD_CLR(connection, &SavedAllSockets);
|
|
|
|
FD_CLR(connection, &SavedAllClients);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************
|
|
|
|
* AttendClient
|
|
|
|
* Adds one client back into the input masks.
|
|
|
|
****************/
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2012-03-21 20:55:09 +01:00
|
|
|
AttendClient(ClientPtr client)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
OsCommPtr oc = (OsCommPtr) client->osPrivate;
|
2003-11-14 16:54:54 +01:00
|
|
|
int connection = oc->fd;
|
2010-06-30 16:59:04 +02:00
|
|
|
|
|
|
|
client->ignoreCount--;
|
|
|
|
if (client->ignoreCount)
|
2012-03-21 20:55:09 +01:00
|
|
|
return;
|
2010-06-30 16:59:04 +02:00
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
if (!GrabInProgress || GrabInProgress == client->index ||
|
2012-03-21 20:55:09 +01:00
|
|
|
FD_ISSET(connection, &GrabImperviousClients)) {
|
|
|
|
FD_SET(connection, &AllClients);
|
|
|
|
FD_SET(connection, &AllSockets);
|
|
|
|
FD_SET(connection, &LastSelectMask);
|
|
|
|
if (FD_ISSET(connection, &IgnoredClientsWithInput))
|
|
|
|
FD_SET(connection, &ClientsWithInput);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
else {
|
|
|
|
FD_SET(connection, &SavedAllClients);
|
|
|
|
FD_SET(connection, &SavedAllSockets);
|
|
|
|
if (FD_ISSET(connection, &IgnoredClientsWithInput))
|
|
|
|
FD_SET(connection, &SavedClientsWithInput);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make client impervious to grabs; assume only executing client calls this */
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2003-11-25 20:29:01 +01:00
|
|
|
MakeClientGrabImpervious(ClientPtr client)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
OsCommPtr oc = (OsCommPtr) client->osPrivate;
|
2003-11-14 16:54:54 +01:00
|
|
|
int connection = oc->fd;
|
|
|
|
|
|
|
|
FD_SET(connection, &GrabImperviousClients);
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
if (ServerGrabCallback) {
|
|
|
|
ServerGrabInfoRec grabinfo;
|
|
|
|
|
|
|
|
grabinfo.client = client;
|
|
|
|
grabinfo.grabstate = CLIENT_IMPERVIOUS;
|
|
|
|
CallCallbacks(&ServerGrabCallback, &grabinfo);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make client pervious to grabs; assume only executing client calls this */
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 08:43:34 +01:00
|
|
|
void
|
2003-11-25 20:29:01 +01:00
|
|
|
MakeClientGrabPervious(ClientPtr client)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2012-03-21 20:55:09 +01:00
|
|
|
OsCommPtr oc = (OsCommPtr) client->osPrivate;
|
2003-11-14 16:54:54 +01:00
|
|
|
int connection = oc->fd;
|
|
|
|
|
|
|
|
FD_CLR(connection, &GrabImperviousClients);
|
2012-03-21 20:55:09 +01:00
|
|
|
if (GrabInProgress && (GrabInProgress != client->index)) {
|
|
|
|
if (FD_ISSET(connection, &ClientsWithInput)) {
|
|
|
|
FD_SET(connection, &SavedClientsWithInput);
|
|
|
|
FD_CLR(connection, &ClientsWithInput);
|
|
|
|
}
|
|
|
|
FD_CLR(connection, &AllSockets);
|
|
|
|
FD_CLR(connection, &AllClients);
|
|
|
|
isItTimeToYield = TRUE;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
if (ServerGrabCallback) {
|
|
|
|
ServerGrabInfoRec grabinfo;
|
|
|
|
|
|
|
|
grabinfo.client = client;
|
|
|
|
grabinfo.grabstate = CLIENT_PERVIOUS;
|
|
|
|
CallCallbacks(&ServerGrabCallback, &grabinfo);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-19 06:05:58 +01:00
|
|
|
/* Add a fd (from launchd or similar) to our listeners */
|
2012-03-21 20:55:09 +01:00
|
|
|
void
|
|
|
|
ListenOnOpenFD(int fd, int noxauth)
|
|
|
|
{
|
2008-08-06 19:23:31 +02:00
|
|
|
char port[256];
|
2008-05-19 08:31:41 +02:00
|
|
|
XtransConnInfo ciptr;
|
2010-04-14 18:06:04 +02:00
|
|
|
const char *display_env = getenv("DISPLAY");
|
2008-08-06 19:23:31 +02:00
|
|
|
|
2012-03-21 20:55:09 +01:00
|
|
|
if (display_env && (strncmp(display_env, "/tmp/launch", 11) == 0)) {
|
2008-08-06 19:23:31 +02:00
|
|
|
/* Make the path the launchd socket if our DISPLAY is set right */
|
2010-04-14 18:06:04 +02:00
|
|
|
strcpy(port, display_env);
|
2012-03-21 20:55:09 +01:00
|
|
|
}
|
|
|
|
else {
|
2008-08-06 19:23:31 +02:00
|
|
|
/* Just some default so things don't break and die. */
|
2011-10-29 20:08:17 +02:00
|
|
|
snprintf(port, sizeof(port), ":%d", atoi(display));
|
2008-08-06 19:23:31 +02:00
|
|
|
}
|
2008-05-17 23:56:53 +02:00
|
|
|
|
|
|
|
/* Make our XtransConnInfo
|
|
|
|
* TRANS_SOCKET_LOCAL_INDEX = 5 from Xtrans.c
|
|
|
|
*/
|
|
|
|
ciptr = _XSERVTransReopenCOTSServer(5, fd, port);
|
2012-03-21 20:55:09 +01:00
|
|
|
if (ciptr == NULL) {
|
2014-03-19 06:05:58 +01:00
|
|
|
ErrorF("Got NULL while trying to Reopen listen port.\n");
|
2008-05-17 23:56:53 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-03-21 20:55:09 +01:00
|
|
|
|
|
|
|
if (noxauth)
|
2008-08-06 19:23:31 +02:00
|
|
|
ciptr->flags = ciptr->flags | TRANS_NOXAUTH;
|
|
|
|
|
2008-05-17 23:56:53 +02:00
|
|
|
/* Allocate space to store it */
|
2012-03-21 20:55:09 +01:00
|
|
|
ListenTransFds =
|
2015-03-21 18:08:25 +01:00
|
|
|
xnfreallocarray(ListenTransFds, ListenTransCount + 1, sizeof(int));
|
2012-03-21 20:55:09 +01:00
|
|
|
ListenTransConns =
|
2015-03-21 18:08:25 +01:00
|
|
|
xnfreallocarray(ListenTransConns, ListenTransCount + 1,
|
|
|
|
sizeof(XtransConnInfo));
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2008-05-17 23:56:53 +02:00
|
|
|
/* Store it */
|
|
|
|
ListenTransConns[ListenTransCount] = ciptr;
|
|
|
|
ListenTransFds[ListenTransCount] = fd;
|
|
|
|
|
2015-11-12 07:02:17 +01:00
|
|
|
SetNotifyFd(fd, QueueNewConnections, X_NOTIFY_READ, NULL);
|
2012-03-21 20:55:09 +01:00
|
|
|
|
2008-05-17 23:56:53 +02:00
|
|
|
/* Increment the count */
|
|
|
|
ListenTransCount++;
|
|
|
|
}
|
2014-03-20 04:46:41 +01:00
|
|
|
|
|
|
|
/* based on TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status) */
|
|
|
|
Bool
|
|
|
|
AddClientOnOpenFD(int fd)
|
|
|
|
{
|
|
|
|
XtransConnInfo ciptr;
|
|
|
|
CARD32 connect_time;
|
|
|
|
char port[20];
|
|
|
|
|
|
|
|
snprintf(port, sizeof(port), ":%d", atoi(display));
|
|
|
|
ciptr = _XSERVTransReopenCOTSServer(5, fd, port);
|
|
|
|
if (ciptr == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
_XSERVTransSetOption(ciptr, TRANS_NONBLOCKING, 1);
|
|
|
|
ciptr->flags |= TRANS_NOXAUTH;
|
|
|
|
|
|
|
|
connect_time = GetTimeInMillis();
|
|
|
|
|
|
|
|
if (!AllocNewConnection(ciptr, fd, connect_time)) {
|
|
|
|
ErrorConnMax(ciptr);
|
|
|
|
_XSERVTransClose(ciptr);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|