mirror of https://github.com/Icinga/icinga2.git
Make sure the Livestatus listener thread terminates after SIGTERM
fixes #8295
This commit is contained in:
parent
03a509f419
commit
88788685d3
|
@ -344,7 +344,7 @@ Socket::Ptr Socket::Accept(void)
|
|||
return new Socket(fd);
|
||||
}
|
||||
|
||||
bool Socket::Poll(bool read, bool write)
|
||||
bool Socket::Poll(bool read, bool write, struct timeval *timeout)
|
||||
{
|
||||
int rc;
|
||||
|
||||
|
@ -362,7 +362,7 @@ bool Socket::Poll(bool read, bool write)
|
|||
FD_ZERO(&exceptfds);
|
||||
FD_SET(GetFD(), &exceptfds);
|
||||
|
||||
rc = select(GetFD() + 1, &readfds, &writefds, &exceptfds, NULL);
|
||||
rc = select(GetFD() + 1, &readfds, &writefds, &exceptfds, timeout);
|
||||
|
||||
if (rc < 0) {
|
||||
Log(LogCritical, "Socket")
|
||||
|
@ -378,7 +378,7 @@ bool Socket::Poll(bool read, bool write)
|
|||
pfd.events = (read ? POLLIN : 0) | (write ? POLLOUT : 0);
|
||||
pfd.revents = 0;
|
||||
|
||||
rc = poll(&pfd, 1, -1);
|
||||
rc = poll(&pfd, 1, timeout ? (timeout->tv_sec + 1000 + timeout->tv_usec / 1000) : -1);
|
||||
|
||||
if (rc < 0) {
|
||||
Log(LogCritical, "Socket")
|
||||
|
|
|
@ -57,7 +57,7 @@ public:
|
|||
void Listen(void);
|
||||
Socket::Ptr Accept(void);
|
||||
|
||||
bool Poll(bool read, bool write);
|
||||
bool Poll(bool read, bool write, struct timeval *timeout = NULL);
|
||||
|
||||
void MakeNonBlocking(void);
|
||||
|
||||
|
|
|
@ -151,10 +151,17 @@ void LivestatusListener::ServerThreadProc(void)
|
|||
|
||||
try {
|
||||
for (;;) {
|
||||
timeval tv = { 0, 500000 };
|
||||
|
||||
if (m_Listener->Poll(true, false, &tv)) {
|
||||
Socket::Ptr client = m_Listener->Accept();
|
||||
Log(LogNotice, "LivestatusListener", "Client connected");
|
||||
Utility::QueueAsyncCallback(boost::bind(&LivestatusListener::ClientHandler, this, client), LowLatencyScheduler);
|
||||
}
|
||||
|
||||
if (!IsActive())
|
||||
break;
|
||||
}
|
||||
} catch (std::exception&) {
|
||||
Log(LogCritical, "ListenerListener", "Cannot accept new connection.");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue