From 3e7efbfb36a54e99bda55a0695b645f6a09e99a3 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 23 Aug 2017 12:00:00 +0200 Subject: [PATCH] tdb: Protect against EINTR Signed-off-by: Volker Lendecke Reviewed-by: Andrew Bartlett --- lib/tdb/common/io.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/tdb/common/io.c b/lib/tdb/common/io.c index fe47d18a5a4..1b422affdca 100644 --- a/lib/tdb/common/io.c +++ b/lib/tdb/common/io.c @@ -52,27 +52,48 @@ static bool tdb_adjust_offset(struct tdb_context *tdb, off_t *off) static ssize_t tdb_pwrite(struct tdb_context *tdb, const void *buf, size_t count, off_t offset) { + ssize_t ret; + if (!tdb_adjust_offset(tdb, &offset)) { return -1; } - return pwrite(tdb->fd, buf, count, offset); + + do { + ret = pwrite(tdb->fd, buf, count, offset); + } while ((ret == -1) && (errno == EINTR)); + + return ret; } static ssize_t tdb_pread(struct tdb_context *tdb, void *buf, size_t count, off_t offset) { + ssize_t ret; + if (!tdb_adjust_offset(tdb, &offset)) { return -1; } - return pread(tdb->fd, buf, count, offset); + + do { + ret = pread(tdb->fd, buf, count, offset); + } while ((ret == -1) && (errno == EINTR)); + + return ret; } static int tdb_ftruncate(struct tdb_context *tdb, off_t length) { + ssize_t ret; + if (!tdb_adjust_offset(tdb, &length)) { return -1; } - return ftruncate(tdb->fd, length); + + do { + ret = ftruncate(tdb->fd, length); + } while ((ret == -1) && (errno == EINTR)); + + return ret; } static int tdb_fstat(struct tdb_context *tdb, struct stat *buf)