diff options
author | Benji Dial <benji@benjidial.net> | 2024-07-31 17:16:21 -0400 |
---|---|---|
committer | Benji Dial <benji@benjidial.net> | 2024-07-31 17:16:21 -0400 |
commit | e6915fb6dd715e39e37702a6d69c220c0f1798bf (patch) | |
tree | 2e3b59335f70f2725802d254168ceaee85faf891 /kernel | |
parent | b1cf9e5dfbc8967bd7cb2a22ec1e5e521f4e0e6e (diff) | |
download | hilbert-os-e6915fb6dd715e39e37702a6d69c220c0f1798bf.tar.gz |
remove argc, argv; arguments will be passed via environment variables
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/include/hilbert/kernel/application.hpp | 10 | ||||
-rw-r--r-- | kernel/include/hilbert/kernel/utility.hpp | 7 | ||||
-rw-r--r-- | kernel/source/application.cpp | 37 | ||||
-rw-r--r-- | kernel/source/entry.cpp | 4 | ||||
-rw-r--r-- | kernel/source/syscall.cpp | 5 |
5 files changed, 53 insertions, 10 deletions
diff --git a/kernel/include/hilbert/kernel/application.hpp b/kernel/include/hilbert/kernel/application.hpp index e7c7d2e..9c2e851 100644 --- a/kernel/include/hilbert/kernel/application.hpp +++ b/kernel/include/hilbert/kernel/application.hpp @@ -104,6 +104,7 @@ namespace hilbert::kernel::application { utility::id_allocator<generic_stream_ptr> open_streams; utility::id_allocator<socket_listener *> running_socket_listeners; + public: struct string_pair { utility::string a; utility::string b; @@ -111,6 +112,9 @@ namespace hilbert::kernel::application { utility::list<string_pair> environment_variables; + private: + string_pair *find_environment_variable(const utility::string &name); + public: utility::string name; @@ -126,10 +130,12 @@ namespace hilbert::kernel::application { process(app_memory *memory, const utility::string &name); ~process(); - //arguments are utility::move'd - void add_environment_variable( + void set_environment_variable( utility::string &&name, utility::string &&value); + void set_environment_variable( + const utility::string &name, const utility::string &value); + //null if unset utility::string *get_environment_variable(const utility::string &name); diff --git a/kernel/include/hilbert/kernel/utility.hpp b/kernel/include/hilbert/kernel/utility.hpp index b0ced32..3fe14b0 100644 --- a/kernel/include/hilbert/kernel/utility.hpp +++ b/kernel/include/hilbert/kernel/utility.hpp @@ -212,7 +212,12 @@ namespace hilbert::kernel::utility { buffer[i] = other.buffer[i]; } - vector(vector &&other) = delete; + vector(vector &&other) + : buffer(other.buffer), + buffer_len(other.buffer_len), + count(other.count) { + other.buffer = 0; + } ~vector() { if (buffer) diff --git a/kernel/source/application.cpp b/kernel/source/application.cpp index 6df49cd..cd76bd9 100644 --- a/kernel/source/application.cpp +++ b/kernel/source/application.cpp @@ -90,9 +90,42 @@ namespace hilbert::kernel::application { delete memory; //:p } - void process::add_environment_variable( + process::string_pair *process::find_environment_variable( + const utility::string &name) { + + for (auto *n = environment_variables.first; n; n = n->next) + if (n->value.a == name) + return &n->value; + + return 0; + + } + + void process::set_environment_variable( utility::string &&name, utility::string &&value) { - environment_variables.insert_end({.a = name, .b = value}); + + auto *sp = find_environment_variable(name); + if (sp) + sp->b = utility::move(value); + else + environment_variables.insert_end({ + .a = utility::move(name), + .b = utility::move(value) + }); + + } + + void process::set_environment_variable( + const utility::string &name, const utility::string &value) { + + auto *sp = find_environment_variable(name); + if (sp) + sp->b = value; + else + environment_variables.insert_end({ + .a = name, .b = value + }); + } utility::string *process::get_environment_variable( diff --git a/kernel/source/entry.cpp b/kernel/source/entry.cpp index 73e79c7..f412838 100644 --- a/kernel/source/entry.cpp +++ b/kernel/source/entry.cpp @@ -218,10 +218,6 @@ extern "C" [[noreturn]] void entry() { application::process *init_process = new application::process(init_memory, utility::string("init", 4)); - init_process->add_environment_variable( - utility::string("ARGC", 4), utility::string("1", 1)); - init_process->add_environment_variable( - utility::string("ARGV0", 5), utility::string("/bin/init", 9)); application::add_process(init_process); application::thread *init_thread = diff --git a/kernel/source/syscall.cpp b/kernel/source/syscall.cpp index 803f7d2..00590c9 100644 --- a/kernel/source/syscall.cpp +++ b/kernel/source/syscall.cpp @@ -625,8 +625,11 @@ namespace hilbert::kernel::syscall { application::process *p = new application::process(memory, file.dir_entry.name); + for (auto *n = owner->environment_variables.first; n; n = n->next) + p->set_environment_variable(n->value.a, n->value.b); + for (uint64_t i = 0; i < psi->env_var_count; ++i) - p->add_environment_variable( + p->set_environment_variable( utility::string(psi->env_vars[i].name, psi->env_vars[i].name_len), utility::string(psi->env_vars[i].value, psi->env_vars[i].value_len)); |