Handle glibc sys/sysctl.h deprecation (#27048)
authorOmair Majid <omajid@redhat.com>
Wed, 16 Oct 2019 09:25:29 +0000 (05:25 -0400)
committerGleb Balykov <g.balykov@samsung.com>
Wed, 25 Mar 2020 12:29:41 +0000 (15:29 +0300)
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 #27008

src/pal/src/misc/sysinfo.cpp

index 52e8ec0..b8a6a70 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