From 9776cc4e7e9037bde5d5ece69f7d1f959da4bfd5 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 6 Apr 2024 15:08:28 +0200 Subject: Resolve /proc/self/exe fullpath --- main.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index c9f21c8..e59691f 100644 --- a/main.c +++ b/main.c @@ -9,12 +9,17 @@ #include #include -static int get_self_filepath(char *buffer, size_t size) { - ssize_t bytes_written = readlink("/proc/self/exe", buffer, size - 1); +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); if(bytes_written == -1) return 0; - buffer[bytes_written] = '\0'; + self_path[bytes_written] = '\0'; + if(!realpath(self_path, buffer)) + return 0; + return 1; } @@ -115,11 +120,11 @@ int main(int argc, char **argv) { const char *user_homepath = argv[3]; char self_path[PATH_MAX]; - if(!get_self_filepath(self_path, sizeof(self_path))) + if(!get_self_filepath(self_path)) return 1; char kms_server_proxy_local_filepath[PATH_MAX]; - snprintf(kms_server_proxy_local_filepath, sizeof(kms_server_proxy_local_filepath), "%s/.local/share/gpu-screen-recorder/kms-server-proxy", user_homepath); + snprintf(kms_server_proxy_local_filepath, sizeof(kms_server_proxy_local_filepath), "%s/.local/share/gpu-screen-recorder/kms-server-proxy-1", user_homepath); if(file_has_sys_admin_capability(gsr_kms_server_filepath)) { const char *args[] = { gsr_kms_server_filepath, initial_socket_path, card_path, NULL }; -- cgit v1.2.3