LibCore: Make singleton process helpers public

This commit is contained in:
Andrew Kaster 2024-04-26 15:18:36 -06:00 committed by Tim Flynn
commit 12a9702acb
Notes: sideshowbarker 2024-07-17 03:27:40 +09:00
2 changed files with 11 additions and 7 deletions

View file

@ -379,7 +379,7 @@ ErrorOr<IPCProcess::ProcessAndIPCSocket> IPCProcess::spawn_and_connect_to_proces
return ProcessAndIPCSocket { move(process), move(ipc_socket) };
}
static ErrorOr<Optional<pid_t>> get_process_pid(StringView process_name, StringView pid_path)
ErrorOr<Optional<pid_t>> IPCProcess::get_process_pid(StringView process_name, StringView pid_path)
{
if (System::stat(pid_path).is_error())
return OptionalNone {};
@ -416,7 +416,7 @@ static ErrorOr<Optional<pid_t>> get_process_pid(StringView process_name, StringV
}
// This is heavily based on how SystemServer's Service creates its socket.
static ErrorOr<int> create_ipc_socket(ByteString const& socket_path)
ErrorOr<int> IPCProcess::create_ipc_socket(ByteString const& socket_path)
{
if (!System::stat(socket_path).is_error())
TRY(System::unlink(socket_path));
@ -444,11 +444,7 @@ static ErrorOr<int> create_ipc_socket(ByteString const& socket_path)
return socket_fd;
}
struct ProcessPaths {
ByteString socket_path;
ByteString pid_path;
};
static ErrorOr<ProcessPaths> paths_for_process(StringView process_name)
ErrorOr<IPCProcess::ProcessPaths> IPCProcess::paths_for_process(StringView process_name)
{
auto runtime_directory = TRY(StandardPaths::runtime_directory());
auto socket_path = ByteString::formatted("{}/{}.socket", runtime_directory, process_name);

View file

@ -138,6 +138,14 @@ public:
return ProcessAndIPCClient<ClientType> { move(process), move(client) };
}
struct ProcessPaths {
ByteString socket_path;
ByteString pid_path;
};
static ErrorOr<ProcessPaths> paths_for_process(StringView process_name);
static ErrorOr<Optional<pid_t>> get_process_pid(StringView process_name, StringView pid_path);
static ErrorOr<int> create_ipc_socket(ByteString const& socket_path);
pid_t pid() const { return m_process.pid(); }
private: