2022-05-19 19:28:15 +02:00
|
|
|
#include "initHelpers.hpp"
|
|
|
|
|
|
|
|
bool Init::isSudo() {
|
|
|
|
return getuid() != geteuid() || !geteuid();
|
|
|
|
}
|
2023-07-23 20:51:00 +02:00
|
|
|
|
|
|
|
void Init::gainRealTime() {
|
|
|
|
const int minPrio = sched_get_priority_min(SCHED_RR);
|
2023-07-24 18:26:24 +02:00
|
|
|
int old_policy;
|
|
|
|
struct sched_param param;
|
|
|
|
|
|
|
|
if (pthread_getschedparam(pthread_self(), &old_policy, ¶m)) {
|
|
|
|
Debug::log(WARN, "Failed to get old pthread scheduling priority");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
param.sched_priority = minPrio;
|
2023-07-23 20:51:00 +02:00
|
|
|
|
|
|
|
if (pthread_setschedparam(pthread_self(), SCHED_RR, ¶m)) {
|
|
|
|
Debug::log(WARN, "Failed to change process scheduling strategy");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_atfork(NULL, NULL, []() {
|
|
|
|
const struct sched_param param = {.sched_priority = 0};
|
|
|
|
if (pthread_setschedparam(pthread_self(), SCHED_OTHER, ¶m))
|
|
|
|
Debug::log(WARN, "Failed to reset process scheduling strategy");
|
|
|
|
});
|
|
|
|
}
|