1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 21:14:59 +00:00
serenity/Userland/Libraries/LibCore/Process.h
Ali Mohammad Pur 5e1499d104 Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
2023-12-17 18:25:10 +03:30

97 lines
2.4 KiB
C++

/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, MacDue <macdue@dueutil.tech>
* Copyright (c) 2023, Sam Atkins <atkinssj@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;
};
// FIXME: Implement other file actions
}
struct ProcessSpawnOptions {
ByteString path;
Vector<ByteString> const& arguments = {};
Optional<ByteString> working_directory = {};
Vector<Variant<FileAction::OpenFile>> const& file_actions = {};
};
class Process {
AK_MAKE_NONCOPYABLE(Process);
public:
enum class KeepAsChild {
Yes,
No
};
Process(Process&& other)
: m_pid(exchange(other.m_pid, 0))
, m_should_disown(exchange(other.m_should_disown, false))
{
}
Process& operator=(Process&& other) = delete;
~Process()
{
(void)disown();
}
static ErrorOr<Process> spawn(ProcessSpawnOptions const& options);
// FIXME: Make the following 2 functions return Process instance or delete them.
static ErrorOr<pid_t> spawn(StringView path, ReadonlySpan<ByteString> arguments, ByteString working_directory = {}, KeepAsChild keep_as_child = KeepAsChild::No);
static ErrorOr<pid_t> spawn(StringView path, ReadonlySpan<StringView> arguments, ByteString working_directory = {}, KeepAsChild keep_as_child = KeepAsChild::No);
// FIXME: Remove this. char const* should not exist on this level of abstraction.
static ErrorOr<pid_t> spawn(StringView path, ReadonlySpan<char const*> 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 { return m_pid; }
ErrorOr<void> disown();
// FIXME: Make it return an exit code.
ErrorOr<bool> wait_for_termination();
private:
Process(pid_t pid)
: m_pid(pid)
, m_should_disown(true)
{
}
pid_t m_pid;
bool m_should_disown;
};
}