main: don't renice as non-root on non-Linux

On BSD systems only the super-user may lower priority values.

meson.build:40:0: ERROR: Dependency "libcap" not found, tried pkgconfig and cmake

src/main.cpp:7:10: fatal error: 'sys/capability.h' file not found
 #include <sys/capability.h>
          ^~~~~~~~~~~~~~~~~~
src/main.cpp:244:2: error: unknown type name 'cap_t'
        cap_t caps = cap_get_proc();
        ^
src/main.cpp:244:15: error: use of undeclared identifier 'cap_get_proc'
        cap_t caps = cap_get_proc();
                     ^
src/main.cpp:247:3: error: unknown type name 'cap_flag_value_t'
                cap_flag_value_t nicecapvalue = CAP_CLEAR;
                ^
src/main.cpp:247:35: error: use of undeclared identifier 'CAP_CLEAR'
                cap_flag_value_t nicecapvalue = CAP_CLEAR;
                                                ^
src/main.cpp:248:23: error: use of undeclared identifier 'CAP_SYS_NICE'
                cap_get_flag( caps, CAP_SYS_NICE, CAP_EFFECTIVE, &nicecapvalue );
                                    ^
src/main.cpp:248:37: error: use of undeclared identifier 'CAP_EFFECTIVE'
                cap_get_flag( caps, CAP_SYS_NICE, CAP_EFFECTIVE, &nicecapvalue );
                                                  ^
src/main.cpp:250:24: error: use of undeclared identifier 'CAP_SET'
                if ( nicecapvalue == CAP_SET )
                                     ^
This commit is contained in:
Jan Beich 2020-10-26 05:27:10 +00:00 committed by Joshie
parent ba467640a8
commit 241df252fd
2 changed files with 5 additions and 1 deletions

View file

@ -5,7 +5,9 @@
#include <mutex>
#include <vector>
#include <cstring>
#if defined(__linux__)
#include <sys/capability.h>
#endif
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/resource.h>
@ -435,6 +437,7 @@ int main(int argc, char **argv)
}
}
#if defined(__linux__)
cap_t caps = cap_get_proc();
if ( caps != nullptr )
{
@ -478,6 +481,7 @@ int main(int argc, char **argv)
{
fprintf( stderr, "No CAP_SYS_NICE, falling back to regular-priority compute and threads.\nPerformance will be affected.\n" );
}
#endif
setenv( "XWAYLAND_FORCE_ENABLE_EXTRA_MODES", "1", 1 );

View file

@ -13,7 +13,7 @@ wayland_server = dependency('wayland-server', version: '>=1.21')
wayland_protos = dependency('wayland-protocols', version: '>=1.17')
xkbcommon = dependency('xkbcommon')
thread_dep = dependency('threads')
cap_dep = dependency('libcap')
cap_dep = dependency('libcap', required: false)
sdl_dep = dependency('SDL2')
stb_dep = dependency('stb')