Serenity Operating System
at master 34 lines 1.2 kB view raw
1/* 2 * Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include "HelperProcess.h" 8#include "Utilities.h" 9#include <AK/String.h> 10#include <QCoreApplication> 11 12ErrorOr<void> spawn_helper_process(StringView process_name, ReadonlySpan<StringView> arguments, Core::System::SearchInPath search_in_path, Optional<ReadonlySpan<StringView>> environment) 13{ 14 auto paths = TRY(get_paths_for_helper_process(process_name)); 15 VERIFY(!paths.is_empty()); 16 ErrorOr<void> result; 17 for (auto const& path : paths) { 18 result = Core::System::exec(path, arguments, search_in_path, environment); 19 if (!result.is_error()) 20 break; 21 } 22 23 return result; 24} 25 26ErrorOr<Vector<String>> get_paths_for_helper_process(StringView process_name) 27{ 28 Vector<String> paths; 29 TRY(paths.try_append(TRY(String::formatted("./{}/{}", process_name, process_name)))); 30 TRY(paths.try_append(TRY(String::formatted("{}/{}", TRY(ak_string_from_qstring(QCoreApplication::applicationDirPath())), process_name)))); 31 TRY(paths.try_append(TRY(String::formatted("./{}", process_name)))); 32 // NOTE: Add platform-specific paths here 33 return paths; 34}