-
Notifications
You must be signed in to change notification settings - Fork 29
/
UnixSignalTest.cpp
74 lines (64 loc) · 2.51 KB
/
UnixSignalTest.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
71
72
73
74
/*
* Copyright 2014 Range Networks, Inc.
*
* This software is distributed under the terms of the GNU Affero Public License.
* See the COPYING file in the main directory for details.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cstdlib>
#include "UnixSignal.h"
#include "Configuration.h"
#include "Logger.h"
ConfigurationTable gConfig;
void test1(int sig) { printf("Test 1, signal %d\n", sig); }
void test2(int sig) { printf("Test 2, signal %d\n", sig); }
void test3(int sig) { printf("Test 3, signal %d\n", sig); }
void test4(int sig) { printf("Test 4, signal %d\n", sig); }
void test5(int sig) { printf("Test 5, signal %d\n", sig); }
void test6(int sig) { printf("Test 6, signal %d\n", sig); }
void registerFuncs(int sig)
{
gSigVec.Register(test1, sig);
gSigVec.Register(test2, sig);
gSigVec.Register(test3, sig);
gSigVec.Register(test4, sig);
gSigVec.Register(test5, sig);
gSigVec.Register(test6, sig);
}
int main(int argc, char *argv[])
{
gLogInit("UnixSignalTest","DEBUG",LOG_LOCAL7);
registerFuncs(SIGINT);
registerFuncs(SIGHUP);
registerFuncs(SIGTERM);
printf("Test1 @ %p\n", test1);
printf("Test2 @ %p\n", test2);
printf("Test3 @ %p\n", test3);
printf("Test4 @ %p\n", test4);
printf("Test5 @ %p\n", test5);
printf("Test6 @ %p\n", test6);
printf("\n");
gSigVec.Dump();
printf("Run this three times. First time, do a 'kill %d' to test SIGTERM\n", getpid());
printf("Second time, do a 'kill -%d %d' to test SIGHUP\n", SIGHUP, getpid());
printf("Third time, do a Control-C to test SIGINT\n");
printf("\n");
printf("Output should iterate through tests 1-6 with the correct signal number\n");
printf("%d for SIGTERM, %d for SIGHUP, %d for SIGINT\n",
SIGTERM, SIGHUP, SIGINT);
while(true)
sleep(60);
return 0;
}