From fd0e45b7517af63e85cf5e8727ed279e42593a44 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 29 Dec 2015 18:27:53 +0100 Subject: pwriten and preadn block signals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/daemon.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/daemon.c b/src/daemon.c index a8278c4..71e0226 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -21,6 +21,7 @@ */ #include "daemon.h" #include +#include #include #include #include @@ -43,16 +44,27 @@ extern char **environ; #define PIO(FUN) \ char *buffer = buf; \ ssize_t r, n = 0; \ + int saved_errno = 0; \ + sigset_t mask, oldmask; \ + sigfillset(&mask); \ + sigprocmask(SIG_BLOCK, &mask, &oldmask); \ while (nbyte) { \ - r = FUN(fildes, buffer, nbyte, (off_t)offset); \ - if (r < 0) return -1; \ - if (r == 0) break; \ + t (r = FUN(fildes, buffer, nbyte, (off_t)offset), r < 0); \ + if (r == 0) \ + break; \ n += r; \ nbyte -= (size_t)r; \ offset += (size_t)r; \ buffer += (size_t)r; \ } \ - return n +done: \ + sigprocmask(SIG_SETMASK, &oldmask, NULL); \ + errno = saved_errno; \ + return n; \ +fail: \ + saved_errno = errno; \ + n = -1; \ + goto done /** -- cgit v1.2.3-70-g09d2