summaryrefslogtreecommitdiff
path: root/src/execute.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2025-02-01 16:25:17 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2025-02-01 16:25:17 +0100
commitf4b6372c1fe8d48aceb853272e0b822b967a56d7 (patch)
tree3f680f1669f2a1c079a77acc20e7da97f7e7dbec /src/execute.cc
parent69d66ac41ab66a5a5da007ccfacc1d5a9d45d819 (diff)
Use new pointerlist and envmapHEADmaster
Diffstat (limited to 'src/execute.cc')
-rw-r--r--src/execute.cc36
1 files changed, 6 insertions, 30 deletions
diff --git a/src/execute.cc b/src/execute.cc
index a905efc..ad6c2a2 100644
--- a/src/execute.cc
+++ b/src/execute.cc
@@ -4,6 +4,7 @@
#include "execute.h"
#include "ctor.h"
+#include "pointerlist.h"
#include <unistd.h>
#include <cstring>
@@ -22,27 +23,6 @@ https://stackoverflow.com/questions/4259629/what-is-the-difference-between-fork-
namespace
{
-class Env
- : public std::vector<char*>
-{
-public:
- Env(const std::vector<std::string>& args)
- {
- for(const auto& arg : args)
- {
- push_back(strdup(arg.data()));
- }
- push_back(nullptr);
- }
-
- ~Env()
- {
- for(auto ptr : *this)
- {
- free(ptr);
- }
- }
-};
int parent_waitpid(pid_t pid)
{
@@ -122,19 +102,15 @@ int execute(const ctor::settings& settings,
auto pid = vfork();
if(pid == 0)
{
- std::vector<std::string> venv;
+ EnvMap envmap((const char**)environ);
for(const auto& [key, value] : env)
{
- venv.push_back(key + "=" + value);
- }
-
- for(auto current = environ; *current; ++current)
- {
- venv.emplace_back(*current);
+ envmap.insert(key + "=" + value);
}
- Env penv(venv);
- execve(command.data(), (char**)argv.data(), penv.data());
+ auto [_, envv] = envmap.get();
+ execve(command.data(), const_cast<char* const *>(argv.data()),
+ const_cast<char* const *>(envv));
std::cout << "Could not execute " << command << ": " <<
strerror(errno) << "\n";
_exit(1); // execve only returns if an error occurred