Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

always use the passed fd in generated saferead() and safewrite() functions #272

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions qmail-pop3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ void die() { _exit(0); }

extern int rename(const char *, const char *);

GEN_SAFE_TIMEOUTREAD(saferead,1200,fd,die())
GEN_SAFE_TIMEOUTWRITE(safewrite,1200,fd,die())
GEN_SAFE_TIMEOUTREAD(saferead,1200,die())
GEN_SAFE_TIMEOUTWRITE(safewrite,1200,die())

char sserrbuf[128];
substdio sserr = SUBSTDIO_FDBUF(safewrite,2,sserrbuf,sizeof(sserrbuf));
Expand Down
4 changes: 2 additions & 2 deletions qmail-popup.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

void _noreturn_ die() { _exit(1); }

GEN_SAFE_TIMEOUTREAD(saferead,1200,fd,die())
GEN_SAFE_TIMEOUTWRITE(safewrite,1200,fd,die())
GEN_SAFE_TIMEOUTREAD(saferead,1200,die())
GEN_SAFE_TIMEOUTWRITE(safewrite,1200,die())

char ssoutbuf[128];
substdio ssout = SUBSTDIO_FDBUF(safewrite,1,ssoutbuf,sizeof(ssoutbuf));
Expand Down
7 changes: 5 additions & 2 deletions qmail-qmqpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ void die_format() { _exit(91); }
int lasterror = 55;
int qmqpfd;

GEN_SAFE_TIMEOUTREAD(saferead,60,qmqpfd,die_conn())
GEN_SAFE_TIMEOUTWRITE(safewrite,60,qmqpfd,die_conn())
GEN_SAFE_TIMEOUTREAD(saferead,60,die_conn())
GEN_SAFE_TIMEOUTWRITE(safewrite,60,die_conn())

char buf[1024];
substdio to = SUBSTDIO_FDBUF(safewrite,-1,buf,sizeof(buf));
Expand Down Expand Up @@ -98,6 +98,9 @@ char *server;
qmqpfd = socket(AF_INET,SOCK_STREAM,0);
if (qmqpfd == -1) die_socket();

to.fd = qmqpfd;
from.fd = qmqpfd;

if (timeoutconn(qmqpfd,&ip,PORT_QMQP,10) != 0) {
lasterror = 73;
if (errno == error_timeout) lasterror = 72;
Expand Down
9 changes: 6 additions & 3 deletions qmail-remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ int timeoutconnect = 60;
int smtpfd;
int timeout = 1200;

GEN_SAFE_TIMEOUTREAD(saferead,timeout,smtpfd,dropped())
GEN_SAFE_TIMEOUTWRITE(safewrite,timeout,smtpfd,dropped())
GEN_SAFE_TIMEOUTREAD(saferead,timeout,dropped())
GEN_SAFE_TIMEOUTWRITE(safewrite,timeout,dropped())

char inbuf[1024];
substdio ssin = SUBSTDIO_FDBUF(read,0,inbuf,sizeof(inbuf));
Expand Down Expand Up @@ -393,7 +393,10 @@ int main(int argc, char **argv)

smtpfd = socket(AF_INET,SOCK_STREAM,0);
if (smtpfd == -1) temp_oserr();


smtpto.fd = smtpfd;
smtpfrom.fd = smtpfd;

if (timeoutconn(smtpfd,&ip.ix[i].ip,(unsigned int) port,timeoutconnect) == 0) {
tcpto_err(&ip.ix[i].ip,0);
partner = ip.ix[i].ip;
Expand Down
2 changes: 1 addition & 1 deletion qmail-smtpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
unsigned int databytes = 0;
int timeout = 1200;

GEN_SAFE_TIMEOUTWRITE(safewrite,timeout,fd,_exit(1))
GEN_SAFE_TIMEOUTWRITE(safewrite,timeout,_exit(1))

char ssoutbuf[512];
substdio ssout = SUBSTDIO_FDBUF(safewrite,1,ssoutbuf,sizeof(ssoutbuf));
Expand Down
4 changes: 2 additions & 2 deletions timeoutread.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

extern ssize_t timeoutread(int t, int fd, char *buf, size_t len);

#define GEN_SAFE_TIMEOUTREAD(funcname,tout,readfd,doexit) \
#define GEN_SAFE_TIMEOUTREAD(funcname,tout,doexit) \
ssize_t funcname(int fd, void *buf, size_t len) \
{ \
ssize_t r; \
r = timeoutread(tout,readfd,buf,len); \
r = timeoutread(tout,fd,buf,len); \
if (r == 0 || r == -1) doexit; \
return r; \
}
Expand Down
4 changes: 2 additions & 2 deletions timeoutwrite.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

extern ssize_t timeoutwrite(int t, int fd, const void *buf, size_t len);

#define GEN_SAFE_TIMEOUTWRITE(funcname,tout,writefd,doexit) \
#define GEN_SAFE_TIMEOUTWRITE(funcname,tout,doexit) \
ssize_t funcname(int fd, const void *buf, size_t len) \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fd argument was never used there. Maybe an omission or a change of mind mid-way...
This sounds like pursuing some work, makes sense to me.
Thank you!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely. Some callers passed "fd" as the "writefd" macro argument, so they actually used the fd passed to the function. And now just all do.

{ \
ssize_t r; \
r = timeoutwrite(tout,writefd,buf,len); \
r = timeoutwrite(tout,fd,buf,len); \
if (r == 0 || r == -1) doexit; \
return r; \
}
Expand Down