aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2023-07-26 05:14:01 +0200
committerdec05eba <dec05eba@protonmail.com>2023-07-26 05:14:01 +0200
commit15a7c2f1b038be695e1e40f4dfdba180fda6d525 (patch)
tree9dd0accb94976517a1dbbb48e1a3c584291c802a
parent4ad0118f359d954f9e5276ca6bf29a51e6dfa559 (diff)
cap_sys_nice, set caps on gsr-kms-server and gpu-screen-recorder
-rwxr-xr-xinstall.sh2
-rw-r--r--src/egl.c17
2 files changed, 18 insertions, 1 deletions
diff --git a/install.sh b/install.sh
index fe0ab2c..983aaf7 100755
--- a/install.sh
+++ b/install.sh
@@ -9,6 +9,8 @@ cd "$script_dir"
strip gsr-kms-server
strip gpu-screen-recorder
rm -f "/usr/local/bin/gpu-screen-recorder"
+setcap cap_sys_admin+ep gsr-kms-server
+setcap cap_sys_nice+ep gpu-screen-recorder
install -Dm755 "gsr-kms-server" "/usr/bin/gsr-kms-server"
install -Dm755 "gpu-screen-recorder" "/usr/bin/gpu-screen-recorder"
diff --git a/src/egl.c b/src/egl.c
index 2875f88..00a5b22 100644
--- a/src/egl.c
+++ b/src/egl.c
@@ -10,6 +10,7 @@
#include <wayland-egl.h>
#include "../external/wlr-export-dmabuf-unstable-v1-client-protocol.h"
#include <unistd.h>
+#include <sys/capability.h>
// Move this shit to a separate wayland file, and have a separate file for x11.
@@ -206,6 +207,18 @@ static gsr_wayland_output* get_wayland_output_by_name(gsr_egl *egl, const char *
return NULL;
}
+static void reset_cap_nice(void) {
+ cap_t caps = cap_get_proc();
+ if(!caps)
+ return;
+
+ const cap_value_t cap_to_remove = CAP_SYS_NICE;
+ cap_set_flag(caps, CAP_EFFECTIVE, 1, &cap_to_remove, CAP_CLEAR);
+ cap_set_flag(caps, CAP_PERMITTED, 1, &cap_to_remove, CAP_CLEAR);
+ cap_set_proc(caps);
+ cap_free(caps);
+}
+
// TODO: Create egl context without surface (in other words, x11/wayland agnostic, doesn't require x11/wayland dependency)
static bool gsr_egl_create_window(gsr_egl *self, bool wayland) {
EGLConfig ecfg;
@@ -219,7 +232,7 @@ static bool gsr_egl_create_window(gsr_egl *self, bool wayland) {
const int32_t ctxattr[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
- EGL_CONTEXT_PRIORITY_LEVEL_IMG, EGL_CONTEXT_PRIORITY_HIGH_IMG,
+ EGL_CONTEXT_PRIORITY_LEVEL_IMG, EGL_CONTEXT_PRIORITY_HIGH_IMG, /* requires cap_sys_nice, ignored otherwise */
EGL_NONE, EGL_NONE
};
@@ -294,9 +307,11 @@ static bool gsr_egl_create_window(gsr_egl *self, bool wayland) {
goto fail;
}
+ reset_cap_nice();
return true;
fail:
+ reset_cap_nice();
gsr_egl_unload(self);
return false;
}