From f4b6372c1fe8d48aceb853272e0b822b967a56d7 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 1 Feb 2025 16:25:17 +0100 Subject: Use new pointerlist and envmap --- ctor.cc | 1 + src/bootstrap.cc | 1 + src/execute.cc | 36 ++++++------------------------------ test/ctor.cc | 2 ++ 4 files changed, 10 insertions(+), 30 deletions(-) diff --git a/ctor.cc b/ctor.cc index 0edd877..67b1465 100644 --- a/ctor.cc +++ b/ctor.cc @@ -19,6 +19,7 @@ ctor::build_configurations ctorConfigs(const ctor::settings& settings) "src/execute.cc", "src/externals_manual.cc", "src/libctor.cc", + "src/pointerlist.cc", "src/rebuild.cc", "src/task.cc", "src/task_ar.cc", diff --git a/src/bootstrap.cc b/src/bootstrap.cc index 42706c1..be1b5ed 100644 --- a/src/bootstrap.cc +++ b/src/bootstrap.cc @@ -19,6 +19,7 @@ #include "tasks.cc" #include "build.cc" #include "tools.cc" +#include "pointerlist.cc" const std::filesystem::path configurationFile("configuration.cc"); const std::filesystem::path configHeaderFile("config.h"); 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 #include @@ -22,27 +23,6 @@ https://stackoverflow.com/questions/4259629/what-is-the-difference-between-fork- namespace { -class Env - : public std::vector -{ -public: - Env(const std::vector& 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 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(argv.data()), + const_cast(envv)); std::cout << "Could not execute " << command << ": " << strerror(errno) << "\n"; _exit(1); // execve only returns if an error occurred diff --git a/test/ctor.cc b/test/ctor.cc index acb232f..31c63ab 100644 --- a/test/ctor.cc +++ b/test/ctor.cc @@ -66,6 +66,7 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings) "execute_test.cc", "testmain.cc", "../src/execute.cc", + "../src/pointerlist.cc", "../src/util.cc", }, .depends = { "testprog", }, @@ -160,6 +161,7 @@ ctor::build_configurations ctorTestConfigs(const ctor::settings& settings) "../src/configure.cc", "../src/deps.cc", "../src/execute.cc", + "../src/pointerlist.cc", "../src/rebuild.cc", "../src/tasks.cc", "../src/task.cc", -- cgit v1.2.3