diff --git a/common/include/villas/utils.hpp b/common/include/villas/utils.hpp index e60e93c42..e108439c4 100644 --- a/common/include/villas/utils.hpp +++ b/common/include/villas/utils.hpp @@ -208,6 +208,9 @@ bool isKubernetes(); /** Check if process is running inside a containerized environment */ bool isContainer(); +/** Check if the process is running in a privileged environment (has SYS_ADMIN capability). */ +bool isPrivileged(); + namespace base64 { using byte = std::uint8_t; diff --git a/common/lib/utils.cpp b/common/lib/utils.cpp index 060dde11f..61d099d28 100644 --- a/common/lib/utils.cpp +++ b/common/lib/utils.cpp @@ -371,5 +371,17 @@ bool isContainer() { return isDocker() || isKubernetes(); } +bool isPrivileged() { + // TODO: a cleaner way would be to use libcap here and check for the + // SYS_ADMIN capability. + auto *f = fopen(PROCFS_PATH "/sys/vm/nr_hugepages", "w"); + if (!f) + return false; + + fclose(f); + + return 0; +} + } /* namespace utils */ } /* namespace villas */