Root user gets proper privilege

This commit is contained in:
hoholee12 2023-07-25 15:53:40 +09:00
parent db4c960a3b
commit 445bae198b

View file

@ -3032,16 +3032,31 @@ void thread_ctrl::set_native_priority(int priority)
} }
#elif defined(__linux__) #elif defined(__linux__)
// available niceness for nonroot: 0~19 // available niceness for nonroot: 0~19
int linuxprio = 9; // available niceness for root: -20~19
int linuxprio = 0;
id_t threadpid = gettid(); id_t threadpid = gettid();
uid_t euid = geteuid();
if (priority > 0)
if (euid == 0)
{
linuxprio = 0; linuxprio = 0;
else if (priority < 0) if (priority > 0)
linuxprio = 19; linuxprio = -6;
else if (priority < 0)
linuxprio = 6;
}
else
{
linuxprio = 6;
if (priority > 0)
linuxprio = 0;
else if (priority < 0)
linuxprio = 12;
}
// nonroot cannot increase niceness value // nonroot cannot increase niceness value
if (getpriority(PRIO_PROCESS, threadpid) < linuxprio) if ((getpriority(PRIO_PROCESS, threadpid) < linuxprio) || (euid == 0))
{ {
if (int err = setpriority(PRIO_PROCESS, threadpid, linuxprio)) if (int err = setpriority(PRIO_PROCESS, threadpid, linuxprio))
{ {