mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 13:19:05 +00:00
LibCore: Add System::exec_command method
This method was taken from the pls utility and its purpose is to execute a given command with all the required requirements such as providing a suitable exec environment.
This commit is contained in:
parent
942e262e86
commit
0d1af1ad63
Notes:
sideshowbarker
2024-07-17 09:49:33 +09:00
Author: https://github.com/supercomputer7
Commit: 0d1af1ad63
Pull-request: https://github.com/SerenityOS/serenity/pull/15895
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/LucasChollet
Reviewed-by: https://github.com/tslater2006
2 changed files with 28 additions and 0 deletions
|
@ -979,6 +979,29 @@ ErrorOr<void> adjtime(const struct timeval* delta, struct timeval* old_delta)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef AK_OS_SERENITY
|
||||
ErrorOr<void> exec_command(Vector<StringView>& command, bool preserve_env)
|
||||
{
|
||||
Vector<StringView> exec_environment;
|
||||
for (size_t i = 0; environ[i]; ++i) {
|
||||
StringView env_view { environ[i], strlen(environ[i]) };
|
||||
auto maybe_needle = env_view.find('=');
|
||||
|
||||
if (!maybe_needle.has_value())
|
||||
continue;
|
||||
|
||||
// FIXME: Allow a custom selection of variables once ArgsParser supports options with optional parameters.
|
||||
if (!preserve_env && env_view.substring_view(0, maybe_needle.value()) != "TERM"sv)
|
||||
continue;
|
||||
|
||||
exec_environment.append(env_view);
|
||||
}
|
||||
|
||||
TRY(Core::System::exec(command.at(0), command, Core::System::SearchInPath::Yes, exec_environment));
|
||||
return {};
|
||||
}
|
||||
#endif
|
||||
|
||||
ErrorOr<void> exec(StringView filename, Span<StringView> arguments, SearchInPath search_in_path, Optional<Span<StringView>> environment)
|
||||
{
|
||||
#ifdef AK_OS_SERENITY
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue