From c052f58eab061462a00a5b481518c380b98abe1f Mon Sep 17 00:00:00 2001 From: "Pawel \"l0ner\" Soltys" Date: Mon, 26 Jan 2015 19:48:56 +0100 Subject: [PATCH] Workaround for compilation on OpenBSD 5.6 On OpenBSD 5.6 sys/ucred.h uses NGROUP define, but misses include to sys/param.h in which NGROUP is defined. sys/ucred.h is included in sys/mount.h which we need to get the cached ram. Because of this include chain our compilation will fail with missing NGROUP define. This can be resolved by including in our code (and in correct order) system headers. --- CMakeLists.txt | 3 +++ openbsd/memory.cc | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b676edd..fd908b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,9 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "OpenBSD") message(STATUS "OpenBSD detected") message(WARNING "OpenBSD is still experimental!") set(METER_SOURCES "openbsd/memory.cc" "openbsd/cpu.cc" "openbsd/load.cc") + if(CMAKE_SYSTEM_VERSION VERSION_LESS 5.7) + add_definitions(-DOPENBSD_WORKAROUND=1) + endif() else() message(FATAL_ERROR "Cannot be compiled on this system") endif() diff --git a/openbsd/memory.cc b/openbsd/memory.cc index 5724303..832cbbf 100644 --- a/openbsd/memory.cc +++ b/openbsd/memory.cc @@ -18,9 +18,22 @@ #include #include + +// Ugly fix to compilation on OpenBSD 5.6 +// these need to be before include sys/mount.h +// and be in this exact order. Otherwise compiling on +// OpenBSD 5.6 will fail with missing NGROUPS define +// or missing gid_t typedefs +#ifdef OPENBSD_WORKAROUND +#include // typedefs +#include // missing NGROUPS +#include +#else +#include +#endif + #include // VFS_* which we use to get cache #include -#include #include // vmtotal struct #include "error.h"