Commit 59eaf21f authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼
Browse files

add utils::isPrivileged()

parent b8778630
......@@ -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;
......
......@@ -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 */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment