Handle glibc sys/sysctl.h deprecation (dotnet/coreclr#27048)
authorOmair Majid <omajid@redhat.com>
Wed, 16 Oct 2019 09:25:29 +0000 (05:25 -0400)
committerJan Vorlicek <janvorli@microsoft.com>
Wed, 16 Oct 2019 09:25:29 +0000 (11:25 +0200)
glibc has deprecated sys/sysctl.h:

    In file included from /coreclr/src/pal/src/misc/sysinfo.cpp:32:
    /usr/include/sys/sysctl.h:21:2: error: "The <sys/sysctl.h> header is deprecated and will be removed." [-Werror,-W#warnings]
    #warning "The <sys/sysctl.h> header is deprecated and will be removed."
     ^
    1 error generated.

Fix that by preferring sysconf and only including sys/sysctl.h if
HAVE_SYSCONF is not true. This mirrors the order of the implementation
code in this file (sysinfo.cpp) which checks for HAVE_SYSCONF
before HAVE_SYSCTL.

Fixes dotnet/coreclr#27008

Commit migrated from https://github.com/dotnet/coreclr/commit/6ce179a17061abbbe9f904f878943a28c8041a62

src/coreclr/src/pal/src/misc/sysinfo.cpp

index e1c949e..50ccf3a 100644 (file)
@@ -28,9 +28,12 @@ Revision History:
 #define __STDC_FORMAT_MACROS
 #include <inttypes.h>
 #include <sys/types.h>
-#if HAVE_SYSCTL
+
+#if HAVE_SYSCONF
+// <unistd.h> already included above
+#elif HAVE_SYSCTL
 #include <sys/sysctl.h>
-#elif !HAVE_SYSCONF
+#else
 #error Either sysctl or sysconf is required for GetSystemInfo.
 #endif