2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00

2146. [cleanup] Silence Linux's spurious "obsolete setsockopt

SO_BSDCOMPAT" message. [RT #16641]
This commit is contained in:
Mark Andrews
2007-02-26 01:37:37 +00:00
parent 394f4aec21
commit 340a05967a
2 changed files with 51 additions and 2 deletions

View File

@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: socket.c,v 1.269 2007/02/13 02:49:08 marka Exp $ */
/* $Id: socket.c,v 1.270 2007/02/26 01:37:37 marka Exp $ */
/*! \file */
@@ -48,6 +48,7 @@
#include <isc/msgs.h>
#include <isc/mutex.h>
#include <isc/net.h>
#include <isc/once.h>
#include <isc/platform.h>
#include <isc/print.h>
#include <isc/region.h>
@@ -69,6 +70,11 @@
*/
#define ISC_SOCKET_NAMES 1
#if defined(SO_BSDCOMPAT) && defined(__linux__)
#include <sys/utsname.h>
#endif
/*%
* Some systems define the socket length argument as an int, some as size_t,
* some as socklen_t. This is here so it can be easily changed if needed.
@@ -1410,7 +1416,45 @@ free_socket(isc_socket_t **socketp) {
*socketp = NULL;
}
#ifdef SO_BSDCOMPAT
/*
* This really should not be necessary to do. Having to workout
* which kernel version we are on at run time so that we don't cause
* the kernel to issue a warning about us using a deprecated socket option.
* Such warnings should *never* be on by default in production kernels.
*
* We can't do this a build time because executables are moved between
* machines and hence kernels.
*
* We can't just not set SO_BSDCOMAT because some kernels require it.
*/
static isc_once_t bsdcompat_once = ISC_ONCE_INIT;
isc_boolean_t bsdcompat = ISC_TRUE;
static void
clear_bsdcompat(void) {
#ifdef __linux__
struct utsname buf;
char *endp;
long int major;
long int minor;
uname(&buf); /* Can only fail if buf is bad in Linux. */
/* Paranoia in parsing can be increased, but we trust uname(). */
major = strtol(buf.release, &endp, 10);
if (*endp == '.') {
minor = strtol(endp+1, &endp, 10);
if ((major > 2) || ((major == 2) && (minor >= 4))) {
bsdcompat = ISC_FALSE;
}
}
#endif /* __linux __ */
}
#endif
/*%
* Create a new 'type' socket managed by 'manager'. Events
* will be posted to 'task' and when dispatched 'action' will be
* called with 'arg' as the arg value. The new socket is returned
@@ -1520,7 +1564,9 @@ isc_socket_create(isc_socketmgr_t *manager, int pf, isc_sockettype_t type,
}
#ifdef SO_BSDCOMPAT
if (type != isc_sockettype_unix &&
RUNTIME_CHECK(isc_once_do(&bsdcompat_once,
clear_bsdcompat) == ISC_R_SUCCESS);
if (type != isc_sockettype_unix && bsdcompat &&
setsockopt(sock->fd, SOL_SOCKET, SO_BSDCOMPAT,
(void *)&on, sizeof(on)) < 0) {
isc__strerror(errno, strbuf, sizeof(strbuf));