summaryrefslogtreecommitdiff
path: root/src/init/initHelpers.cpp
blob: 2666ed0bf056a446c1da4e4cacb63827f35f024a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "initHelpers.hpp"

bool Init::isSudo() {
    return getuid() != geteuid() || !geteuid();
}

void Init::gainRealTime() {
    const int                minPrio = sched_get_priority_min(SCHED_RR);
    const struct sched_param param   = {.sched_priority = minPrio};

    if (pthread_setschedparam(pthread_self(), SCHED_RR, &param)) {
        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, &param))
            Debug::log(WARN, "Failed to reset process scheduling strategy");
    });
}