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 <fstream>
#include <string>
#include <vector>
#include <unistd.h>
#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<const char*> 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<char* const*>(new_argv.data()));
/* If execvp returns, it failed */
perror("execvp pkexec");
exit(1);
}
static std::string get_log_path() {