31std::string g_ignore_ctrl_c;
36 (void)!write(STDOUT_FILENO, g_ignore_ctrl_c.data(), g_ignore_ctrl_c.size());
40void IgnoreCtrlC(std::string message)
43 g_ignore_ctrl_c = std::move(message);
44 struct sigaction sa{};
45 sa.sa_handler = HandleCtrlC;
46 sigemptyset(&sa.sa_mask);
47 sa.sa_flags = SA_RESTART;
48 sigaction(SIGINT, &sa,
nullptr);
56 : m_exe_name(exe_name), m_process_argv0(process_argv0), m_init(
init),
60 std::unique_ptr<interfaces::Init> spawnProcess(
const char* new_exe_name)
override
63 int fd = m_process->spawn(new_exe_name, m_process_argv0, pid);
64 LogDebug(::BCLog::IPC,
"Process %s pid %i launched\n", new_exe_name, pid);
65 auto init = m_protocol->connect(fd, m_exe_name);
66 Ipc::addCleanup(*
init, [
this, new_exe_name, pid] {
67 int status = m_process->waitSpawned(pid);
68 LogDebug(::BCLog::IPC,
"Process %s pid %i exited with status %i\n", new_exe_name, pid, status);
72 bool startSpawnedProcess(
int argc,
char* argv[],
int&
exit_status)
override
76 if (!m_process->checkSpawned(argc, argv, fd)) {
79 IgnoreCtrlC(
strprintf(
"[%s] SIGINT received — waiting for parent to shut down.\n", m_exe_name));
80 m_protocol->serve(fd, m_exe_name, m_init);
84 std::unique_ptr<interfaces::Init> connectAddress(std::string& address)
override
86 if (address.empty() || address ==
"0")
return nullptr;
88 if (address ==
"auto") {
96 }
catch (
const std::system_error& e) {
98 if (e.code() == std::errc::connection_refused || e.code() == std::errc::no_such_file_or_directory) {
106 return m_protocol->connect(fd, m_exe_name);
108 void listenAddress(std::string& address)
override
111 m_protocol->listen(fd, m_exe_name, m_init);
113 void disconnectIncoming()
override
115 m_protocol->disconnectIncoming();
117 void addCleanup(std::type_index type,
void* iface, std::function<
void()> cleanup)
override
119 m_protocol->addCleanup(type, iface, std::move(cleanup));
121 Context& context()
override {
return m_protocol->context(); }
122 const char* m_exe_name;
123 const char* m_process_argv0;
125 std::unique_ptr<Protocol> m_protocol;
126 std::unique_ptr<Process> m_process;
132std::unique_ptr<Ipc>
MakeIpc(
const char* exe_name,
const char* process_argv0,
Init&
init)
134 return std::make_unique<ipc::IpcImpl>(exe_name, process_argv0,
init);
std::unique_ptr< interfaces::Init > init
fs::path GetDataDirNet() const
Get data directory path with appended network identifier.
Initial interface created when a process is first started, and used to give and get access to other i...
Interface providing access to interprocess-communication (IPC) functionality.
#define LogDebug(category,...)
std::unique_ptr< Ipc > MakeIpc(const char *exe_name, const char *process_argv0, Init &init)
Return implementation of Ipc interface.
std::unique_ptr< Protocol > MakeCapnpProtocol()
std::unique_ptr< Process > MakeProcess()
Constructor for Process interface.