threadCreate(): check for and handle missing SYS_NICE

SYS_NICE is a capability that allows a process to set thread affinity
and priority, among other things (see capabilities(7) for more info).

In this commit, add a function that allows to determine if the process
has this capability, and try to change the thread affinity and priority,
if requested. If the capability does not exist, the function will simply
not attempt to change the corresponding thread attributes.

To determine if the process has SYS_NICE, libcap can be used. However,
it might not be installed by default. To avoid requiring another
dependency, if we detect that libcap is not present, use a workaround by
try to set a real-time scheduling policy; if it's present, or can be
changed, we assume that the process has SYS_NICE (and clean up, if
relevant).

Simplify reading of capabilities
This commit is contained in:
Robert Schmidt
2024-06-03 14:00:41 +02:00
parent 6a12784872
commit 66bf27bce9
4 changed files with 69 additions and 23 deletions
+6
View File
@@ -659,6 +659,12 @@ add_library(UTIL
${OPENAIR_DIR}/common/utils/time_meas.c
${OPENAIR_DIR}/common/utils/time_stat.c
)
pkg_check_modules(cap libcap)
if (cap_FOUND)
# see system.c for more info
target_link_libraries(UTIL PRIVATE cap)
target_compile_definitions(UTIL PRIVATE HAVE_LIB_CAP)
endif()
target_link_libraries(UTIL PUBLIC ${T_LIB} pthread)
set(SECURITY_SRC