Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/lib/libc/resolv/res_send.c,v rcsdiff: /ftp/cvs/cvsroot/src/lib/libc/resolv/res_send.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.13 retrieving revision 1.14 diff -u -p -r1.13 -r1.14 --- src/lib/libc/resolv/res_send.c 2007/03/30 20:23:05 1.13 +++ src/lib/libc/resolv/res_send.c 2008/06/21 20:41:48 1.14 @@ -1,4 +1,4 @@ -/* $NetBSD: res_send.c,v 1.13 2007/03/30 20:23:05 ghen Exp $ */ +/* $NetBSD: res_send.c,v 1.14 2008/06/21 20:41:48 christos Exp $ */ /* * Copyright (c) 1985, 1989, 1993 @@ -74,9 +74,9 @@ #if defined(LIBC_SCCS) && !defined(lint) #ifdef notdef static const char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93"; -static const char rcsid[] = "Id: res_send.c,v 1.9.18.8 2006/10/16 23:00:58 marka Exp"; +static const char rcsid[] = "Id: res_send.c,v 1.18.10.1 2008/01/27 02:06:46 marka Exp"; #else -__RCSID("$NetBSD: res_send.c,v 1.13 2007/03/30 20:23:05 ghen Exp $"); +__RCSID("$NetBSD: res_send.c,v 1.14 2008/06/21 20:41:48 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -130,9 +130,7 @@ __weak_alias(res_nsend,__res_nsend) #endif /* USE_POLL */ /* Options. Leave them on. */ -#ifndef DEBUG #define DEBUG -#endif #include "res_debug.h" #include "res_private.h" @@ -140,6 +138,8 @@ __weak_alias(res_nsend,__res_nsend) #ifndef USE_POLL static const int highestFD = FD_SETSIZE - 1; +#else +static int highestFD = 0; #endif /* Forward. */ @@ -311,9 +311,13 @@ int res_nsend(res_state statp, const u_char *buf, int buflen, u_char *ans, int anssiz) { - int gotsomewhere, terrno, try, v_circuit, resplen, ns, n; + int gotsomewhere, terrno, tries, v_circuit, resplen, ns, n; char abuf[NI_MAXHOST]; +#ifdef USE_POLL + highestFD = sysconf(_SC_OPEN_MAX) - 1; +#endif + /* No name servers or res_init() failure */ if (statp->nscount == 0 || EXT(statp).ext == NULL) { errno = ESRCH; @@ -419,7 +423,7 @@ res_nsend(res_state statp, /* * Send request, RETRY times, or until successful. */ - for (try = 0; try < statp->retry; try++) { + for (tries = 0; tries < statp->retry; tries++) { for (ns = 0; ns < statp->nscount; ns++) { struct sockaddr *nsap; int nsaplen; @@ -467,7 +471,7 @@ res_nsend(res_state statp, if (v_circuit) { /* Use VC; at most one attempt per server. */ - try = statp->retry; + tries = statp->retry; n = send_vc(statp, buf, buflen, ans, anssiz, &terrno, ns); if (n < 0) @@ -478,7 +482,7 @@ res_nsend(res_state statp, } else { /* Use datagrams. */ n = send_dg(statp, buf, buflen, ans, anssiz, &terrno, - ns, try, &v_circuit, &gotsomewhere); + ns, tries, &v_circuit, &gotsomewhere); if (n < 0) goto fail; if (n == 0) @@ -615,6 +619,9 @@ send_vc(res_state statp, u_short len; u_char *cp; void *tmp; +#ifdef SO_NOSIGPIPE + int on = 1; +#endif nsap = get_nsaddr(statp, (size_t)ns); nsaplen = get_salen(nsap); @@ -641,12 +648,10 @@ send_vc(res_state statp, res_nclose(statp); statp->_vcsock = socket(nsap->sa_family, SOCK_STREAM, 0); -#ifndef USE_POLL if (statp->_vcsock > highestFD) { res_nclose(statp); errno = ENOTSOCK; } -#endif if (statp->_vcsock < 0) { switch (errno) { case EPROTONOSUPPORT: @@ -662,6 +667,17 @@ send_vc(res_state statp, return (-1); } } +#ifdef SO_NOSIGPIPE + /* + * Disable generation of SIGPIPE when writing to a closed + * socket. Write should return -1 and set errno to EPIPE + * instead. + * + * Push on even if setsockopt(SO_NOSIGPIPE) fails. + */ + (void)setsockopt(statp->_vcsock, SOL_SOCKET, SO_NOSIGPIPE, &on, + sizeof(on)); +#endif errno = 0; if (connect(statp->_vcsock, nsap, (socklen_t)nsaplen) < 0) { *terrno = errno; @@ -789,7 +805,7 @@ send_vc(res_state statp, static int send_dg(res_state statp, const u_char *buf, int buflen, u_char *ans, - int anssiz, int *terrno, int ns, int try, int *v_circuit, + int anssiz, int *terrno, int ns, int tries, int *v_circuit, int *gotsomewhere) { const HEADER *hp = (const HEADER *)(const void *)buf; @@ -811,12 +827,10 @@ send_dg(res_state statp, const u_char *b nsaplen = get_salen(nsap); if (EXT(statp).nssocks[ns] == -1) { EXT(statp).nssocks[ns] = socket(nsap->sa_family, SOCK_DGRAM, 0); -#ifndef USE_POLL if (EXT(statp).nssocks[ns] > highestFD) { res_nclose(statp); errno = ENOTSOCK; } -#endif if (EXT(statp).nssocks[ns] < 0) { switch (errno) { case EPROTONOSUPPORT: @@ -873,7 +887,7 @@ send_dg(res_state statp, const u_char *b /* * Wait for reply. */ - seconds = (statp->retrans << try); + seconds = (statp->retrans << tries); if (ns > 0) seconds /= statp->nscount; if (seconds <= 0)