mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-10 10:09:14 +00:00
LibCore: Remove now-unused singleton process utilities
This commit is contained in:
parent
8362c073f3
commit
d61770c457
Notes:
sideshowbarker
2024-07-16 23:52:22 +09:00
Author: https://github.com/trflynn89
Commit: d61770c457
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/45
Reviewed-by: https://github.com/ADKaster ✅
3 changed files with 8 additions and 98 deletions
|
@ -453,57 +453,4 @@ ErrorOr<IPCProcess::ProcessPaths> IPCProcess::paths_for_process(StringView proce
|
|||
return ProcessPaths { move(socket_path), move(pid_path) };
|
||||
}
|
||||
|
||||
ErrorOr<IPCProcess::ProcessAndIPCSocket> IPCProcess::spawn_singleton_and_connect_to_process(ProcessSpawnOptions const& options)
|
||||
{
|
||||
auto [socket_path, pid_path] = TRY(paths_for_process(options.name));
|
||||
Process process { -1 };
|
||||
|
||||
if (auto existing_pid = TRY(get_process_pid(options.name, pid_path)); existing_pid.has_value()) {
|
||||
process = Process { *existing_pid };
|
||||
} else {
|
||||
auto ipc_fd = TRY(create_ipc_socket(socket_path));
|
||||
|
||||
sigset_t original_set;
|
||||
sigset_t setting_set;
|
||||
sigfillset(&setting_set);
|
||||
(void)pthread_sigmask(SIG_BLOCK, &setting_set, &original_set);
|
||||
|
||||
// FIXME: Roll this daemon implementation into `Process::disown`.
|
||||
if (auto pid = TRY(System::fork()); pid == 0) {
|
||||
(void)pthread_sigmask(SIG_SETMASK, &original_set, nullptr);
|
||||
TRY(System::setsid());
|
||||
TRY(System::signal(SIGCHLD, SIG_IGN));
|
||||
|
||||
auto& arguments = const_cast<Vector<ByteString>&>(options.arguments);
|
||||
arguments.append("--pid-file"sv);
|
||||
arguments.append(pid_path);
|
||||
|
||||
auto takeover_string = ByteString::formatted("{}:{}", options.name, TRY(System::dup(ipc_fd)));
|
||||
TRY(Environment::set("SOCKET_TAKEOVER"sv, takeover_string, Environment::Overwrite::Yes));
|
||||
|
||||
auto process = TRY(Process::spawn(options));
|
||||
{
|
||||
auto pid_file = TRY(File::open(pid_path, File::OpenMode::Write));
|
||||
TRY(pid_file->write_until_depleted(ByteString::number(process.pid())));
|
||||
}
|
||||
|
||||
TRY(System::kill(getpid(), SIGTERM));
|
||||
} else {
|
||||
auto wait_err = System::waitpid(pid);
|
||||
(void)pthread_sigmask(SIG_SETMASK, &original_set, nullptr);
|
||||
TRY(wait_err);
|
||||
}
|
||||
|
||||
auto pid = TRY(get_process_pid(options.name, pid_path));
|
||||
VERIFY(pid.has_value());
|
||||
|
||||
process = Process { *pid };
|
||||
}
|
||||
|
||||
auto ipc_socket = TRY(LocalSocket::connect(socket_path));
|
||||
TRY(ipc_socket->set_blocking(true));
|
||||
|
||||
return ProcessAndIPCSocket { move(process), move(ipc_socket) };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue