diff options
-rw-r--r-- | meson_options.txt | 2 | ||||
-rwxr-xr-x | meson_post_install.sh | 2 | ||||
-rw-r--r-- | tools/gsr-global-hotkeys/main.c | 13 |
3 files changed, 12 insertions, 5 deletions
diff --git a/meson_options.txt b/meson_options.txt index 19a9a37..c568106 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,2 +1,2 @@ option('systemd', type : 'boolean', value : true, description : 'Install systemd service file') -option('capabilities', type : 'boolean', value : true, description : 'Set binary admin capability on gsr-global-hotkeys binary to allow global hotkeys')
\ No newline at end of file +option('capabilities', type : 'boolean', value : true, description : 'Set binary setuid capability on gsr-global-hotkeys binary to allow global hotkeys')
\ No newline at end of file diff --git a/meson_post_install.sh b/meson_post_install.sh index ad57569..e9a7b17 100755 --- a/meson_post_install.sh +++ b/meson_post_install.sh @@ -1,4 +1,4 @@ #!/bin/sh -/usr/sbin/setcap cap_sys_admin+ep ${MESON_INSTALL_DESTDIR_PREFIX}/bin/gsr-global-hotkeys \ +/usr/sbin/setcap cap_setuid+ep ${MESON_INSTALL_DESTDIR_PREFIX}/bin/gsr-global-hotkeys \ || echo "\n!!! Please re-run install as root\n"
\ No newline at end of file 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"); |