patch for SO_BSDCOMPAT problem on 2.5 Linux development kernels

Mikael Pettersson mikpe@REDACTED
Wed Jul 9 21:15:26 CEST 2003


SO_BSDCOMPAT is obsolete since the 2.4 kernels, and now 2.5 kernels
log a warning every time it is used. This is a problem since beam
uses it unconditionally even though it only makes a difference in very
old kernels (2.2 and older).

This patch fixes the problem. It performs a runtime kernel version test,
since that's what Raimo Niskanen preferred. It would be nice to get this
fix into OpenSource R9C-0, even if it's too late for the commercial
release. (Tested with kernels 2.2.25, 2.4.21, and 2.5.74.)

/Mikael Pettersson
The HiPE group.

--- otp-0626/erts/emulator/drivers/common/inet_drv.c.~1~	2003-06-06 13:58:49.000000000 +0200
+++ otp-0626/erts/emulator/drivers/common/inet_drv.c	2003-07-08 19:40:28.000000000 +0200
@@ -6108,6 +6108,43 @@
 
 -----------------------------------------------------------------------------*/
 
+#if defined(HAVE_SO_BSDCOMPAT)
+#if defined(__linux__)
+#include <sys/utsname.h>
+static int should_use_so_bsdcompat(void)
+{
+    static int init_done;
+    static int so_bsdcompat_is_obsolete;
+
+    if (!init_done) {
+	struct utsname utsname;
+	unsigned int version, patchlevel;
+
+	init_done = 1;
+	if (uname(&utsname) < 0) {
+	    fprintf(stderr, "uname: %s\r\n", strerror(errno));
+	    return 1;
+	}
+	/* Format is <version>.<patchlevel>.<sublevel><extraversion>
+	   where the first three are unsigned integers and the last
+	   is an arbitrary string. We only care about the first two. */
+	if (sscanf(utsname.release, "%u.%u", &version, &patchlevel) != 2) {
+	    fprintf(stderr, "uname: unexpected release '%s'\r\n",
+		    utsname.release);
+	    return 1;
+	}
+	/* SO_BSCOMPAT is deprecated and triggers warnings in 2.5
+	   kernels. It is a no-op in 2.4 but not in 2.2 kernels. */
+	if (version > 2 || (version == 2 && patchlevel >= 5))
+	    so_bsdcompat_is_obsolete = 1;
+    }
+    return !so_bsdcompat_is_obsolete;
+}
+#else	/* __linux__ */
+#define should_use_so_bsdcompat() 1
+#endif	/* __linux__ */
+#endif	/* HAVE_SO_BSDCOMPAT */
+
 static int udp_inet_init()
 {
     return 0;
@@ -6167,7 +6204,7 @@
 	     * existing machine doesn't close the socket. (Linux behaves this
 	     * way)
 	     */
-	    {
+	    if (should_use_so_bsdcompat()) {
 		int one = 1;
 		/* Ignore errors */
 		sock_setopt(desc->inet.s, SOL_SOCKET, SO_BSDCOMPAT, &one,
@@ -6200,7 +6237,7 @@
 	     * existing machine doesn't close the socket. (Linux behaves this
 	     * way)
 	     */
-	    {
+	    if (should_use_so_bsdcompat()) {
 		int one = 1;
 		/* Ignore errors */
 		sock_setopt(desc->inet.s, SOL_SOCKET, SO_BSDCOMPAT, &one,



More information about the erlang-questions mailing list