Skip to content

Commit 102befe

Browse files
authored
remove signal handler (#641)
1 parent faf6ffd commit 102befe

File tree

2 files changed

+3
-39
lines changed

2 files changed

+3
-39
lines changed

msgq/impl_msgq.cc

+3-34
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,10 @@
22
#include <cstring>
33
#include <iostream>
44
#include <cstdlib>
5-
#include <csignal>
65
#include <cerrno>
76

87
#include "msgq/impl_msgq.h"
98

10-
11-
volatile sig_atomic_t msgq_do_exit = 0;
12-
13-
void sig_handler(int signal) {
14-
assert(signal == SIGINT || signal == SIGTERM);
15-
msgq_do_exit = 1;
16-
}
17-
18-
199
MSGQContext::MSGQContext() {
2010
}
2111

@@ -72,23 +62,14 @@ int MSGQSubSocket::connect(Context *context, std::string endpoint, std::string a
7262

7363

7464
Message * MSGQSubSocket::receive(bool non_blocking){
75-
msgq_do_exit = 0;
76-
77-
void (*prev_handler_sigint)(int);
78-
void (*prev_handler_sigterm)(int);
79-
if (!non_blocking){
80-
prev_handler_sigint = std::signal(SIGINT, sig_handler);
81-
prev_handler_sigterm = std::signal(SIGTERM, sig_handler);
82-
}
83-
8465
msgq_msg_t msg;
8566

8667
MSGQMessage *r = NULL;
8768

8869
int rc = msgq_msg_recv(&msg, q);
8970

9071
// Hack to implement blocking read with a poller. Don't use this
91-
while (!non_blocking && rc == 0 && msgq_do_exit == 0){
72+
while (!non_blocking && rc == 0){
9273
msgq_pollitem_t items[1];
9374
items[0].q = q;
9475

@@ -107,21 +88,9 @@ Message * MSGQSubSocket::receive(bool non_blocking){
10788
}
10889
}
10990

110-
111-
if (!non_blocking){
112-
std::signal(SIGINT, prev_handler_sigint);
113-
std::signal(SIGTERM, prev_handler_sigterm);
114-
}
115-
116-
errno = msgq_do_exit ? EINTR : 0;
117-
11891
if (rc > 0){
119-
if (msgq_do_exit){
120-
msgq_msg_close(&msg); // Free unused message on exit
121-
} else {
122-
r = new MSGQMessage;
123-
r->takeOwnership(msg.data, msg.size);
124-
}
92+
r = new MSGQMessage;
93+
r->takeOwnership(msg.data, msg.size);
12594
}
12695

12796
return (Message*)r;

msgq/ipc_pyx.pyx

-5
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,6 @@ cdef class SubSocket:
199199
msg = self.socket.receive(non_blocking)
200200

201201
if msg == NULL:
202-
# If a blocking read returns no message check errno if SIGINT was caught in the C++ code
203-
if errno.errno == errno.EINTR:
204-
print("SIGINT received, exiting")
205-
sys.exit(1)
206-
207202
return None
208203
else:
209204
sz = msg.getSize()

0 commit comments

Comments
 (0)