Skip to content

Commit

Permalink
Linux: don't use deprecated sysctl (#45753)
Browse files Browse the repository at this point in the history
* Linux: don't use deprecated sysctl

* Handle deprecated sysctl in coreclr, gc, corehost.
  • Loading branch information
tmds authored Jan 21, 2021
1 parent 3d913fd commit bf573c7
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 12 deletions.
7 changes: 6 additions & 1 deletion src/coreclr/gc/unix/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ check_library_exists(${PTHREAD_LIBRARY} pthread_setaffinity_np "" HAVE_PTHREAD_S
check_cxx_symbol_exists(_SC_PHYS_PAGES unistd.h HAVE__SC_PHYS_PAGES)
check_cxx_symbol_exists(_SC_AVPHYS_PAGES unistd.h HAVE__SC_AVPHYS_PAGES)
check_cxx_symbol_exists(swapctl sys/swap.h HAVE_SWAPCTL)
check_function_exists(sysctl HAVE_SYSCTL)
if(CLR_CMAKE_TARGET_LINUX)
# sysctl is deprecated on Linux
set(HAVE_SYSCTL 0)
else()
check_function_exists(sysctl HAVE_SYSCTL)
endif()
check_function_exists(sysinfo HAVE_SYSINFO)
check_function_exists(sysconf HAVE_SYSCONF)
check_struct_has_member ("struct sysinfo" mem_unit "sys/sysinfo.h" HAVE_SYSINFO_WITH_MEM_UNIT)
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#cmakedefine01 HAVE_SYS_LWP_H
#cmakedefine01 HAVE_LWP_H
#cmakedefine01 HAVE_RUNETYPE_H
#cmakedefine01 HAVE_SYS_SYSCTL_H
#cmakedefine01 HAVE_GNU_LIBNAMES_H
#cmakedefine01 HAVE_PRCTL_H
#cmakedefine01 HAVE_NUMA_H
Expand Down
8 changes: 6 additions & 2 deletions src/coreclr/pal/src/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ int main(int argc, char **argv) {

set(CMAKE_REQUIRED_LIBRARIES)

check_include_files(sys/sysctl.h HAVE_SYS_SYSCTL_H)
check_function_exists(sysctlbyname HAVE_SYSCTLBYNAME)
check_include_files(gnu/lib-names.h HAVE_GNU_LIBNAMES_H)

Expand Down Expand Up @@ -113,7 +112,12 @@ set(CMAKE_REQUIRED_LIBRARIES)
check_function_exists(fsync HAVE_FSYNC)
check_function_exists(futimes HAVE_FUTIMES)
check_function_exists(utimes HAVE_UTIMES)
check_function_exists(sysctl HAVE_SYSCTL)
if(CLR_CMAKE_TARGET_LINUX)
# sysctl is deprecated on Linux
set(HAVE_SYSCTL 0)
else()
check_function_exists(sysctl HAVE_SYSCTL)
endif()
check_function_exists(sysinfo HAVE_SYSINFO)
check_function_exists(sysconf HAVE_SYSCONF)
check_function_exists(gmtime_r HAVE_GMTIME_R)
Expand Down
4 changes: 0 additions & 4 deletions src/installer/corehost/cli/hostmisc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,6 @@ namespace pal
#define __stdcall /* nothing */
#if !defined(TARGET_FREEBSD)
#define __fastcall /* nothing */
#else
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/param.h>
#endif
#define STDMETHODCALLTYPE __stdcall

Expand Down
4 changes: 4 additions & 0 deletions src/installer/corehost/cli/hostmisc/pal.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#include <sys/sysctl.h>
#elif defined(__sun)
#include <sys/utsname.h>
#elif defined(TARGET_FREEBSD)
#include <sys/types.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#endif

#if !HAVE_DIRENT_D_TYPE
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Native/Unix/System.Native/pal_sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int32_t SystemNative_Sysctl(int* name, unsigned int namelen, void* value, size_t
void* newp = NULL;
size_t newlen = 0;

#if defined(__linux__) || defined(TARGET_WASM)
#if defined(TARGET_WASM)
return sysctl(name, (int)(namelen), value, len, newp, newlen);
#else
return sysctl(name, namelen, value, len, newp, newlen);
Expand Down
11 changes: 8 additions & 3 deletions src/libraries/Native/Unix/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -806,9 +806,14 @@ check_type_size(
BUILTIN_TYPES_ONLY)
set(CMAKE_EXTRA_INCLUDE_FILES) # reset CMAKE_EXTRA_INCLUDE_FILES

check_include_files(
"sys/types.h;sys/sysctl.h"
HAVE_SYS_SYSCTL_H)
if (CLR_CMAKE_TARGET_LINUX)
# sysctl is deprecated on Linux
set(HAVE_SYS_SYSCTL_H 0)
else ()
check_include_files(
"sys/types.h;sys/sysctl.h"
HAVE_SYS_SYSCTL_H)
endif()

check_include_files(
"sys/ioctl.h"
Expand Down

0 comments on commit bf573c7

Please sign in to comment.