From 107cbb10157b165e19ed2f7fb747c60c670fe6c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 11 Jul 2021 10:22:47 +0200 Subject: [PATCH] =?UTF-8?q?shm:=20close=20pool=20FD=20if=20buffer=20doesn?= =?UTF-8?q?=E2=80=99t=20support=20SHM=20scrolling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The only reason to keep the pool FD open is if we’re going to SHM scroll the buffer; we need the FD for fallocate(FALLOC_FL_PUNCH_HOLE). In all other cases, there’s absolutely no need to keep the FD open. Thus, close it as soon as we’ve instantiated the buffer. This frees up FDs, and help keep foot from FD ulimit. --- shm.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/shm.c b/shm.c index ed20af3a..00804400 100644 --- a/shm.c +++ b/shm.c @@ -156,7 +156,6 @@ page_size(void) static bool instantiate_offset(struct wl_shm *shm, struct buffer *buf, off_t new_offset) { - xassert(buf->fd >= 0); xassert(buf->mmapped == NULL); xassert(buf->wl_buf == NULL); xassert(buf->pix == NULL); @@ -417,6 +416,12 @@ shm_get_buffer(struct wl_shm *shm, int width, int height, unsigned long cookie, } #endif + if (!shm_can_scroll(ret)) { + /* We only need to keep the pool FD open if we’re going to SHM + * scroll it */ + close(pool_fd); + } + return ret; err: