Commit a55eba7f authored by Robert Ricci's avatar Robert Ricci

Add a signal handler that calls exit() - without this, there are some

things (like finishing writing the gmon.out file when profiling) that
don't happen when you control-c or kill the program.
parent 955b9617
......@@ -54,6 +54,7 @@ void writeToConnections(multimap<Time, Connection *> & schedule);
void addNewPeer(fd_set * readable);
void readFromPeers(fd_set * readable);
void packetCapture(fd_set * readable);
void exitHandler(int signal);
int main(int argc, char * argv[])
{
......@@ -288,6 +289,17 @@ void init(void)
global::maxReader = -1;
logInit(stderr, LOG_EVERYTHING, true);
/*
* Install a signal handler so that we can catch control-C's, etc.
*/;
struct sigaction action;
action.sa_handler = exitHandler;
sigemptyset(&action.sa_mask);
action.sa_flags = 0;
sigaction(SIGTERM,&action,NULL);
sigaction(SIGINT,&action,NULL);
srandom(getpid());
switch (global::connectionModelArg)
{
......@@ -774,3 +786,8 @@ int acceptServer(int acceptfd, struct sockaddr_in * remoteAddress,
setDescriptor(resultfd);
return resultfd;
}
void exitHandler(int signal) {
logWrite(EXCEPTION,"Killed with signal %i, cleaning up",signal);
exit(0);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment