CernVM-FS  2.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
monitor.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_MONITOR_H_
6 #define CVMFS_MONITOR_H_
7 
8 #include <pthread.h>
9 #include <signal.h>
10 #include <sys/types.h>
11 #include <unistd.h>
12 
13 #include <map>
14 #include <string>
15 
16 #include "platform.h"
17 
18 struct Pipe;
19 
25 class Watchdog {
26  public:
27  static Watchdog *Create(const std::string &crash_dump_path);
28  static pid_t GetPid();
29  ~Watchdog();
30  void Spawn();
31  void RegisterOnCrash(void (*CleanupOnCrash)(void));
32 
33  static void *MainWatchdogListener(void *data);
34 
35  private:
36  typedef std::map<int, struct sigaction> SigactionMap;
37 
38  struct CrashData {
39  int signal;
40  int sys_errno;
41  pid_t pid;
42  };
43 
44  struct ControlFlow {
45  enum Flags {
49  };
50  };
51 
56  static const unsigned kSignalHandlerStacksize = 2 * 1024 * 1024; // 2 MB
61  static const unsigned kMaxBacktrace = 64;
62 
64  static Watchdog *Me() { return instance_; }
65 
66  static void SendTrace(int sig, siginfo_t *siginfo, void *context);
67 
68  explicit Watchdog(const std::string &crash_dump_path);
69  SigactionMap SetSignalHandlers(const SigactionMap &signal_handlers);
70  void Supervise();
71  void LogEmergency(std::string msg);
72  std::string ReportStacktrace();
73  std::string GenerateStackTrace(pid_t pid);
74  std::string ReadUntilGdbPrompt(int fd_pipe);
75 
76  bool spawned_;
77  std::string crash_dump_path_;
78  std::string exe_path_;
85  pthread_t thread_listener_;
86  void (*on_crash_)(void);
90 };
91 
92 namespace monitor {
93 // TODO(jblomer): move me
94 unsigned GetMaxOpenFiles();
95 } // namespace monitor
96 
97 #endif // CVMFS_MONITOR_H_
Watchdog(const std::string &crash_dump_path)
Definition: monitor.cc:547
void Supervise()
Definition: monitor.cc:515
std::map< int, struct sigaction > SigactionMap
Definition: monitor.h:36
std::string GenerateStackTrace(pid_t pid)
Definition: monitor.cc:70
std::string ReportStacktrace()
Definition: monitor.cc:247
SigactionMap old_signal_handlers_
Definition: monitor.h:89
static void SendTrace(int sig, siginfo_t *siginfo, void *context)
Definition: monitor.cc:288
static Watchdog * Create(const std::string &crash_dump_path)
Definition: monitor.cc:59
static Watchdog * Me()
Definition: monitor.h:64
void Spawn()
Definition: monitor.cc:376
void LogEmergency(std::string msg)
Definition: monitor.cc:174
std::string exe_path_
Definition: monitor.h:78
static Watchdog * instance_
Definition: monitor.h:63
stack_t sighandler_stack_
Definition: monitor.h:88
static pid_t GetPid()
Definition: monitor.cc:160
pthread_t thread_listener_
Definition: monitor.h:85
pthread_spinlock_t platform_spinlock
Pipe * pipe_watchdog_
Definition: monitor.h:80
std::string ReadUntilGdbPrompt(int fd_pipe)
Definition: monitor.cc:203
static void * MainWatchdogListener(void *data)
Definition: monitor.cc:474
unsigned GetMaxOpenFiles()
Definition: monitor.cc:600
Pipe * pipe_terminate_
Send the terminate signal to the listener.
Definition: monitor.h:84
SigactionMap SetSignalHandlers(const SigactionMap &signal_handlers)
Definition: monitor.cc:355
bool spawned_
Definition: monitor.h:76
static const unsigned kSignalHandlerStacksize
Definition: monitor.h:56
~Watchdog()
Definition: monitor.cc:563
void RegisterOnCrash(void(*CleanupOnCrash)(void))
Definition: monitor.cc:239
Definition: posix.h:184
void(* on_crash_)(void)
Definition: monitor.h:86
Pipe * pipe_listener_
The supervisee makes sure its watchdog does not die.
Definition: monitor.h:82
pid_t watchdog_pid_
Definition: monitor.h:79
platform_spinlock lock_handler_
Definition: monitor.h:87
std::string crash_dump_path_
Definition: monitor.h:77
static const unsigned kMaxBacktrace
Definition: monitor.h:61