diff --git a/Userland/Services/SystemServer/Service.cpp b/Userland/Services/SystemServer/Service.cpp index d83e29d03a7..d484b4fae7b 100644 --- a/Userland/Services/SystemServer/Service.cpp +++ b/Userland/Services/SystemServer/Service.cpp @@ -193,12 +193,9 @@ ErrorOr Service::spawn(int socket_fd) } } - auto environment = TRY(StringBuilder::create()); - TRY(environment.try_append(m_environment)); - if (!m_sockets.is_empty()) { // The new descriptor is !CLOEXEC here. - TRY(environment.try_appendff(" SOCKET_TAKEOVER={}", TRY(socket_takeover_builder.to_string()))); + TRY(Core::System::setenv("SOCKET_TAKEOVER"sv, socket_takeover_builder.string_view(), true)); } if (m_account.has_value() && m_account.value().uid() != getuid()) { @@ -207,13 +204,20 @@ ErrorOr Service::spawn(int socket_fd) dbgln("Failed to drop privileges (GID={}, UID={})\n", account.gid(), account.uid()); exit(1); } - TRY(environment.try_appendff(" HOME={}", account.home_directory())); + TRY(Core::System::setenv("HOME"sv, account.home_directory(), true)); } - auto arguments = TRY(StringBuilder::create()); - TRY(arguments.try_appendff("{} {}", m_executable_path, m_extra_arguments)); + TRY(m_environment.view().for_each_split_view(' ', SplitBehavior::Nothing, [&](auto env) { + return Core::System::putenv(env); + })); - TRY(Core::System::exec(m_executable_path, arguments.string_view().split_view(' '), Core::System::SearchInPath::No, environment.string_view().split_view(' '))); + Vector arguments; + TRY(arguments.try_append(m_executable_path)); + TRY(m_extra_arguments.view().for_each_split_view(' ', SplitBehavior::Nothing, [&](auto arg) { + return arguments.try_append(arg); + })); + + TRY(Core::System::exec(m_executable_path, arguments, Core::System::SearchInPath::No)); } else if (!m_multi_instance) { // We are the parent. m_pid = pid;