mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
866609c682
Some checks are pending
CI / Lagom (false, NO_FUZZ, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (false, FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
104 lines
2.3 KiB
C++
104 lines
2.3 KiB
C++
/*
|
|
* Copyright (c) 2021, Andreas Kling <andreas@ladybird.org>
|
|
* Copyright (c) 2022, MacDue <macdue@dueutil.tech>
|
|
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
|
|
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/ByteString.h>
|
|
#include <AK/Forward.h>
|
|
#include <AK/Span.h>
|
|
#include <LibCore/File.h>
|
|
|
|
namespace Core {
|
|
|
|
namespace FileAction {
|
|
|
|
struct OpenFile {
|
|
ByteString path;
|
|
File::OpenMode mode = File::OpenMode::NotOpen;
|
|
int fd = -1;
|
|
mode_t permissions = 0600;
|
|
};
|
|
|
|
struct CloseFile {
|
|
int fd { -1 };
|
|
};
|
|
|
|
// FIXME: Implement other file actions
|
|
|
|
}
|
|
|
|
struct ProcessSpawnOptions {
|
|
StringView name {};
|
|
ByteString executable {};
|
|
bool search_for_executable_in_path { false };
|
|
Vector<ByteString> const& arguments {};
|
|
Optional<ByteString> working_directory {};
|
|
|
|
using FileActionType = Variant<FileAction::OpenFile, FileAction::CloseFile>;
|
|
Vector<FileActionType> file_actions {};
|
|
};
|
|
|
|
class Process {
|
|
AK_MAKE_NONCOPYABLE(Process);
|
|
|
|
public:
|
|
enum class KeepAsChild {
|
|
Yes,
|
|
No
|
|
};
|
|
|
|
Process(Process&& other);
|
|
Process& operator=(Process&& other);
|
|
~Process();
|
|
|
|
static ErrorOr<Process> spawn(ProcessSpawnOptions const& options);
|
|
static Process current();
|
|
|
|
static ErrorOr<Process> spawn(StringView path, ReadonlySpan<ByteString> arguments, ByteString working_directory = {}, KeepAsChild keep_as_child = KeepAsChild::No);
|
|
static ErrorOr<Process> spawn(StringView path, ReadonlySpan<StringView> arguments, ByteString working_directory = {}, KeepAsChild keep_as_child = KeepAsChild::No);
|
|
|
|
static ErrorOr<String> get_name();
|
|
enum class SetThreadName {
|
|
No,
|
|
Yes,
|
|
};
|
|
static ErrorOr<void> set_name(StringView, SetThreadName = SetThreadName::No);
|
|
|
|
static void wait_for_debugger_and_break();
|
|
static ErrorOr<bool> is_being_debugged();
|
|
|
|
pid_t pid() const;
|
|
|
|
#ifndef AK_OS_WINDOWS
|
|
ErrorOr<void> disown();
|
|
#endif
|
|
|
|
ErrorOr<int> wait_for_termination();
|
|
|
|
private:
|
|
#ifndef AK_OS_WINDOWS
|
|
Process(pid_t pid = -1)
|
|
: m_pid(pid)
|
|
, m_should_disown(true)
|
|
{
|
|
}
|
|
|
|
pid_t m_pid;
|
|
bool m_should_disown;
|
|
#else
|
|
Process(void* handle = 0)
|
|
: m_handle(handle)
|
|
{
|
|
}
|
|
|
|
void* m_handle;
|
|
#endif
|
|
};
|
|
|
|
}
|