mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:37:34 +00:00
Ladybird: Abstract spawning helper processes into separate methods
This will let us use the same path discovery methods for WebContent, SQLServer, and any other helper processes we need to launch.
This commit is contained in:
parent
792258afe8
commit
3e6d790cf0
4 changed files with 56 additions and 6 deletions
35
Ladybird/HelperProcess.cpp
Normal file
35
Ladybird/HelperProcess.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "HelperProcess.h"
|
||||
#include "Utilities.h"
|
||||
#include <AK/String.h>
|
||||
#include <QCoreApplication>
|
||||
|
||||
ErrorOr<void> spawn_helper_process(StringView process_name, Span<StringView> arguments, Core::System::SearchInPath search_in_path, Optional<Span<StringView>> environment)
|
||||
{
|
||||
auto paths = TRY(get_paths_for_helper_process(process_name));
|
||||
VERIFY(!paths.is_empty());
|
||||
ErrorOr<void> result;
|
||||
for (auto const& path : paths) {
|
||||
arguments[0] = path.bytes_as_string_view();
|
||||
result = Core::System::exec(path, arguments, search_in_path, environment);
|
||||
if (!result.is_error())
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
ErrorOr<Vector<String>> get_paths_for_helper_process(StringView process_name)
|
||||
{
|
||||
Vector<String> paths;
|
||||
TRY(paths.try_append(TRY(String::formatted("./{}/{}", process_name, process_name))));
|
||||
TRY(paths.try_append(TRY(String::formatted("{}/{}", TRY(ak_string_from_qstring(QCoreApplication::applicationDirPath())), process_name))));
|
||||
TRY(paths.try_append(TRY(String::formatted("./{}", process_name))));
|
||||
// NOTE: Add platform-specific paths here
|
||||
return paths;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue