2023-02-02 10:00:30 +00:00
|
|
|
/*
|
|
|
|
* 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>
|
|
|
|
|
2023-02-05 19:02:54 +00:00
|
|
|
ErrorOr<void> spawn_helper_process(StringView process_name, ReadonlySpan<StringView> arguments, Core::System::SearchInPath search_in_path, Optional<ReadonlySpan<StringView>> environment)
|
2023-02-02 10:00:30 +00:00
|
|
|
{
|
|
|
|
auto paths = TRY(get_paths_for_helper_process(process_name));
|
|
|
|
VERIFY(!paths.is_empty());
|
|
|
|
ErrorOr<void> result;
|
|
|
|
for (auto const& path : paths) {
|
|
|
|
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)
|
|
|
|
{
|
2023-05-25 18:30:26 +00:00
|
|
|
auto application_path = TRY(ak_string_from_qstring(QCoreApplication::applicationDirPath()));
|
2023-02-02 10:00:30 +00:00
|
|
|
Vector<String> paths;
|
2023-05-25 18:30:26 +00:00
|
|
|
|
2023-02-02 10:00:30 +00:00
|
|
|
TRY(paths.try_append(TRY(String::formatted("./{}/{}", process_name, process_name))));
|
2023-05-25 18:30:26 +00:00
|
|
|
TRY(paths.try_append(TRY(String::formatted("{}/{}/{}", application_path, process_name, process_name))));
|
|
|
|
TRY(paths.try_append(TRY(String::formatted("{}/{}", application_path, process_name))));
|
2023-02-02 10:00:30 +00:00
|
|
|
TRY(paths.try_append(TRY(String::formatted("./{}", process_name))));
|
|
|
|
// NOTE: Add platform-specific paths here
|
|
|
|
return paths;
|
|
|
|
}
|