From fc6a52aea07419d4eb1a42458ba2459faf52e4b9 Mon Sep 17 00:00:00 2001 From: ian Date: Sun, 11 Jul 1999 18:15:10 +0000 Subject: [PATCH] Bugfixes; adnstest has ability to use poll(2), and user can set initflags; checkall prints passed list as well as failed list, if any failed. --- changelog | 2 ++ client/adnstest.c | 82 ++++++++++++++++++++++++++++++++++++++++++----- regress/checkall | 6 ++-- src/adns.h | 27 +++++++++------- src/event.c | 6 +++- src/poll.c | 44 +++++++++++++------------ 6 files changed, 124 insertions(+), 43 deletions(-) diff --git a/changelog b/changelog index 207c322..2944a03 100644 --- a/changelog +++ b/changelog @@ -9,6 +9,8 @@ adns (0.3) unstable; urgency=low * New adns_errabbrev() for getting status abbreviation strings. * regress/checkall prints summary list of failed tests, if any. * Event loop functions for poll(2), and some raw variants. + * adnstest has ability to use poll(2), and user can set initflags. + * checkall prints passed list as well as failed list, if any failed. Bugfixes: * Non-RFC822 mailbox `domain' formatting now works, and clarified. diff --git a/client/adnstest.c b/client/adnstest.c index 52344d1..a293d3b 100644 --- a/client/adnstest.c +++ b/client/adnstest.c @@ -26,6 +26,8 @@ #include #include #include +#include +#include #ifndef OUTPUTSTREAM # define OUTPUTSTREAM stdout @@ -91,6 +93,10 @@ static void fdom_split(const char *fdom, const char **dom_r, int *qf_r, *ownflags= 0; } +static int consistsof(const char *string, const char *accept) { + return strspn(string,accept) == strlen(string); +} + int main(int argc, char *const *argv) { adns_state ads; adns_query *qus, qu; @@ -98,19 +104,42 @@ int main(int argc, char *const *argv) { const char *initstring, *rrtn, *fmtn; const char *const *fdomlist, *domain; char *show, *cp; - int len, i, qc, qi, tc, ti, ch, qflags; + int len, i, qc, qi, tc, ti, ch, qflags, initflagsnum, npollfds, npollfdsavail, timeout; + struct pollfd *pollfds; adns_status r, ri; const adns_rrtype *types; struct timeval now; adns_rrtype *types_a; char ownflags[10]; + char *ep; + const char *initflags, *owninitflags; + if (argv[0] && argv[1] && argv[1][0] == '-') { + initflags= argv[1]+1; + argv++; + } else { + initflags= ""; + } if (argv[0] && argv[1] && argv[1][0] == '/') { initstring= argv[1]+1; argv++; } else { initstring= 0; } + + initflagsnum= strtoul(initflags,&ep,0); + if (*ep == ',') { + owninitflags= ep+1; + if (!consistsof(owninitflags,"p")) { + fputs("unknown owninitflag\n",stderr); + exit(4); + } + } else if (!*ep) { + owninitflags= ""; + } else { + fputs("bad [,]\n",stderr); + exit(4); + } if (argv[0] && argv[1] && argv[1][0] == ':') { for (cp= argv[1]+1, tc=1; (ch= *cp); cp++) @@ -121,7 +150,12 @@ int main(int argc, char *const *argv) { types_a[ti]= strtoul(cp,&cp,10); if ((ch= *cp)) { if (ch != ',') { - fputs("usage: dtest [/] [:,...] [ ...]\n",stderr); + fputs("usage: adnstest [-[,]] [/]\n" + " [ :,... ]\n" + " [ [[,]/] ... ]\n" + "initflags: p use poll(2) instead of select(2)\n" + "queryflags: a print status abbrevs instead of strings\n", + stderr); exit(4); } cp++; @@ -143,14 +177,25 @@ int main(int argc, char *const *argv) { if (!qus) { perror("malloc qus"); exit(3); } if (initstring) { - r= adns_init_strcfg(&ads,adns_if_debug|adns_if_noautosys,stdout,initstring); + r= adns_init_strcfg(&ads, + (adns_if_debug|adns_if_noautosys)^initflagsnum, + stdout,initstring); } else { - r= adns_init(&ads,adns_if_debug|adns_if_noautosys,0); + r= adns_init(&ads, + (adns_if_debug|adns_if_noautosys)^initflagsnum, + 0); } if (r) failure_errno("init",r); + npollfdsavail= 0; + pollfds= 0; + for (qi=0; qistatus) + strchr(ownflags,'a') + ? adns_errabbrev(ans->status) : adns_strerror(ans->status), ans->nrrs, ans->cname ? ans->cname : "$", diff --git a/regress/checkall b/regress/checkall index 9412247..0765eab 100755 --- a/regress/checkall +++ b/regress/checkall @@ -1,13 +1,14 @@ #!/bin/sh failed='' +passed='' for f in case-*.sys do case="`echo \"$f\" | sed -e 's/^case-//; s/\.sys$//'`" if ./r1test $case then - : + passed="$passed $case" else echo failed="$failed $case" @@ -24,7 +25,8 @@ fi echo >&2 " AT LEAST ONE TEST FAILED -$failed +passed tests:${passed:- NONE} +failed tests:$failed " exit 1 diff --git a/src/adns.h b/src/adns.h index ce92c8b..190142b 100644 --- a/src/adns.h +++ b/src/adns.h @@ -479,30 +479,35 @@ int adns_beforepoll(adns_state ads, struct pollfd *fds, int *nfds_io, int *timeo * listen for more structs then *nfds_io will be set to the number * required and _beforepoll will return ERANGE. * - * NOTE that if now is 0, adns may acquire additional fds from one - * call to the next, so you must put adns_beforepoll in a loop, rather - * than assuming that the second call (with the buffer size requested - * by the first) will not return ERANGE. - * * You may call _beforepoll with fds==0 and *nfds_io 0, in which case * adns will fill in the number of fds that it might be interested in - * in *nfds_io, and always return 0. + * in *nfds_io, and always return either 0 (if it is not interested in + * any fds) or ERANGE (if it is). + * + * NOTE that (unless timeout_io is 0) adns may acquire additional fds + * from one call to the next, so you must put adns_beforepoll in a + * loop, rather than assuming that the second call (with the buffer + * size requested by the first) will not return ERANGE. * * adns only ever sets POLLIN, POLLOUT and POLLPRI in its pollfd * structs, and only ever looks at those bits. POLLPRI is required to - * detect TCP Urgent Data, which should not be used by a DNS server, + * detect TCP Urgent Data (which should not be used by a DNS server) * so that adns can know that the TCP stream is now useless. * * In any case, *timeout_io should be a timeout value as for poll(2), * which adns will modify downwards as required. If the caller does - * not plan to block then *timeout_io should be 0 on entry. + * not plan to block then *timeout_io should be 0 on entry, or + * alternatively, timeout_io may be 0. (Alternatively, the caller may + * use _beforeselect with timeout_io==0 to find out about file + * descriptors, and use _firsttimeout is used to find out when adns + * might want to time something out.) * * adns_beforepoll will return 0 on success, and will not fail for any * reason other than the fds buffer being too small (ERANGE). * - * If *now is not 0 then this call will never actually do any I/O, or - * change the fds that adns is using or the timeouts it wants. In any - * case it won't block. + * This call will never actually do any I/O, or change the fds that + * adns is using or the timeouts it wants; and in any case it won't + * block. */ #define ADNS_POLLFDS_RECOMMENDED 2 diff --git a/src/event.c b/src/event.c index d54d847..1b527a2 100644 --- a/src/event.c +++ b/src/event.c @@ -454,12 +454,16 @@ void adns_beforeselect(adns_state ads, int *maxfd_io, fd_set *readfds_io, void adns_afterselect(adns_state ads, int maxfd, const fd_set *readfds, const fd_set *writefds, const fd_set *exceptfds, const struct timeval *now) { + struct timeval tv_buf; struct pollfd pollfds[MAX_POLLFDS]; - int npollfds; + int npollfds, i; + adns__must_gettimeofday(ads,&now,&tv_buf); + if (!now) return; adns_processtimeouts(ads,now); npollfds= adns__pollfds(ads,pollfds); + for (i=0; i= MAX_POLLFDS) { @@ -63,7 +65,7 @@ int adns_beforepoll(adns_state ads, struct pollfd *fds, int *nfds_io, int *timeo } else { found= adns__pollfds(ads,fds_tmp); *nfds_io= found; - if (found < space) return space ? ERANGE : 0; + if (space < found) return ERANGE; memcpy(fds,fds_tmp,sizeof(struct pollfd)*found); } return 0; @@ -76,7 +78,7 @@ void adns_afterpoll(adns_state ads, const struct pollfd *fds, int nfds, adns__must_gettimeofday(ads,&now,&tv_buf); if (!now) return; - adns__timeouts(ads,1, 0,0, *now); + adns__timeouts(ads, 1, 0,0, *now); adns__fdevents(ads, fds,nfds, 0,0,0,0, *now,0); } -- 2.30.2