Make sure the Livestatus listener thread terminates after SIGTERM

fixes #8295
This commit is contained in:
Gunnar Beutner 2015-01-29 11:39:06 +01:00
parent 03a509f419
commit 88788685d3
3 changed files with 14 additions and 7 deletions

View File

@ -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")

View File

@ -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);

View File

@ -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.");
}