X-Git-Url: https://git.distorted.org.uk/~mdw/adns/blobdiff_plain/6f2c243f115bd079373c959476ac4f46e8a31e91..87e46054b4db54320b42bd44da7d7267f06c1ae0:/src/general.c diff --git a/src/general.c b/src/general.c index 33946ad..b701b9f 100644 --- a/src/general.c +++ b/src/general.c @@ -270,3 +270,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); +}