Skip to content

Commit

Permalink
Change RAM check on Mac from sysctlbyname() to sysctl()
Browse files Browse the repository at this point in the history
For an unknown reason, the RAM size returned by sysctlbyname() just up and went
nuts.  Switched to the more basic sysctl(), with all of the requisite changes
in the autotools code and program-wide definition file.  The results returned
by sysctl() seem to work.

	modified:   config.h.in
	modified:   configure.ac
	modified:   src/init.c
	modified:   src/sd_defs.h
  • Loading branch information
tbowers7 committed Feb 15, 2018
1 parent 0eb1911 commit 8dcdc3b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@
/* Define to 1 if you have the `strtol' function. */
#undef HAVE_STRTOL

/* Define to 1 if you have the `sysctlbyname' function. */
#undef HAVE_SYSCTLBYNAME
/* Define to 1 if you have the `sysctl' function. */
#undef HAVE_SYSCTL

/* Define to 1 if you have the `sysinfo' function. */
#undef HAVE_SYSINFO
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ AC_CHECK_TYPES([socklen_t], [], [], [#include <sys/socket.h>])
dnl ScopeDesign requirements
AC_FUNC_MALLOC
AC_CHECK_FUNCS([sqrt strdup])
AC_CHECK_FUNCS([sysinfo sysctlbyname])
AC_CHECK_FUNCS([sysinfo sysctl])


dnl LIBARGTABLE requirements
Expand Down
14 changes: 9 additions & 5 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ int init_get_sysinfo(void){
SYS_RAM = (double)s.totalram / 1024. / 1024.; // in MB

#elif HAVE__MAC
size_t size;
unsigned long long memsize;
sysctlbyname("HW_MEMSIZE", &memsize, &size, NULL, 0);
SYS_RAM = (double)memsize / 1024. / 1024.; // In MB
int mib[2];
int64_t physical_memory;
size_t length;
mib[0] = CTL_HW;
mib[1] = HW_MEMSIZE;
length = sizeof(int64_t);
sysctl(mib, 2, &physical_memory, &length, NULL, 0);
SYS_RAM = (double)physical_memory / 1024. / 1024.; // In MB

#else
SYS_RAM = 0;
SYS_RAM = 0.;

#endif

Expand Down
2 changes: 1 addition & 1 deletion src/sd_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# define HAVE__MAC 0
# define HAVE__OTHER 0
# define SD_SYS 50 // Linux
#elif HAVE_SYSCTLBYNAME
#elif HAVE_SYSCTL
# define HAVE__LINUX 0
# define HAVE__MAC 1
# define HAVE__OTHER 0
Expand Down

0 comments on commit 8dcdc3b

Please sign in to comment.