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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
#include "common/config.h"
#include "common/signal.h"
#include "global/signal_handler.h"
#include "common/debug.h"
#include "include/coredumpctl.h"
#include "gtest/gtest.h"
#include <errno.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include "include/ceph_assert.h"
#define dout_context g_ceph_context
static volatile sig_atomic_t got_sigusr1 = 0;
static void handle_sigusr1(int signo)
{
got_sigusr1 = 1;
}
TEST(SignalApi, SimpleInstall)
{
install_sighandler(SIGPIPE, handle_sigusr1, 0);
}
TEST(SignalApi, SimpleInstallAndTest)
{
install_sighandler(SIGPIPE, handle_sigusr1, 0);
// SIGPIPE starts out blocked
int ret = kill(getpid(), SIGPIPE);
ASSERT_EQ(ret, 0);
ASSERT_EQ(got_sigusr1, 0);
// handle SIGPIPE
sigset_t mask;
sigemptyset(&mask);
ret = sigsuspend(&mask);
if (ret == -1)
ret = errno;
// we should have gotten it
ASSERT_EQ(ret, EINTR);
ASSERT_EQ(got_sigusr1, 1);
}
TEST(SignalEffects, ErrnoTest1)
{
}
bool usr1 = false;
bool usr2 = false;
void reset()
{
usr1 = false;
usr2 = false;
}
void testhandler(int signal)
{
switch (signal) {
case SIGUSR1:
usr1 = true;
break;
case SIGUSR2:
usr2 = true;
break;
default:
ceph_abort_msg("unexpected signal");
}
}
TEST(SignalHandler, Single)
{
reset();
init_async_signal_handler();
register_async_signal_handler(SIGUSR1, testhandler);
ASSERT_TRUE(usr1 == false);
int ret = kill(getpid(), SIGUSR1);
ASSERT_EQ(ret, 0);
sleep(1);
ASSERT_TRUE(usr1 == true);
unregister_async_signal_handler(SIGUSR1, testhandler);
shutdown_async_signal_handler();
}
TEST(SignalHandler, Multiple)
{
int ret;
reset();
init_async_signal_handler();
register_async_signal_handler(SIGUSR1, testhandler);
register_async_signal_handler(SIGUSR2, testhandler);
ASSERT_TRUE(usr1 == false);
ASSERT_TRUE(usr2 == false);
ret = kill(getpid(), SIGUSR1);
ASSERT_EQ(ret, 0);
ret = kill(getpid(), SIGUSR2);
ASSERT_EQ(ret, 0);
sleep(1);
ASSERT_TRUE(usr1 == true);
ASSERT_TRUE(usr2 == true);
unregister_async_signal_handler(SIGUSR1, testhandler);
unregister_async_signal_handler(SIGUSR2, testhandler);
shutdown_async_signal_handler();
}
TEST(SignalHandler, LogInternal)
{
g_ceph_context->_log->inject_segv();
{
PrCtl unset_dumpable;
ASSERT_DEATH(derr << "foo" << dendl, ".*");
}
g_ceph_context->_log->reset_segv();
}
/*
TEST(SignalHandler, MultipleBigFd)
{
int ret;
for (int i = 0; i < 1500; i++)
::open(".", O_RDONLY);
reset();
init_async_signal_handler();
register_async_signal_handler(SIGUSR1, testhandler);
register_async_signal_handler(SIGUSR2, testhandler);
ASSERT_TRUE(usr1 == false);
ASSERT_TRUE(usr2 == false);
ret = kill(getpid(), SIGUSR1);
ASSERT_EQ(ret, 0);
ret = kill(getpid(), SIGUSR2);
ASSERT_EQ(ret, 0);
sleep(1);
ASSERT_TRUE(usr1 == true);
ASSERT_TRUE(usr2 == true);
unregister_async_signal_handler(SIGUSR1, testhandler);
unregister_async_signal_handler(SIGUSR2, testhandler);
shutdown_async_signal_handler();
}
*/
|