Applications may end up allocating a bunch of shmfence objects, each of which uses a file descriptor, which must be kept open lest some other client ask for a copy of it later on.
Lacking an API that can turn a memory mapping back into a file descriptor, about the best we can do is push the file descriptors out of the way of other X clients so that we don't run out of the ability to accept new connections. This uses fcntl F_GETFD to push the FD up above MAXCLIENTS. Signed-off-by: Keith Packard <[email protected]> --- This patch has been added to my keithp-fixes branch miext/sync/misyncshm.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/miext/sync/misyncshm.c b/miext/sync/misyncshm.c index 3f9350a..59f99fb 100644 --- a/miext/sync/misyncshm.c +++ b/miext/sync/misyncshm.c @@ -32,6 +32,7 @@ #include "pixmapstr.h" #include <sys/mman.h> #include <unistd.h> +#include <fcntl.h> #include <X11/xshmfence.h> static DevPrivateKeyRec syncShmFencePrivateKey; @@ -120,12 +121,26 @@ miSyncShmScreenDestroyFence(ScreenPtr pScreen, SyncFence * pFence) } static int +miSyncShmMoveFd(int fd) +{ + int newfd; + + newfd = fcntl(fd, F_DUPFD, MAXCLIENTS); + if (newfd < 0) + return fd; + + close(fd); + return newfd; +} + +static int miSyncShmCreateFenceFromFd(ScreenPtr pScreen, SyncFence *pFence, int fd, Bool initially_triggered) { SyncShmFencePrivatePtr pPriv = SYNC_FENCE_PRIV(pFence); miSyncInitFence(pScreen, pFence, initially_triggered); + fd = miSyncShmMoveFd(fd); pPriv->fence = xshmfence_map_shm(fd); if (pPriv->fence) { pPriv->fd = fd; @@ -145,6 +160,7 @@ miSyncShmGetFenceFd(ScreenPtr pScreen, SyncFence *pFence) pPriv->fd = xshmfence_alloc_shm(); if (pPriv->fd < 0) return -1; + pPriv->fd = miSyncShmMoveFd(pPriv->fd); pPriv->fence = xshmfence_map_shm(pPriv->fd); if (!pPriv->fence) { close (pPriv->fd); -- 1.8.4.2 _______________________________________________ [email protected]: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: http://lists.x.org/mailman/listinfo/xorg-devel
