summaryrefslogtreecommitdiff
path: root/kernel/source
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/source')
-rw-r--r--kernel/source/application.cpp37
-rw-r--r--kernel/source/entry.cpp4
-rw-r--r--kernel/source/syscall.cpp5
3 files changed, 39 insertions, 7 deletions
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));