From 100f9d5de33a5137f316451739602399b4b8d72c Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Tue, 22 Dec 2020 10:38:39 +0300 Subject: [PATCH] Fix error and remove useless code --- base/daemon/BaseDaemon.cpp | 23 +++-------------------- base/daemon/BaseDaemon.h | 20 -------------------- 2 files changed, 3 insertions(+), 40 deletions(-) diff --git a/base/daemon/BaseDaemon.cpp b/base/daemon/BaseDaemon.cpp index f6a904ac0a8..19bbca508bc 100644 --- a/base/daemon/BaseDaemon.cpp +++ b/base/daemon/BaseDaemon.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -474,7 +473,6 @@ BaseDaemon::~BaseDaemon() void BaseDaemon::terminate() { - getTaskManager().cancelAll(); if (::raise(SIGTERM) != 0) throw Poco::SystemException("cannot terminate process"); } @@ -568,7 +566,6 @@ void BaseDaemon::initialize(Application & self) { closeFDs(); - task_manager = std::make_unique(); ServerApplication::initialize(self); /// now highest priority (lowest value) is PRIO_APPLICATION = -100, we want higher! @@ -805,23 +802,6 @@ void BaseDaemon::logRevision() const + ", PID " + std::to_string(getpid())); } -/// Makes server shutdown if at least one Poco::Task have failed. -void BaseDaemon::exitOnTaskError() -{ - Poco::Observer obs(*this, &BaseDaemon::handleNotification); - getTaskManager().addObserver(obs); -} - -/// Used for exitOnTaskError() -void BaseDaemon::handleNotification(Poco::TaskFailedNotification *_tfn) -{ - task_failed = true; - Poco::AutoPtr fn(_tfn); - Poco::Logger * lg = &(logger()); - LOG_ERROR(lg, "Task '{}' failed. Daemon is shutting down. Reason - {}", fn->task()->name(), fn->reason().displayText()); - ServerApplication::terminate(); -} - void BaseDaemon::defineOptions(Poco::Util::OptionSet & new_options) { new_options.addOption( @@ -905,6 +885,9 @@ void BaseDaemon::shouldSetupWatchdog(char * argv0_) void BaseDaemon::setupWatchdog() { + /// Initialize in advance to avoid double initialization in forked processes. + DateLUT::instance(); + std::string original_process_name; if (argv0) original_process_name = argv0; diff --git a/base/daemon/BaseDaemon.h b/base/daemon/BaseDaemon.h index 1b3661fab24..0fb5bb47b2d 100644 --- a/base/daemon/BaseDaemon.h +++ b/base/daemon/BaseDaemon.h @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -26,9 +25,6 @@ #include -namespace Poco { class TaskManager; } - - /// \brief Base class for applications that can run as daemons. /// /// \code @@ -61,9 +57,6 @@ public: /// Определяет параметр командной строки void defineOptions(Poco::Util::OptionSet & new_options) override; - /// Заставляет демон завершаться, если хотя бы одна задача завершилась неудачно - void exitOnTaskError(); - /// Завершение демона ("мягкое") void terminate(); @@ -137,16 +130,8 @@ public: void shouldSetupWatchdog(char * argv0_); protected: - /// Возвращает TaskManager приложения - /// все методы task_manager следует вызывать из одного потока - /// иначе возможен deadlock, т.к. joinAll выполняется под локом, а любой метод тоже берет лок - Poco::TaskManager & getTaskManager() { return *task_manager; } - virtual void logRevision() const; - /// Используется при exitOnTaskError() - void handleNotification(Poco::TaskFailedNotification *); - /// thread safe virtual void handleSignal(int signal_id); @@ -170,15 +155,10 @@ protected: virtual std::string getDefaultCorePath() const; - std::unique_ptr task_manager; - std::optional pid_file; std::atomic_bool is_cancelled{false}; - /// Флаг устанавливается по сообщению из Task (при аварийном завершении). - bool task_failed = false; - bool log_to_console = false; /// Событие, чтобы проснуться во время ожидания