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.
This commit is contained in:
x3
2026-09-08 09:23:14 +00:00
parent 4bff4f3db2
commit e47ac11be1
+12 -10
View File
@@ -6,6 +6,7 @@
#include <ctime> #include <ctime>
#include <fstream> #include <fstream>
#include <string> #include <string>
#include <vector>
#include <unistd.h> #include <unistd.h>
#include "config.h" #include "config.h"
#include "rsync_manager.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"); g_print("x3-backup requires root privileges. Re-launching with pkexec...\n");
std::string cmd = "pkexec"; /* Build argv for exec: pkexec + original args + NULL */
for (int i = 0; i < argc; i++) { std::vector<const char*> new_argv;
std::string arg = argv[i]; new_argv.push_back("pkexec");
if (arg.find(' ') != std::string::npos) for (int i = 0; i < argc; i++)
cmd += " \"" + arg + "\""; new_argv.push_back(argv[i]);
else new_argv.push_back(nullptr);
cmd += " " + arg;
} execvp("pkexec", const_cast<char* const*>(new_argv.data()));
int ret = system(cmd.c_str()); /* If execvp returns, it failed */
exit(ret); perror("execvp pkexec");
exit(1);
} }
static std::string get_log_path() { static std::string get_log_path() {