From 83f41d1491dcf226a10016433657e3dc24c434b9 Mon Sep 17 00:00:00 2001 From: MacDue Date: Sat, 4 Feb 2023 15:45:06 +0000 Subject: [PATCH] SystemServer: Revert back to inheriting environments again This reverts the SystemServer exec() logic to how it was before 81bd91c, but now with some extra TRY()s. This allows the HOME var to always be propagated from LoginServer which prevents needing to unveil() /etc/passwd everywhere. --- Userland/Services/SystemServer/Service.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Userland/Services/SystemServer/Service.cpp b/Userland/Services/SystemServer/Service.cpp index d83e29d03a..d484b4fae7 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;