1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:17:35 +00:00

LibCore: Use Core::Environment::raw_environ() instead of environment()

This commit is contained in:
Sam Atkins 2024-01-30 18:30:22 +00:00 committed by Sam Atkins
parent 40b04d4da5
commit c2bc07ef7c
4 changed files with 8 additions and 18 deletions

View file

@ -9,6 +9,7 @@
#include "Command.h" #include "Command.h"
#include <AK/Format.h> #include <AK/Format.h>
#include <AK/ScopeGuard.h> #include <AK/ScopeGuard.h>
#include <LibCore/Environment.h>
#include <LibCore/File.h> #include <LibCore/File.h>
#include <LibCore/System.h> #include <LibCore/System.h>
#include <fcntl.h> #include <fcntl.h>
@ -30,7 +31,7 @@ ErrorOr<OwnPtr<Command>> Command::create(StringView command, char const* const a
posix_spawn_file_actions_adddup2(&file_actions, stdout_fds[1], STDOUT_FILENO); posix_spawn_file_actions_adddup2(&file_actions, stdout_fds[1], STDOUT_FILENO);
posix_spawn_file_actions_adddup2(&file_actions, stderr_fds[1], STDERR_FILENO); posix_spawn_file_actions_adddup2(&file_actions, stderr_fds[1], STDERR_FILENO);
auto pid = TRY(Core::System::posix_spawnp(command, &file_actions, nullptr, const_cast<char**>(arguments), System::environment())); auto pid = TRY(Core::System::posix_spawnp(command, &file_actions, nullptr, const_cast<char**>(arguments), Core::Environment::raw_environ()));
posix_spawn_file_actions_destroy(&file_actions); posix_spawn_file_actions_destroy(&file_actions);
ArmedScopeGuard runner_kill { [&pid] { kill(pid, SIGKILL); } }; ArmedScopeGuard runner_kill { [&pid] { kill(pid, SIGKILL); } };

View file

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech> * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org> * Copyright (c) 2023-2024, Sam Atkins <atkinssj@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -10,6 +10,7 @@
#include <AK/ScopeGuard.h> #include <AK/ScopeGuard.h>
#include <AK/String.h> #include <AK/String.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibCore/Environment.h>
#include <LibCore/File.h> #include <LibCore/File.h>
#include <LibCore/Process.h> #include <LibCore/Process.h>
#include <LibCore/System.h> #include <LibCore/System.h>
@ -100,9 +101,9 @@ ErrorOr<Process> Process::spawn(ProcessSpawnOptions const& options)
pid_t pid; pid_t pid;
if (options.search_for_executable_in_path) { if (options.search_for_executable_in_path) {
pid = TRY(System::posix_spawnp(options.executable.view(), &spawn_actions, nullptr, const_cast<char**>(argv_list.get().data()), System::environment())); pid = TRY(System::posix_spawnp(options.executable.view(), &spawn_actions, nullptr, const_cast<char**>(argv_list.get().data()), Core::Environment::raw_environ()));
} else { } else {
pid = TRY(System::posix_spawn(options.executable.view(), &spawn_actions, nullptr, const_cast<char**>(argv_list.get().data()), System::environment())); pid = TRY(System::posix_spawn(options.executable.view(), &spawn_actions, nullptr, const_cast<char**>(argv_list.get().data()), Core::Environment::raw_environ()));
} }
return Process { pid }; return Process { pid };
} }

View file

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021-2022, Kenneth Myhra <kennethmyhra@serenityos.org> * Copyright (c) 2021-2022, Kenneth Myhra <kennethmyhra@serenityos.org>
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org> * Copyright (c) 2021-2024, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022, Matthias Zimmerman <matthias291999@gmail.com> * Copyright (c) 2022, Matthias Zimmerman <matthias291999@gmail.com>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
@ -48,7 +48,6 @@ static int memfd_create(char const* name, unsigned int flags)
#endif #endif
#if defined(AK_OS_MACOS) #if defined(AK_OS_MACOS)
# include <crt_externs.h>
# include <mach-o/dyld.h> # include <mach-o/dyld.h>
# include <sys/mman.h> # include <sys/mman.h>
#else #else
@ -1749,15 +1748,6 @@ ErrorOr<String> resolve_executable_from_environment(StringView filename, int fla
return Error::from_errno(ENOENT); return Error::from_errno(ENOENT);
} }
char** environment()
{
#if defined(AK_OS_MACOS)
return *_NSGetEnviron();
#else
return environ;
#endif
}
ErrorOr<ByteString> current_executable_path() ErrorOr<ByteString> current_executable_path()
{ {
char path[4096] = {}; char path[4096] = {};

View file

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021-2022, Kenneth Myhra <kennethmyhra@serenityos.org> * Copyright (c) 2021-2022, Kenneth Myhra <kennethmyhra@serenityos.org>
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org> * Copyright (c) 2021-2024, Sam Atkins <atkinssj@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -274,8 +274,6 @@ ErrorOr<void> posix_fallocate(int fd, off_t offset, off_t length);
ErrorOr<String> resolve_executable_from_environment(StringView filename, int flags = 0); ErrorOr<String> resolve_executable_from_environment(StringView filename, int flags = 0);
char** environment();
ErrorOr<ByteString> current_executable_path(); ErrorOr<ByteString> current_executable_path();
ErrorOr<Bytes> allocate(size_t count, size_t size); ErrorOr<Bytes> allocate(size_t count, size_t size);