]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
2146. [cleanup] Silence Linux's spurious "obsolete setsockopt
authorMark Andrews <marka@isc.org>
Mon, 26 Feb 2007 01:37:37 +0000 (01:37 +0000)
committerMark Andrews <marka@isc.org>
Mon, 26 Feb 2007 01:37:37 +0000 (01:37 +0000)
                        SO_BSDCOMPAT" message. [RT #16641]

CHANGES
lib/isc/unix/socket.c

diff --git a/CHANGES b/CHANGES
index 3df60d23e0427490c9defdf6c21bd72062d92f60..68b86732df4f81672deb2265d27f273082dc900d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+2146.  [cleanup]       Silence Linux's spurious "obsolete setsockopt
+                       SO_BSDCOMPAT" message. [RT #16641]
+
 2145.  [bug]           Check DS/DLV digest lengths for known digests.
                        [RT #16622]
 
index 717ee6ed5ddbb80ad303d0b6cdaff6dde8e58a67..6fea7920c94d6d6444fdd77c30fdf6d39d5d2653 100644 (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>
  */
 #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));