1 /* 2 BAREOS® - Backup Archiving REcovery Open Sourced 3 4 Copyright (C) 2019-2019 Bareos GmbH & Co. KG 5 6 This program is Free Software; you can redistribute it and/or 7 modify it under the terms of version three of the GNU Affero General Public 8 License as published by the Free Software Foundation and included 9 in the file LICENSE. 10 11 This program is distributed in the hope that it will be useful, but 12 WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Affero General Public License for more details. 15 16 You should have received a copy of the GNU Affero General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19 02110-1301, USA. 20 */ 21 22 #include "include/bareos.h" 23 #include <chrono> 24 25 namespace TimerThread { 26 struct Timer; 27 } 28 29 class JobControlRecord; 30 class BareosSocket; 31 32 class WatchdogTimer { 33 public: 34 WatchdogTimer(JobControlRecord* jcr = nullptr); 35 ~WatchdogTimer(); 36 37 void Start(std::chrono::milliseconds interval); 38 void Stop(); 39 40 JobControlRecord* jcr_ = nullptr; GetTimerControlledItem()41 const TimerThread::Timer* GetTimerControlledItem() const 42 { 43 return timer_item; 44 } 45 46 protected: 47 TimerThread::Timer* timer_item = nullptr; 48 49 // deleted: 50 WatchdogTimer() = delete; 51 WatchdogTimer(const WatchdogTimer& other) = delete; 52 WatchdogTimer(const WatchdogTimer&& other) = delete; 53 WatchdogTimer& operator=(const WatchdogTimer& rhs) = delete; 54 WatchdogTimer& operator=(const WatchdogTimer&& rhs) = delete; 55 }; 56 57 class BThreadWatchdog : public WatchdogTimer { 58 public: 59 BThreadWatchdog(JobControlRecord* jcr); 60 BThreadWatchdog(std::chrono::milliseconds waittime, JobControlRecord* jcr); 61 ~BThreadWatchdog() = default; 62 63 pthread_t thread_id_; 64 static void Callback(TimerThread::Timer* timer); 65 66 private: 67 void Init(); 68 }; 69 70 class BProcessWatchdog : public WatchdogTimer { 71 public: 72 pid_t pid_; 73 bool killed_ = false; 74 }; 75 76 class BSockWatchdog : public WatchdogTimer { 77 public: 78 BareosSocket* bsock_; 79 }; 80