From e47ac11be14fe02755dd81934b6c5d675331a971 Mon Sep 17 00:00:00 2001 From: x3 Date: Tue, 8 Sep 2026 09:23:14 +0000 Subject: [PATCH] fix: use execvp instead of system() for privilege escalation system() blocked and prevented pkexec from re-launching the program. execvp replaces the process, allowing pkexec to take over properly. --- src/main.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index cd69fb7..336675c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "config.h" #include "rsync_manager.h" @@ -24,16 +25,17 @@ static void escalate_privileges(int argc, char* argv[]) { g_print("x3-backup requires root privileges. Re-launching with pkexec...\n"); - std::string cmd = "pkexec"; - for (int i = 0; i < argc; i++) { - std::string arg = argv[i]; - if (arg.find(' ') != std::string::npos) - cmd += " \"" + arg + "\""; - else - cmd += " " + arg; - } - int ret = system(cmd.c_str()); - exit(ret); + /* Build argv for exec: pkexec + original args + NULL */ + std::vector new_argv; + new_argv.push_back("pkexec"); + for (int i = 0; i < argc; i++) + new_argv.push_back(argv[i]); + new_argv.push_back(nullptr); + + execvp("pkexec", const_cast(new_argv.data())); + /* If execvp returns, it failed */ + perror("execvp pkexec"); + exit(1); } static std::string get_log_path() {