-
Notifications
You must be signed in to change notification settings - Fork 0
/
signalHandler.cpp
70 lines (52 loc) · 1.44 KB
/
signalHandler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* sigHandler.cpp
*
* Created on: Mar 25, 2012
* Author: gkowshik
*/
#include "main.h"
void signal_handler(int sig)
{
if(sig == SIGTERM)
{
printf("[SigHandle] Caught SIGTERM\n");
globalShutdownToggle=1;
pthread_mutex_lock(¤tNeighboursLock);
for(map<struct NodeInfo, int>::iterator i=currentNeighbours.begin();i!=currentNeighbours.end();i++) {
printf("Close Connection to a neighbors\n");
destroyConnectionAndCleanup((*i).second);
}
pthread_mutex_unlock(¤tNeighboursLock);
shutdown(acceptServerSocket,SHUT_RDWR);
close(acceptServerSocket);
//pthread_kill(keyboard_thread,SIGUSR2);
}
if(sig == SIGALRM)
{
printf("[SigHandle] Caught SIGALARM\n");
pthread_exit(0);
}
if(sig==SIGINT)
{
printf("[SigHandle]\tCaught SIGINT, should write status file if required\n");
pthread_mutex_lock(&statusMsgLock) ;
if(statusTimerFlag)
metadata->statusFloodTimeout = 0;
printf("***Going to signal the status serialize which is on wait\n");
pthread_cond_signal(&statusMsgCV);
pthread_mutex_unlock(&statusMsgLock) ;
}
if(sig == SIGUSR1 && metadata->joinTimeOut == 0)
{
printf("[SigHandle] Caught SIGUSR1\n");
//Join request timeout
joinTimeOutFlag = 1;
printf("Close Connection\n");
destroyConnectionAndCleanup((*currentNeighbours.begin()).second);
}
if(sig == SIGUSR2)
{
printf("[SigHandle] Caught SIGUSR2\n");
}
printf("[SigHandle]\t********** Leaving sighandler thread \n");
}