mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 10:37:34 +00:00
LibCore: Add System::environment
Move this from an internal function of Core::Process so that it can be used elsewhere.
This commit is contained in:
parent
806808f406
commit
cb920b23cc
3 changed files with 16 additions and 16 deletions
|
@ -21,20 +21,6 @@
|
||||||
# include <syscall.h>
|
# include <syscall.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(AK_OS_MACOS)
|
|
||||||
# include <crt_externs.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static char** environment()
|
|
||||||
{
|
|
||||||
#if defined(AK_OS_MACOS)
|
|
||||||
return *_NSGetEnviron();
|
|
||||||
#else
|
|
||||||
extern char** environ;
|
|
||||||
return environ;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
struct ArgvList {
|
struct ArgvList {
|
||||||
|
@ -77,11 +63,11 @@ struct ArgvList {
|
||||||
if (!m_working_directory.is_empty())
|
if (!m_working_directory.is_empty())
|
||||||
posix_spawn_file_actions_addchdir(&spawn_actions, m_working_directory.characters());
|
posix_spawn_file_actions_addchdir(&spawn_actions, m_working_directory.characters());
|
||||||
|
|
||||||
auto pid = TRY(System::posix_spawn(m_path.view(), &spawn_actions, nullptr, const_cast<char**>(get().data()), environment()));
|
auto pid = TRY(System::posix_spawn(m_path.view(), &spawn_actions, nullptr, const_cast<char**>(get().data()), System::environment()));
|
||||||
if (keep_as_child == Process::KeepAsChild::No)
|
if (keep_as_child == Process::KeepAsChild::No)
|
||||||
TRY(System::disown(pid));
|
TRY(System::disown(pid));
|
||||||
#else
|
#else
|
||||||
auto pid = TRY(System::posix_spawn(m_path.view(), nullptr, nullptr, const_cast<char**>(get().data()), environment()));
|
auto pid = TRY(System::posix_spawn(m_path.view(), nullptr, nullptr, const_cast<char**>(get().data()), System::environment()));
|
||||||
// FIXME: Support keep_as_child outside Serenity.
|
// FIXME: Support keep_as_child outside Serenity.
|
||||||
(void)keep_as_child;
|
(void)keep_as_child;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -43,7 +43,10 @@ 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 <sys/mman.h>
|
# include <sys/mman.h>
|
||||||
|
#else
|
||||||
|
extern char** environ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define HANDLE_SYSCALL_RETURN_VALUE(syscall_name, rc, success_value) \
|
#define HANDLE_SYSCALL_RETURN_VALUE(syscall_name, rc, success_value) \
|
||||||
|
@ -1714,4 +1717,13 @@ 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
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,4 +271,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();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue