From f48b0534f110397246809d279225afedb28aa233 Mon Sep 17 00:00:00 2001 From: Marek Chalupa Date: Mon, 25 Apr 2016 11:33:00 +0200 Subject: [PATCH] xwayland-shm: fortify fallocate against EINTR If posix_fallocate or ftruncate is interrupted by signal while working, we return -1 as fd and the allocation process returns BadAlloc error. That causes xwayland clients to abort with 'BadAlloc (insufficient resources for operation)' even when there's a lot of resources available. Fix it by trying again when we get EINTR. Signed-off-by: Marek Chalupa Reviewed-by: Pekka Paalanen --- hw/xwayland/xwayland-shm.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/xwayland/xwayland-shm.c b/hw/xwayland/xwayland-shm.c index e8545b3be..c199e5efb 100644 --- a/hw/xwayland/xwayland-shm.c +++ b/hw/xwayland/xwayland-shm.c @@ -140,14 +140,20 @@ os_create_anonymous_file(off_t size) return -1; #ifdef HAVE_POSIX_FALLOCATE - ret = posix_fallocate(fd, 0, size); + do { + ret = posix_fallocate(fd, 0, size); + } while (ret == EINTR); + if (ret != 0) { close(fd); errno = ret; return -1; } #else - ret = ftruncate(fd, size); + do { + ret = ftruncate(fd, size); + } while (ret == -1 && errno == EINTR); + if (ret < 0) { close(fd); return -1;