aboutsummaryrefslogtreecommitdiff
path: root/tools/gsr-global-hotkeys/main.c
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-11-24 23:49:24 +0100
committerdec05eba <dec05eba@protonmail.com>2024-11-24 23:49:24 +0100
commit7d19afc0ab9ca880ea51fcab186bb2c5e9604aaf (patch)
treef7e59bb991530bb6dbf811ac51cadae4f2401c98 /tools/gsr-global-hotkeys/main.c
parenta872c07f7a1a8d65ee507a33bac9b023d9d936b4 (diff)
cap_sys_admin->cap_setuid for gsr-global-hotkeys
Diffstat (limited to 'tools/gsr-global-hotkeys/main.c')
-rw-r--r--tools/gsr-global-hotkeys/main.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/tools/gsr-global-hotkeys/main.c b/tools/gsr-global-hotkeys/main.c
index 4951801..11eaee5 100644
--- a/tools/gsr-global-hotkeys/main.c
+++ b/tools/gsr-global-hotkeys/main.c
@@ -44,7 +44,7 @@ static int open_restricted(const char *path, int flags, void *user_data) {
(void)user_data;
int fd = open(path, flags);
if(fd < 0)
- fprintf(stderr, "Failed to open %s, error: %s\n", path, strerror(errno));
+ fprintf(stderr, "error: failed to open %s, error: %s\n", path, strerror(errno));
return fd < 0 ? -errno : fd;
}
@@ -178,7 +178,7 @@ static bool mapper_refresh_keymap(key_mapper *mapper) {
};
mapper->xkb_keymap = xkb_keymap_new_from_names(mapper->xkb_context, &names, XKB_KEYMAP_COMPILE_NO_FLAGS);
if(mapper->xkb_keymap == NULL) {
- fprintf(stderr, "Failed to create XKB keymap.\n");
+ fprintf(stderr, "error: failed to create XKB keymap.\n");
return false;
}
@@ -189,7 +189,7 @@ static bool mapper_refresh_keymap(key_mapper *mapper) {
mapper->xkb_state = xkb_state_new(mapper->xkb_keymap);
if(mapper->xkb_state == NULL) {
- fprintf(stderr, "Failed to create XKB state.\n");
+ fprintf(stderr, "error: failed to create XKB state.\n");
return false;
}
@@ -197,6 +197,13 @@ static bool mapper_refresh_keymap(key_mapper *mapper) {
}
int main(void) {
+ if(geteuid() != 0) {
+ if(setuid(0) == -1) {
+ fprintf(stderr, "error: failed to change user to root\n");
+ return 1;
+ }
+ }
+
struct udev *udev = udev_new();
if(!udev) {
fprintf(stderr, "error: udev_new failed\n");