nightmaremail

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit ac7b99eb0c8f24cb54babd03f206ccad6b150ed1
parent ec5d57bd0530d190fb0eec2552caadcc7944ac02
Author: Rolf Eike Beer <eike@sf-mail.de>
Date:   Mon,  9 Nov 2020 17:34:34 +0100

add generator macros for substdio wrappers around timeoutread() and timeoutwrite()

Diffstat:
Mqmail-pop3d.c | 17++---------------
Mqmail-popup.c | 17++---------------
Mqmail-qmqpc.c | 16++--------------
Mqmail-remote.c | 17++---------------
Mqmail-smtpd.c | 9+--------
Mtimeoutread.h | 9+++++++++
Mtimeoutwrite.h | 9+++++++++
7 files changed, 27 insertions(+), 67 deletions(-)

diff --git a/qmail-pop3d.c b/qmail-pop3d.c @@ -24,21 +24,8 @@ void die() { _exit(0); } extern int rename(const char *, const char *); -ssize_t saferead(int fd, void *buf, size_t len) -{ - ssize_t r; - r = timeoutread(1200,fd,buf,len); - if (r == 0 || r == -1) die(); - return r; -} - -ssize_t safewrite(int fd, const void *buf, size_t len) -{ - ssize_t r; - r = timeoutwrite(1200,fd,buf,len); - if (r == 0 || r == -1) die(); - return r; -} +GEN_SAFE_TIMEOUTREAD(saferead,1200,fd,die()) +GEN_SAFE_TIMEOUTWRITE(safewrite,1200,fd,die()) char sserrbuf[128]; substdio sserr = SUBSTDIO_FDBUF(safewrite,2,sserrbuf,sizeof sserrbuf); diff --git a/qmail-popup.c b/qmail-popup.c @@ -16,21 +16,8 @@ void die() { _exit(1); } -ssize_t saferead(int fd, void *buf, size_t len) -{ - ssize_t r; - r = timeoutread(1200,fd,buf,len); - if (r == 0 || r == -1) die(); - return r; -} - -ssize_t safewrite(int fd, const void *buf, size_t len) -{ - ssize_t r; - r = timeoutwrite(1200,fd,buf,len); - if (r == 0 || r == -1) die(); - return r; -} +GEN_SAFE_TIMEOUTREAD(saferead,1200,fd,die()) +GEN_SAFE_TIMEOUTWRITE(safewrite,1200,fd,die()) char ssoutbuf[128]; substdio ssout = SUBSTDIO_FDBUF(safewrite,1,ssoutbuf,sizeof ssoutbuf); diff --git a/qmail-qmqpc.c b/qmail-qmqpc.c @@ -34,20 +34,8 @@ void die_format() { _exit(91); } int lasterror = 55; int qmqpfd; -ssize_t saferead(int fd, void *buf, size_t len) -{ - ssize_t r; - r = timeoutread(60,qmqpfd,buf,len); - if (r == 0 || r == -1) die_conn(); - return r; -} -ssize_t safewrite(int fd, const void *buf, size_t len) -{ - ssize_t r; - r = timeoutwrite(60,qmqpfd,buf,len); - if (r == 0 || r == -1) die_conn(); - return r; -} +GEN_SAFE_TIMEOUTREAD(saferead,60,qmqpfd,die_conn()) +GEN_SAFE_TIMEOUTWRITE(safewrite,60,qmqpfd,die_conn()) char buf[1024]; substdio to = SUBSTDIO_FDBUF(safewrite,-1,buf,sizeof buf); diff --git a/qmail-remote.c b/qmail-remote.c @@ -106,21 +106,8 @@ int timeoutconnect = 60; int smtpfd; int timeout = 1200; -ssize_t saferead(int fd, void *buf, size_t len) -{ - ssize_t r; - r = timeoutread(timeout,smtpfd,buf,len); - if (r == 0 || r == -1) dropped(); - return r; -} - -ssize_t safewrite(int fd, const void *buf, size_t len) -{ - ssize_t r; - r = timeoutwrite(timeout,smtpfd,buf,len); - if (r == 0 || r == -1) dropped(); - return r; -} +GEN_SAFE_TIMEOUTREAD(saferead,timeout,smtpfd,dropped()) +GEN_SAFE_TIMEOUTWRITE(safewrite,timeout,smtpfd,dropped()) char inbuf[1024]; substdio ssin = SUBSTDIO_FDBUF(read,0,inbuf,sizeof inbuf); diff --git a/qmail-smtpd.c b/qmail-smtpd.c @@ -29,13 +29,7 @@ unsigned int databytes = 0; int timeout = 1200; -ssize_t safewrite(int fd, const void *buf, size_t len) -{ - ssize_t r; - r = timeoutwrite(timeout,fd,buf,len); - if (r == 0 || r == -1) _exit(1); - return r; -} +GEN_SAFE_TIMEOUTWRITE(safewrite,timeout,fd,_exit(1)) char ssoutbuf[512]; substdio ssout = SUBSTDIO_FDBUF(safewrite,1,ssoutbuf,sizeof ssoutbuf); @@ -265,7 +259,6 @@ void smtp_rcpt(arg) char *arg; { out("250 ok\r\n"); } - ssize_t saferead(int fd, void *buf, size_t len) { ssize_t r; diff --git a/timeoutread.h b/timeoutread.h @@ -5,4 +5,13 @@ extern ssize_t timeoutread(int t, int fd, char *buf, size_t len); +#define GEN_SAFE_TIMEOUTREAD(funcname,tout,readfd,doexit) \ +ssize_t funcname(int fd, void *buf, size_t len) \ +{ \ + ssize_t r; \ + r = timeoutread(tout,readfd,buf,len); \ + if (r == 0 || r == -1) doexit; \ + return r; \ +} + #endif diff --git a/timeoutwrite.h b/timeoutwrite.h @@ -5,4 +5,13 @@ extern ssize_t timeoutwrite(int t, int fd, const void *buf, size_t len); +#define GEN_SAFE_TIMEOUTWRITE(funcname,tout,writefd,doexit) \ +ssize_t funcname(int fd, const void *buf, size_t len) \ +{ \ + ssize_t r; \ + r = timeoutwrite(tout,writefd,buf,len); \ + if (r == 0 || r == -1) doexit; \ + return r; \ +} + #endif