MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / initializeTerminationAndSignalProcessing

Method initializeTerminationAndSignalProcessing

src/Daemon/BaseDaemon.cpp:448–496  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

446extern const char * GIT_HASH;
447
448void BaseDaemon::initializeTerminationAndSignalProcessing()
449{
450 CrashWriter::initialize(config());
451 if (config().getBool("send_crash_reports.enabled", false)
452 && config().getBool("send_crash_reports.send_logical_errors", false)
453 && CrashWriter::initialized())
454 {
455 LOG_DEBUG(&logger(), "Sending logical errors is enabled");
456 Exception::callback = [](std::string_view format_string, int code, bool remote, const Exception::Trace & trace)
457 {
458 if (!remote && code == ErrorCodes::LOGICAL_ERROR)
459 {
460 CrashWriter::FramePointers frame_pointers;
461 for (size_t i = 0; i < trace.size(); ++i)
462 frame_pointers[i] = trace[i];
463 CrashWriter::onException(code, format_string, frame_pointers, /* offset= */ 0, trace.size());
464 }
465 };
466 }
467
468 /// We want to avoid SIGPIPE when working with sockets and pipes, and just handle return value/errno instead.
469 blockSignals({SIGPIPE});
470
471 /// Setup signal handlers.
472 HandledSignals::instance().setupTerminateHandler();
473 HandledSignals::instance().setupCommonDeadlySignalHandlers();
474 HandledSignals::instance().setupCommonTerminateRequestSignalHandlers();
475 HandledSignals::instance().addSignalHandler({SIGHUP}, closeLogsSignalHandler, true);
476 HandledSignals::instance().addSignalHandler({SIGCHLD}, childSignalHandler, true);
477
478 /// Set up Poco ErrorHandler for Poco Threads.
479 static KillingErrorHandler killing_error_handler;
480 Poco::ErrorHandler::set(&killing_error_handler);
481
482 signal_listener = std::make_unique<SignalListener>(this, getLogger("BaseDaemon"), [this](int, bool) { onTerminateRequestSignal(); });
483
484#if (defined(__ELF__) && !defined(OS_FREEBSD)) || defined(OS_DARWIN)
485 build_id = SymbolIndex::instance().getBuildIDHex();
486#endif
487
488 signal_listener_thread.start(*signal_listener);
489
490#if defined(OS_LINUX)
491 std::string executable_path = getExecutablePath();
492
493 if (!executable_path.empty())
494 stored_binary_hash = Elf(executable_path).getStoredBinaryHash();
495#endif
496}
497
498void BaseDaemon::logRevision() const
499{

Callers

nothing calls this directly

Calls 15

initializeFunction · 0.85
loggerFunction · 0.85
blockSignalsFunction · 0.85
getExecutablePathFunction · 0.85
setupTerminateHandlerMethod · 0.80
addSignalHandlerMethod · 0.80
getBuildIDHexMethod · 0.80
setFunction · 0.50
getLoggerFunction · 0.50
ElfClass · 0.50

Tested by

no test coverage detected