aboutsummaryrefslogtreecommitdiff
path: root/nx-X11
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2017-03-15 15:16:37 +0000
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2017-03-21 10:58:08 +0100
commitc468be804ec48231db12f504c2d877ef7a11adc1 (patch)
treeab68d1908fa18b1ffc8ad7640566fc25f56370ec /nx-X11
parent3be144ffde5f35df21ad115cbdedb8a072420edb (diff)
downloadnx-libs-c468be804ec48231db12f504c2d877ef7a11adc1.tar.gz
nx-libs-c468be804ec48231db12f504c2d877ef7a11adc1.tar.bz2
nx-libs-c468be804ec48231db12f504c2d877ef7a11adc1.zip
os: Use NotifyFd interface for listen descriptors
Bundle X.org backport of these commits: commit 7ea64fb4374504bd3d524fc08c90efdab9f253ea Author: Alan Coopersmith <alan.coopersmith@oracle.com> Date: Mon Mar 9 09:55:57 2015 -0700 Clear ListenTransConns entries in CloseWellKnownConnections Since _XSERVTransClose frees the connection pointer passed to it, remove that pointer from the array, so we don't try to double free it if we come back into CloseWellKnownConnections again. Should fix https://bugzilla.yoctoproject.org/show_bug.cgi?id=6665 in which the shutdown section of the main() loop called CloseWellKnownConnections() and then moved on to ddxGiveUp(), which failed to release the VT and thus called AbortServer(), which called CloseWellKnownConnections() again. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com> Reviewed-by: Adam Jackson <ajax@redhat.com> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> commit 7b02f0b87ec2fa0cc5a65307a1fd55c671cec884 Author: Keith Packard <keithp@keithp.com> Date: Wed Nov 11 22:02:17 2015 -0800 os: Use NotifyFd interface for listen descriptors Replace the custom path for dealing with new incoming connections with the general-purpose NotifyFd API. Reviewed-by: Adam Jackson <ajax@redhat.com> Signed-off-by: Keith Packard <keithp@keithp.com> commit ba71b69f94f00a6f6910597185610668e79c10be Author: Alan Coopersmith <alan.coopersmith@oracle.com> Date: Fri Jan 1 17:34:41 2016 -0800 Avoid segfault in CloseWellKnownConnections when using -displayfd When -displayfd is looping through the possible display ids to use, if it can't open all the listening sockets for one (say when :0 is already in use), it calls CloseWellKnownConnections to close all the ListenTransConns entries before the point that ListenTransFds was allocated & initialized, so CloseWellKnownConnections would segfault trying to read entries from a NULL ListenTransFds pointer. Introduced by commit 7b02f0b8 Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com> Reviewed-by: Keith Packard <keithp@keithp.com> Backported-to-NX-by: Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
Diffstat (limited to 'nx-X11')
-rw-r--r--nx-X11/programs/Xserver/include/os.h4
-rw-r--r--nx-X11/programs/Xserver/os/WaitFor.c4
-rw-r--r--nx-X11/programs/Xserver/os/connection.c119
3 files changed, 53 insertions, 74 deletions
diff --git a/nx-X11/programs/Xserver/include/os.h b/nx-X11/programs/Xserver/include/os.h
index 5dd5e2012..1af34a04c 100644
--- a/nx-X11/programs/Xserver/include/os.h
+++ b/nx-X11/programs/Xserver/include/os.h
@@ -137,10 +137,6 @@ extern char *ClientAuthorized(
unsigned int /*string_n*/,
char* /*auth_string*/);
-extern Bool EstablishNewConnections(
- ClientPtr /*clientUnused*/,
- void * /*closure*/);
-
extern void CheckConnections(void);
extern void CloseDownConnection(ClientPtr /*client*/);
diff --git a/nx-X11/programs/Xserver/os/WaitFor.c b/nx-X11/programs/Xserver/os/WaitFor.c
index 4d7fe3f84..76e5da5f2 100644
--- a/nx-X11/programs/Xserver/os/WaitFor.c
+++ b/nx-X11/programs/Xserver/os/WaitFor.c
@@ -495,10 +495,6 @@ WaitForSomething(int *pClientsReady)
}
XFD_ANDSET(&clientsReadable, &LastSelectMask, &AllClients);
- XFD_ANDSET(&tmp_set, &LastSelectMask, &WellKnownConnections);
- if (XFD_ANYSET(&tmp_set))
- QueueWorkProc(EstablishNewConnections, NULL,
- (void *)&LastSelectMask);
XFD_ANDSET(&tmp_set, &LastSelectMask, &NotifyReadFds);
if (XFD_ANYSET(&tmp_set) || someNotifyWriteReady)
diff --git a/nx-X11/programs/Xserver/os/connection.c b/nx-X11/programs/Xserver/os/connection.c
index 7638cdfdd..b251c2f5c 100644
--- a/nx-X11/programs/Xserver/os/connection.c
+++ b/nx-X11/programs/Xserver/os/connection.c
@@ -123,7 +123,6 @@ SOFTWARE.
int lastfdesc; /* maximum file descriptor */
-fd_set WellKnownConnections; /* Listener mask */
fd_set NotifyReadFds; /* mask for other file descriptors */
fd_set NotifyWriteFds; /* mask for other write file descriptors */
fd_set AllSockets; /* select on this */
@@ -152,6 +151,9 @@ static fd_set SavedAllSockets;
static fd_set SavedClientsWithInput;
int GrabInProgress = 0;
+static void
+QueueNewConnections(int curconn, int ready, void *data);
+
#if !defined(WIN32)
int *ConnectionTranslation = NULL;
#else
@@ -407,8 +409,6 @@ CreateWellKnownSockets(void)
ClearConnectionTranslation();
#endif
- FD_ZERO (&WellKnownConnections);
-
/* display is initialized to "0" by main(). It is then set to the display
* number if specified on the command line. */
if (NoListenAll) {
@@ -442,13 +442,13 @@ CreateWellKnownSockets(void)
int fd = _XSERVTransGetConnectionNumber(ListenTransConns[i]);
ListenTransFds[i] = fd;
- FD_SET(fd, &WellKnownConnections);
+ SetNotifyFd(fd, QueueNewConnections, X_NOTIFY_READ, NULL);
if (!_XSERVTransIsLocal(ListenTransConns[i]))
DefineSelf (fd);
}
- if (!XFD_ANYSET (&WellKnownConnections) && !NoListenAll)
+ if (ListenTransCount == 0 && !NoListenAll)
FatalError ("Cannot establish any listening sockets - Make sure an X server isn't already running");
#if !defined(WIN32)
OsSignal (SIGPIPE, SIG_IGN);
@@ -456,7 +456,6 @@ CreateWellKnownSockets(void)
#endif
OsSignal (SIGINT, GiveUp);
OsSignal (SIGTERM, GiveUp);
- XFD_COPYSET (&WellKnownConnections, &AllSockets);
ResetHosts(display);
InitParentProcess();
@@ -525,7 +524,7 @@ ResetWellKnownSockets (void)
* Remove it from out list.
*/
- FD_CLR (ListenTransFds[i], &WellKnownConnections);
+ RemoveNotifyFd(ListenTransFds[i]);
ListenTransFds[i] = ListenTransFds[ListenTransCount - 1];
ListenTransConns[i] = ListenTransConns[ListenTransCount - 1];
ListenTransCount -= 1;
@@ -539,13 +538,14 @@ ResetWellKnownSockets (void)
int newfd = _XSERVTransGetConnectionNumber (ListenTransConns[i]);
- FD_CLR (ListenTransFds[i], &WellKnownConnections);
ListenTransFds[i] = newfd;
- FD_SET(newfd, &WellKnownConnections);
}
}
}
+ for (i = 0; i < ListenTransCount; i++)
+ SetNotifyFd(ListenTransFds[i], QueueNewConnections, X_NOTIFY_READ, NULL);
+
ResetAuthorization ();
ResetHosts(display);
/*
@@ -561,8 +561,15 @@ CloseWellKnownConnections(void)
{
int i;
- for (i = 0; i < ListenTransCount; i++)
- _XSERVTransClose (ListenTransConns[i]);
+ for (i = 0; i < ListenTransCount; i++) {
+ if (ListenTransConns[i] != NULL) {
+ _XSERVTransClose(ListenTransConns[i]);
+ ListenTransConns[i] = NULL;
+ if (ListenTransFds != NULL)
+ RemoveNotifyFd(ListenTransFds[i]);
+ }
+ }
+ ListenTransCount = 0;
}
static void
@@ -827,23 +834,18 @@ AllocNewConnection (XtransConnInfo trans_conn, int fd, CARD32 conn_time)
* and AllSockets.
*****************/
-/*ARGSUSED*/
-Bool
+static Bool
EstablishNewConnections(ClientPtr clientUnused, void * closure)
{
- fd_set readyconnections; /* set of listeners that are ready */
- int curconn; /* fd of listener that's ready */
- register int newconn; /* fd of new client */
+ int curconn = (int) (intptr_t) closure;
+ int newconn; /* fd of new client */
CARD32 connect_time;
- register int i;
- register ClientPtr client;
- register OsCommPtr oc;
- fd_set tmask;
-
- XFD_ANDSET (&tmask, (fd_set*)closure, &WellKnownConnections);
- XFD_COPYSET(&tmask, &readyconnections);
- if (!XFD_ANYSET(&readyconnections))
- return TRUE;
+ int i;
+ ClientPtr client;
+ OsCommPtr oc;
+ XtransConnInfo trans_conn, new_trans_conn;
+ int status;
+
connect_time = GetTimeInMillis();
/* kill off stragglers */
for (i=1; i<currentMaxClients; i++)
@@ -857,59 +859,44 @@ EstablishNewConnections(ClientPtr clientUnused, void * closure)
CloseDownClient(client);
}
}
-#ifndef WIN32
- for (i = 0; i < howmany(XFD_SETSIZE, NFDBITS); i++)
- {
- while (readyconnections.fds_bits[i])
-#else
- for (i = 0; i < XFD_SETCOUNT(&readyconnections); i++)
-#endif
- {
- XtransConnInfo trans_conn, new_trans_conn;
- int status;
-
-#ifndef WIN32
- curconn = ffs (readyconnections.fds_bits[i]) - 1;
- readyconnections.fds_bits[i] &= ~((fd_mask)1 << curconn);
- curconn += (i * (sizeof(fd_mask)*8));
-#else
- curconn = XFD_FD(&readyconnections, i);
-#endif
+ if ((trans_conn = lookup_trans_conn(curconn)) == NULL)
+ return TRUE;
- if ((trans_conn = lookup_trans_conn (curconn)) == NULL)
- continue;
+ if ((new_trans_conn = _XSERVTransAccept(trans_conn, &status)) == NULL)
+ return TRUE;
- if ((new_trans_conn = _XSERVTransAccept (trans_conn, &status)) == NULL)
- continue;
+ newconn = _XSERVTransGetConnectionNumber(new_trans_conn);
- newconn = _XSERVTransGetConnectionNumber (new_trans_conn);
+ if (newconn < lastfdesc) {
+ int clientid;
- if (newconn < lastfdesc)
- {
- int clientid;
#if !defined(WIN32)
- clientid = ConnectionTranslation[newconn];
+ clientid = ConnectionTranslation[newconn];
#else
- clientid = GetConnectionTranslation(newconn);
+ clientid = GetConnectionTranslation(newconn);
#endif
- if(clientid && (client = clients[clientid]))
- CloseDownClient(client);
- }
+ if (clientid && (client = clients[clientid]))
+ CloseDownClient(client);
+ }
- _XSERVTransSetOption(new_trans_conn, TRANS_NONBLOCKING, 1);
+ _XSERVTransSetOption(new_trans_conn, TRANS_NONBLOCKING, 1);
+
+ if (trans_conn->flags & TRANS_NOXAUTH)
+ new_trans_conn->flags = new_trans_conn->flags | TRANS_NOXAUTH;
+
+ if (!AllocNewConnection(new_trans_conn, newconn, connect_time)) {
+ ErrorConnMax(new_trans_conn);
+ }
- if (!AllocNewConnection (new_trans_conn, newconn, connect_time
- ))
- {
- ErrorConnMax(new_trans_conn);
- }
- }
-#ifndef WIN32
- }
-#endif
return TRUE;
}
+static void
+QueueNewConnections(int fd, int ready, void *data)
+{
+ QueueWorkProc(EstablishNewConnections, NULL, (void *) (intptr_t) fd);
+}
+
#define NOROOM "Maximum number of clients reached"
/************