diff options
-rw-r--r-- | main.c | 26 |
1 files changed, 17 insertions, 9 deletions
@@ -9,15 +9,14 @@ #include <sys/sendfile.h> #include <sys/capability.h> -static int get_self_filepath(char *buffer) { - char self_path[PATH_MAX]; - - ssize_t bytes_written = readlink("/proc/self/exe", self_path, sizeof(self_path) - 1); +static int readlink_realpath(const char *filepath, char *buffer) { + char symlinked_path[PATH_MAX]; + ssize_t bytes_written = readlink(filepath, symlinked_path, sizeof(symlinked_path) - 1); if(bytes_written == -1) return 0; - self_path[bytes_written] = '\0'; - if(!realpath(self_path, buffer)) + symlinked_path[bytes_written] = '\0'; + if(!realpath(symlinked_path, buffer)) return 0; return 1; @@ -120,7 +119,7 @@ int main(int argc, char **argv) { const char *user_homepath = argv[3]; char self_path[PATH_MAX]; - if(!get_self_filepath(self_path)) + if(!readlink_realpath("/proc/self/exe", self_path)) return 1; char kms_server_proxy_local_filepath[PATH_MAX]; @@ -130,8 +129,17 @@ int main(int argc, char **argv) { const char *args[] = { gsr_kms_server_filepath, initial_socket_path, card_path, NULL }; return execv(args[0], (char *const*)args); } else if(file_has_sys_admin_capability(kms_server_proxy_local_filepath)) { - if(strcmp(self_path, kms_server_proxy_local_filepath) != 0) { - const char *args[] = { kms_server_proxy_local_filepath, initial_socket_path, card_path, user_homepath, NULL }; + /* Need to resolve kms_server_proxy_local_filepath because /home can be a symlink to another location */ + char kms_server_proxy_local_filepath_full[PATH_MAX]; + if(!readlink_realpath(kms_server_proxy_local_filepath, kms_server_proxy_local_filepath_full)) + return 1; + + /* + Run cached ~/.local/share/gpu-screen-recorder/kms-server-proxy which has sys admin capability. + The one in flatpak location gets capabilities overwritten on flatpak update. + */ + if(strcmp(self_path, kms_server_proxy_local_filepath_full) != 0) { + const char *args[] = { kms_server_proxy_local_filepath_full, initial_socket_path, card_path, user_homepath, NULL }; return execv(args[0], (char *const*)args); } |