mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
add utils::isPrivileged()
This commit is contained in:
parent
5c0a96c911
commit
5bb68b2fe1
2 changed files with 15 additions and 0 deletions
|
@ -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 */
|
||||
|
|
Loading…
Add table
Reference in a new issue