Permalink
Browse files

Fix order of startup for logging in logserver

So that the logserver's logs are in the same order as other programs, we need
to half-start LoggingThread, then half-start LogServerThread (so the ZeroMQ
queues are available to attach to).  After that, both threads are welcome to
continue on their merry way.

Also, tweaked the SIGHUP handler log message to match the others.
  • Loading branch information...
1 parent 7270557 commit 8e195035ee0664207c007bb0b4592e95437560d8 @Beirdo Beirdo committed May 10, 2012
View
3 mythtv/libs/libmythbase/logging.cpp
@@ -268,7 +268,10 @@ void LoggerThread::run(void)
LOG(VB_GENERAL, LOG_INFO, "Added logging to the console");
if (m_locallogs)
+ {
+ logServerWait();
m_zmqContext = logServerThread->getZMQContext();
+ }
else
{
m_zmqContext = nzmqt::createDefaultContext(NULL);
View
21 mythtv/libs/libmythbase/loggingserver.cpp
@@ -654,7 +654,7 @@ void LogServerThread::run(void)
this, SLOT(handleSigHup()));
/* Setup SIGHUP */
- LOG(VB_GENERAL, LOG_NOTICE, "Setting up SIGHUP handler");
+ LOG(VB_GENERAL, LOG_INFO, "Setup SIGHUP handler");
struct sigaction sa;
sa.sa_handler = logSighup;
sigemptyset( &sa.sa_mask );
@@ -678,9 +678,11 @@ void LogServerThread::run(void)
m_zmqPubSock = m_zmqContext->createSocket(nzmqt::ZMQSocket::TYP_PUB);
m_zmqPubSock->bindTo("inproc://loggers");
- logThreadStarted.wakeAll();
+ // cerr << "wake all" << endl;
locker.unlock();
-
+ logThreadStarted.wakeAll();
+ // cerr << "unlock" << endl;
+
m_heartbeatTimer = new QTimer(this);
connect(m_heartbeatTimer, SIGNAL(timeout()), this, SLOT(checkHeartBeats()));
m_heartbeatTimer->start(1000);
@@ -1112,10 +1114,12 @@ void logServerStart(void)
if (!logServerThread)
logServerThread = new LogServerThread();
+ // cerr << "starting server" << endl;
QMutexLocker locker(&logThreadStartedMutex);
logServerThread->start();
logThreadStarted.wait(locker.mutex());
-
+ locker.unlock();
+ // cerr << "done starting server" << endl;
}
/// \brief Entry point for stopping logging for an application
@@ -1135,6 +1139,15 @@ void logServerStop(void)
}
}
+void logServerWait(void)
+{
+ // cerr << "waiting" << endl;
+ QMutexLocker locker(&logThreadStartedMutex);
+ logThreadStarted.wait(locker.mutex());
+ locker.unlock();
+ // cerr << "done waiting" << endl;
+}
+
void FileLogger::receivedMessage(const QList<QByteArray> &msg)
{
// Filter on the clientId
View
1 mythtv/libs/libmythbase/loggingserver.h
@@ -24,6 +24,7 @@ class LoggingItem;
MBASE_PUBLIC void logServerStart(void);
MBASE_PUBLIC void logServerStop(void);
+void logServerWait(void);
/// \brief Base class for the various logging mechanisms
class LoggerBase : public QObject {
View
5 mythtv/programs/mythlogserver/main.cpp
@@ -80,14 +80,13 @@ int main(int argc, char *argv[])
if (retval != GENERIC_EXIT_OK)
return retval;
- // Must be started before ConfigureLogging()
- logServerStart();
-
bool daemonize = cmdline.toBool("daemon");
QString mask("general");
if ((retval = cmdline.ConfigureLogging(mask, daemonize)) != GENERIC_EXIT_OK)
return retval;
+ logServerStart();
+
if (daemonize)
// Don't listen to console input if daemonized
close(0);

0 comments on commit 8e19503

Please sign in to comment.