mirror of
https://github.com/openbsd/xenocara.git
synced 2025-12-12 20:29:12 +00:00
try to handle running out of file descriptors by refusing client connections
in case the X server is near the limit and only allow connections again if there are resources freed up this is done by checking the amount of currently used FDs + a reserve and comparing that to the FD limit with help from benno@, millert@, florian@ ok matthieu@, benno@
This commit is contained in:
@@ -148,6 +148,9 @@ static int ListenTransCount;
|
|||||||
|
|
||||||
static void ErrorConnMax(XtransConnInfo /* trans_conn */ );
|
static void ErrorConnMax(XtransConnInfo /* trans_conn */ );
|
||||||
|
|
||||||
|
static int FdReserve = 5;
|
||||||
|
static Bool Backoff = FALSE;
|
||||||
|
|
||||||
static XtransConnInfo
|
static XtransConnInfo
|
||||||
lookup_trans_conn(int fd)
|
lookup_trans_conn(int fd)
|
||||||
{
|
{
|
||||||
@@ -689,6 +692,11 @@ EstablishNewConnections(ClientPtr clientUnused, void *closure)
|
|||||||
if ((trans_conn = lookup_trans_conn(curconn)) == NULL)
|
if ((trans_conn = lookup_trans_conn(curconn)) == NULL)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
if ((getdtablecount() + FdReserve) >= getdtablesize())
|
||||||
|
Backoff = TRUE;
|
||||||
|
else
|
||||||
|
Backoff = FALSE;
|
||||||
|
|
||||||
if ((new_trans_conn = _XSERVTransAccept(trans_conn, &status)) == NULL)
|
if ((new_trans_conn = _XSERVTransAccept(trans_conn, &status)) == NULL)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
@@ -699,7 +707,7 @@ EstablishNewConnections(ClientPtr clientUnused, void *closure)
|
|||||||
if (trans_conn->flags & TRANS_NOXAUTH)
|
if (trans_conn->flags & TRANS_NOXAUTH)
|
||||||
new_trans_conn->flags = new_trans_conn->flags | TRANS_NOXAUTH;
|
new_trans_conn->flags = new_trans_conn->flags | TRANS_NOXAUTH;
|
||||||
|
|
||||||
if (!AllocNewConnection(new_trans_conn, newconn, connect_time)) {
|
if (Backoff || !AllocNewConnection(new_trans_conn, newconn, connect_time)) {
|
||||||
ErrorConnMax(new_trans_conn);
|
ErrorConnMax(new_trans_conn);
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -753,6 +761,8 @@ ConnMaxNotify(int fd, int events, void *data)
|
|||||||
}
|
}
|
||||||
RemoveNotifyFd(trans_conn->fd);
|
RemoveNotifyFd(trans_conn->fd);
|
||||||
_XSERVTransClose(trans_conn);
|
_XSERVTransClose(trans_conn);
|
||||||
|
|
||||||
|
Backoff = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
Reference in New Issue
Block a user