Add support to CommonLib? to support google core dumper.

This commit is contained in:
dgotwisner 2014-03-31 11:15:28 +02:00 committed by Michael Iedema
parent 3a2602c75d
commit 9c17f09fe6
3 changed files with 29 additions and 7 deletions

View File

@ -91,11 +91,11 @@ BitVectorTest_LDADD = libcommon.la $(SQLITE_LA)
InterthreadTest_SOURCES = InterthreadTest.cpp
InterthreadTest_LDADD = libcommon.la $(SQLITE_LA)
InterthreadTest_LDFLAGS = -lpthread
InterthreadTest_LDFLAGS = -lpthread -lcoredumper
SocketsTest_SOURCES = SocketsTest.cpp
SocketsTest_LDADD = libcommon.la $(SQLITE_LA)
SocketsTest_LDFLAGS = -lpthread
SocketsTest_LDFLAGS = -lpthread -lcoredumper
TimevalTest_SOURCES = TimevalTest.cpp
TimevalTest_LDADD = libcommon.la
@ -110,10 +110,10 @@ ConfigurationTest_SOURCES = ConfigurationTest.cpp
ConfigurationTest_LDADD = libcommon.la $(SQLITE_LA)
SelfDetectTest_SOURCES = SelfDetectTest.cpp
SelfDetectTest_LDADD = libcommon.la $(SQLITE_LA)
SelfDetectTest_LDADD = libcommon.la $(SQLITE_LA) -lcoredumper
UnixSignalTest_SOURCES = UnixSignalTest.cpp
UnixSignalTest_LDADD = libcommon.la $(SQLITE_LA)
UnixSignalTest_LDADD = libcommon.la $(SQLITE_LA) -lcoredumper
# ReportingTest_SOURCES = ReportingTest.cpp
# ReportingTest_LDADD = libcommon.la $(SQLITE_LA)

View File

@ -31,6 +31,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include "coredumper.h"
#include "UnixSignal.h"
#include "Logger.h"
@ -53,8 +54,23 @@ static void _sigHandler(int sig)
void UnixSignal::Handler(int sig)
{
//TODO: Code should go here to generate the core file, before we change too
// much of the data in the program.
// Only write core files for the signals that need core
switch(sig)
{
case SIGQUIT: case SIGILL: case SIGABRT: case SIGFPE: case SIGSEGV:
case SIGBUS: case SIGSYS: case SIGTRAP: case SIGXCPU: case SIGXFSZ:
{
char buf[BUFSIZ];
if (mAddPid)
snprintf(buf, sizeof(buf)-1, "%s.%d", mCoreFile.c_str(), getpid());
else
snprintf(buf, sizeof(buf)-1, "%s", mCoreFile.c_str());
WriteCoreDump(buf);
}
break;
default:
break;
}
printf("Processing signal vector for sig %d\n", sig);
mLock[sig].lock();
@ -72,8 +88,10 @@ UnixSignal::UnixSignal(void)
for (int i = 0; i < C_NSIG; i++)
{
mListHandlers[i].clear();
signal(i, _sigHandler);
//signal(i, _sigHandler);
}
mAddPid = false;
mCoreFile = "core";
}
UnixSignal::~UnixSignal(void)
@ -93,6 +111,7 @@ void UnixSignal::Register(sighandler_t handler, int sig) // register the handler
return;
}
mLock[sig].lock();
signal(sig, _sigHandler); // only catch signals that have been registered
mListHandlers[sig].insert(mListHandlers[sig].end(), handler);
mLock[sig].unlock();
}

View File

@ -31,6 +31,8 @@ public:
private:
std::list<sighandler_t> mListHandlers[C_NSIG]; // list of signal handlers to call for all signals
Mutex mLock[C_NSIG];
bool mAddPid; // if true file is file.pid
std::string mCoreFile; // name of file to save to
public:
UnixSignal(void);
~UnixSignal(void);
@ -38,6 +40,7 @@ public:
void Register(sighandler_t handler, int sig); // register a signal handler with the system
void Handler(int sig); // main signal handler, iterates through mListHandlers
void Dump(void); // debug dump of list
inline void CoreName(const std::string &coreFile, bool addPid) { mCoreFile = coreFile; mAddPid = addPid; }
};
extern UnixSignal gSigVec;