/*******************************************************************************
* Main.cc Tms process
* T.Barnaby, BEAM Ltd, 2007-02-07
*******************************************************************************
*/
#include <stdio.h>
#include <syslog.h>
#include <unistd.h>
#include <signal.h>
#include <sys/resource.h>
#include <sys/mman.h>
#include <main.h>
#include <Control.h>
#include <BDebug.h>
#include <ucontext.h>
#include <Debug.h>
#define COREDUMP 0
typedef void (*SigFunction)(int, siginfo_t*, void*);
Config config;
int realTime;
void sigCrash(int sig, siginfo_t* sigInfo, void* context){
ucontext_t* ucontext = (ucontext_t*)context;
char strBuf[1024];
time_t t;
BDebugBacktrace bt;
t = time(0);
sprintf(strBuf, "TmsServer: Version %s crashed with signal %d at location: 0x%x accessing 0x%p on %s",
VERSION, sig, ucontext->uc_mcontext.gregs[REG_EIP], sigInfo->si_addr, ctime(&t));
bt.dumpBacktraceSyslog(strBuf);
bt.dumpBacktraceStdout(strBuf);
bt.dumpBacktraceFile("/var/log/tmsServerCrash", strBuf);
bt.dumpBacktraceFile("/var/log/tmsServer.log", strBuf);
_exit(1);
}
void signalSet(int sigNumber, SigFunction sigFunction){
struct sigaction sigAction;
sigAction.sa_sigaction = sigFunction;
sigemptyset(&sigAction.sa_mask);
sigAction.sa_flags = SA_SIGINFO;
sigAction.sa_restorer = 0;
sigaction(sigNumber, &sigAction, 0);
}
void usage(){