Handle glibc sys/sysctl.h deprecation (#27048) (#681)
authorDongkyun Son <tenblood@gmail.com>
Wed, 8 Jan 2020 19:43:14 +0000 (04:43 +0900)
committerMike McLaughlin <mikem@microsoft.com>
Wed, 8 Jan 2020 19:43:14 +0000 (11:43 -0800)
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

Co-authored-by: Omair Majid <omajid@redhat.com>
src/pal/src/misc/sysinfo.cpp

index dd23c9cea8d6f52d80112ae682e5bf6c421e9829..45b6b3bdb811abe1565a4af55b24292bf590c0d6 100644 (file)
@@ -26,9 +26,12 @@ Revision History:
 #include <errno.h>
 #include <unistd.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