X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fgeneral.c;h=00a1ae808f2d7ef23d3ba4faf1ba693efb9ac76e;hb=dd34699eca563b946f6d9665b1b85fdb57e3bb25;hp=15025a406c8375a68e60c86c921d24282a087a82;hpb=09957b1ca58af52bbc90e88ec198f14b8a06c0f7;p=adns.git diff --git a/src/general.c b/src/general.c index 15025a4..00a1ae8 100644 --- a/src/general.c +++ b/src/general.c @@ -4,7 +4,7 @@ * - vbuf handling */ /* - * This file is part of adns, which is Copyright (C) 1997, 1998 Ian Jackson + * This file is part of adns, which is Copyright (C) 1997-1999 Ian Jackson * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,8 +22,10 @@ */ #include -#include +#include +#include +#include #include #include "internal.h" @@ -197,16 +199,18 @@ adns_status adns_rr_info(adns_rrtype type, return st; } -#define SINFO(n,s) { adns_s_##n, s } +#define SINFO(n,s) { adns_s_##n, #n, s } static const struct sinfo { adns_status st; + const char *abbrev; const char *string; } sinfos[]= { SINFO( ok, "OK" ), SINFO( nomemory, "Out of memory" ), SINFO( unknownrrtype, "Query not implemented in DNS library" ), + SINFO( systemfail, "General resolver or system failure" ), SINFO( timeout, "DNS query timed out" ), SINFO( allservfail, "All nameservers failed" ), @@ -221,7 +225,7 @@ static const struct sinfo { SINFO( rcodeunknown, "Nameserver sent unknown response code" ), SINFO( inconsistent, "Inconsistent resource records in DNS" ), - SINFO( prohibitedcname, "DNS data refers to an alias" ), + SINFO( prohibitedcname, "DNS alias found where canonical name wanted" ), SINFO( answerdomaininvalid, "Found syntactically invalid domain name" ), SINFO( answerdomaintoolong, "Found overly-long domain name" ), SINFO( invaliddata, "Found invalid DNS data" ), @@ -241,16 +245,22 @@ static int si_compar(const void *key, const void *elem) { return *st < si->st ? -1 : *st > si->st ? 1 : 0; } +static const struct sinfo *findsinfo(adns_status st) { + return bsearch(&st,sinfos,sizeof(sinfos)/sizeof(*sinfos),sizeof(*sinfos),si_compar); +} + const char *adns_strerror(adns_status st) { - static char buf[100]; + const struct sinfo *si; + + si= findsinfo(st); + return si->string; +} +const char *adns_errabbrev(adns_status st) { const struct sinfo *si; - si= bsearch(&st,sinfos,sizeof(sinfos)/sizeof(*si),sizeof(*si),si_compar); - if (si) return si->string; - - snprintf(buf,sizeof(buf),"code %d",st); - return buf; + si= findsinfo(st); + return si->abbrev; } void adns__isort(void *array, int nobjs, int sz, void *tempbuf, @@ -270,3 +280,32 @@ void adns__isort(void *array, int nobjs, int sz, void *tempbuf, } } } + +/* SIGPIPE protection. */ + +void adns__sigpipe_protect(adns_state ads) { + sigset_t toblock; + struct sigaction sa; + int r; + + if (ads->iflags & adns_if_nosigpipe) return; + + sigfillset(&toblock); + sigdelset(&toblock,SIGPIPE); + + sa.sa_handler= SIG_IGN; + sigfillset(&sa.sa_mask); + sa.sa_flags= 0; + + r= sigprocmask(SIG_SETMASK,&toblock,&ads->stdsigmask); assert(!r); + r= sigaction(SIGPIPE,&sa,&ads->stdsigpipe); assert(!r); +} + +void adns__sigpipe_unprotect(adns_state ads) { + int r; + + if (ads->iflags & adns_if_nosigpipe) return; + + r= sigaction(SIGPIPE,&ads->stdsigpipe,0); assert(!r); + r= sigprocmask(SIG_SETMASK,&ads->stdsigmask,0); assert(!r); +}