CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Watchdog Class Reference

#include <monitor.h>

Inheritance diagram for Watchdog:
Collaboration diagram for Watchdog:

Classes

struct  ControlFlow
 
struct  CrashData
 

Public Types

typedef void(* FnOnCrash )(void)
 

Public Member Functions

 ~Watchdog ()
 
void Spawn (const std::string &crash_dump_path)
 

Static Public Member Functions

static WatchdogCreate (FnOnCrash on_crash)
 
static pid_t GetPid ()
 

Static Public Attributes

static int g_suppressed_signals [13]
 
static int g_crash_signals [8]
 

Private Types

typedef std::map< int, struct
sigaction > 
SigactionMap
 

Private Member Functions

 Watchdog (FnOnCrash on_crash)
 
void Fork ()
 
bool WaitForSupervisee ()
 
SigactionMap SetSignalHandlers (const SigactionMap &signal_handlers)
 
void Supervise ()
 
void LogEmergency (std::string msg)
 
std::string ReportStacktrace ()
 
std::string GenerateStackTrace (pid_t pid)
 
std::string ReadUntilGdbPrompt (int fd_pipe)
 
- Private Member Functions inherited from SingleCopy
 SingleCopy ()
 

Static Private Member Functions

static WatchdogMe ()
 
static void * MainWatchdogListener (void *data)
 
static void ReportSignalAndTerminate (int sig, siginfo_t *siginfo, void *context)
 
static void SendTrace (int sig, siginfo_t *siginfo, void *context)
 

Private Attributes

bool spawned_
 
std::string crash_dump_path_
 
std::string exe_path_
 
pid_t watchdog_pid_
 
UniquePtr< Pipe< kPipeWatchdog > > pipe_watchdog_
 
UniquePtr< Pipe
< kPipeWatchdogSupervisor > > 
pipe_listener_
 The supervisee makes sure its watchdog does not die. More...
 
UniquePtr< Pipe
< kPipeThreadTerminator > > 
pipe_terminate_
 Send the terminate signal to the listener. More...
 
pthread_t thread_listener_
 
FnOnCrash on_crash_
 
platform_spinlock lock_handler_
 
stack_t sighandler_stack_
 
SigactionMap old_signal_handlers_
 

Static Private Attributes

static const unsigned kSignalHandlerStacksize = 2 * 1024 * 1024
 
static const unsigned kMaxBacktrace = 64
 
static Watchdoginstance_ = NULL
 

Detailed Description

This file is part of the CernVM File System. This class can fork a watchdog process that listens on a pipe and prints a stackstrace into syslog, when cvmfs fails. The crash dump is also appended to the crash dump file, if the path is not empty. Singleton.

The watchdog process if forked on Create and put on hold. Spawn() will start the supervision and set the crash dump path. It should be called from the final supervisee pid (after daemon etc.) but preferably before any threads are started.

Note: logging should be set up before calling Create()

Definition at line 33 of file monitor.h.

Member Typedef Documentation

typedef void(* Watchdog::FnOnCrash)(void)

Crash cleanup handler signature.

Definition at line 38 of file monitor.h.

typedef std::map<int, struct sigaction> Watchdog::SigactionMap
private

Definition at line 55 of file monitor.h.

Constructor & Destructor Documentation

Watchdog::~Watchdog ( )

Definition at line 635 of file monitor.cc.

Here is the call graph for this function:

Watchdog::Watchdog ( FnOnCrash  on_crash)
explicitprivate

Definition at line 623 of file monitor.cc.

Here is the call graph for this function:

Member Function Documentation

Watchdog * Watchdog::Create ( FnOnCrash  on_crash)
static

Definition at line 70 of file monitor.cc.

Referenced by cvmcache_spawn_watchdog(), Init(), main(), swissknife::CommandSync::Main(), and PosixQuotaManager::MainCacheManager().

Here is the call graph for this function:

Here is the caller graph for this function:

void Watchdog::Fork ( )
private

Fork the watchdog process and put it on hold until Spawn() is called.

Definition at line 387 of file monitor.cc.

Here is the call graph for this function:

string Watchdog::GenerateStackTrace ( pid_t  pid)
private

Uses an external shell and gdb to create a full stack trace of the dying process. The same shell is used to force-quit the client afterwards.

Definition at line 82 of file monitor.cc.

Here is the call graph for this function:

pid_t Watchdog::GetPid ( )
static

Definition at line 172 of file monitor.cc.

Referenced by TalkManager::MainResponder().

Here is the caller graph for this function:

void Watchdog::LogEmergency ( std::string  msg)
private

Log a string to syslog and into the crash dump file. We expect ideally nothing to be logged, so that file is created on demand.

Definition at line 183 of file monitor.cc.

Here is the call graph for this function:

void * Watchdog::MainWatchdogListener ( void *  data)
staticprivate

Definition at line 556 of file monitor.cc.

Here is the call graph for this function:

static Watchdog* Watchdog::Me ( )
inlinestaticprivate

Definition at line 84 of file monitor.h.

string Watchdog::ReadUntilGdbPrompt ( int  fd_pipe)
private

Reads from the file descriptor until the specific gdb prompt is reached or the pipe gets broken.

Parameters
fd_pipethe file descriptor of the pipe to be read
Returns
the data read from the pipe

Definition at line 212 of file monitor.cc.

void Watchdog::ReportSignalAndTerminate ( int  sig,
siginfo_t *  siginfo,
void *  context 
)
staticprivate

Definition at line 289 of file monitor.cc.

Here is the call graph for this function:

string Watchdog::ReportStacktrace ( )
private

Generates useful information from the backtrace log in the pipe.

Definition at line 251 of file monitor.cc.

Here is the call graph for this function:

void Watchdog::SendTrace ( int  sig,
siginfo_t *  siginfo,
void *  context 
)
staticprivate

Definition at line 299 of file monitor.cc.

Here is the call graph for this function:

Watchdog::SigactionMap Watchdog::SetSignalHandlers ( const SigactionMap signal_handlers)
private

Sets the signal handlers of the current process according to the ones defined in the given SigactionMap.

Parameters
signal_handlersa map of SIGNAL -> struct sigaction
Returns
a SigactionMap containing the old handlers

Definition at line 366 of file monitor.cc.

Referenced by MainWatchdogListener().

Here is the caller graph for this function:

void Watchdog::Spawn ( const std::string &  crash_dump_path)

Set up the signal handling and kick off the supervision.

Definition at line 510 of file monitor.cc.

Referenced by cvmcache_spawn_watchdog(), main(), swissknife::CommandSync::Main(), PosixQuotaManager::MainCacheManager(), and Spawn().

Here is the call graph for this function:

Here is the caller graph for this function:

void Watchdog::Supervise ( )
private

Definition at line 598 of file monitor.cc.

Here is the call graph for this function:

bool Watchdog::WaitForSupervisee ( )
private

Definition at line 454 of file monitor.cc.

Here is the call graph for this function:

Member Data Documentation

std::string Watchdog::crash_dump_path_
private

Definition at line 103 of file monitor.h.

std::string Watchdog::exe_path_
private

Definition at line 104 of file monitor.h.

int Watchdog::g_crash_signals
static
Initial value:
= { SIGQUIT, SIGILL, SIGABRT,
SIGFPE, SIGSEGV, SIGBUS,
SIGPIPE, SIGXFSZ }

Signals used by crash signal handler. If received, create a stack trace.

Definition at line 52 of file monitor.h.

int Watchdog::g_suppressed_signals
static
Initial value:
= { SIGHUP, SIGINT, SIGQUIT,
SIGILL, SIGABRT, SIGBUS,
SIGFPE, SIGUSR1, SIGSEGV,
SIGUSR2, SIGTERM, SIGXCPU,
SIGXFSZ}

Signals that watchdog should not receive. If it does, report and exit.

Definition at line 48 of file monitor.h.

Referenced by AuthzExternalFetcher::ExecHelper().

Watchdog * Watchdog::instance_ = NULL
staticprivate

Definition at line 83 of file monitor.h.

Referenced by Me(), and ~Watchdog().

const unsigned Watchdog::kMaxBacktrace = 64
staticprivate

If the GDB/LLDB method of generating a stack trace fails, fall back to libc's backtrace with a maximum depth.

Definition at line 81 of file monitor.h.

const unsigned Watchdog::kSignalHandlerStacksize = 2 * 1024 * 1024
staticprivate

Preallocated memory block to make sure that signal handler don't run into stack overflows.

Definition at line 76 of file monitor.h.

platform_spinlock Watchdog::lock_handler_
private

Definition at line 113 of file monitor.h.

Referenced by Watchdog(), and ~Watchdog().

SigactionMap Watchdog::old_signal_handlers_
private

Definition at line 115 of file monitor.h.

Referenced by MainWatchdogListener().

FnOnCrash Watchdog::on_crash_
private

Definition at line 112 of file monitor.h.

UniquePtr<Pipe<kPipeWatchdogSupervisor> > Watchdog::pipe_listener_
private

The supervisee makes sure its watchdog does not die.

Definition at line 108 of file monitor.h.

Referenced by MainWatchdogListener(), and ~Watchdog().

UniquePtr<Pipe<kPipeThreadTerminator> > Watchdog::pipe_terminate_
private

Send the terminate signal to the listener.

Definition at line 110 of file monitor.h.

Referenced by MainWatchdogListener(), and ~Watchdog().

UniquePtr<Pipe<kPipeWatchdog> > Watchdog::pipe_watchdog_
private

Definition at line 106 of file monitor.h.

Referenced by ~Watchdog().

stack_t Watchdog::sighandler_stack_
private

Definition at line 114 of file monitor.h.

Referenced by Watchdog(), and ~Watchdog().

bool Watchdog::spawned_
private

Definition at line 102 of file monitor.h.

Referenced by ~Watchdog().

pthread_t Watchdog::thread_listener_
private

Definition at line 111 of file monitor.h.

Referenced by ~Watchdog().

pid_t Watchdog::watchdog_pid_
private

Definition at line 105 of file monitor.h.


The documentation for this class was generated from the following files: