From 80444b8a176e1775b926f7285a8a2ac89b9f0055 Mon Sep 17 00:00:00 2001 From: Daniel Bengtsson Date: Mon, 2 Dec 2024 23:15:25 +0100 Subject: [PATCH] process_linux: Fix call to execvp --- tests/process_linux.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/process_linux.cpp b/tests/process_linux.cpp index f087f44..fefe1fe 100644 --- a/tests/process_linux.cpp +++ b/tests/process_linux.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "logger.hpp" @@ -15,9 +16,9 @@ namespace zit { using namespace std; Process::Process(const string& name, - vector argv, + vector argv, const char* cwd, - vector stop_cmd) + vector stop_cmd) : m_pid(0), m_name(name), m_stop_cmd(std::move(stop_cmd)) { pid_t ppid = getpid(); m_pid = fork(); @@ -41,8 +42,12 @@ Process::Process(const string& name, perror("chdir failed"); exit(1); } - argv.push_back(nullptr); - execvp(argv[0], const_cast(argv.data())); + vector argv_c; + argv_c.reserve(argv.size() + 1); + std::ranges::transform(argv, back_inserter(argv_c), + [](const string& s) { return const_cast(s.data()); }); + argv_c.push_back(nullptr); + execvp(argv_c[0], argv_c.data()); cerr << "Failed launching " << argv[0] << ": " << strerror(errno) << endl; _exit(1); // Important to use _exit(1) in the child branch } else {