Skip to content
Browse files

Shutdown is now clean and smooooth.

  • Loading branch information...
1 parent 35299d1 commit cf0d2d6d7a60d5e6954e1f3e0671f945c6435031 @Beirdo Beirdo committed Apr 25, 2012
View
13 mythtv/libs/libmythbase/logging.cpp
@@ -259,7 +259,7 @@ void LoggerThread::run(void)
m_zmqContext = logServerThread->getZMQContext();
else
{
- m_zmqContext = nzmqt::createDefaultContext(this);
+ m_zmqContext = nzmqt::createDefaultContext(NULL);
m_zmqContext->start();
}
@@ -333,8 +333,11 @@ void LoggerThread::run(void)
qLock.relock();
}
- delete m_zmqSocket;
- delete m_zmqContext;
+ m_zmqSocket->setLinger(0);
+ m_zmqSocket->close();
+
+ if (!locallogs)
+ delete m_zmqContext;
logThreadFinished = true;
@@ -419,7 +422,8 @@ void LoggerThread::handleItem(LoggingItem *item)
if (item->m_message[0] != '\0')
{
// Send it to mythlogserver
- m_zmqSocket->sendMessage(item->toByteArray());
+ if (!logThreadFinished)
+ m_zmqSocket->sendMessage(item->toByteArray());
}
}
@@ -659,6 +663,7 @@ void LogPrintLine( uint64_t mask, LogLevel_t level, const char *file, int line,
item = logQueue.dequeue();
qLock.unlock();
logThread->handleItem(item);
+ logThread->logConsole(item);
item->deleteItem();
qLock.relock();
}
View
12 mythtv/libs/libmythbase/logging.h
@@ -5,6 +5,7 @@
#include <QMutex>
#include <QQueue>
#include <QTime>
+#include <QPointer>
#include <stdint.h>
#include <time.h>
@@ -159,6 +160,9 @@ class LoggingItem: public QObject
class LoggerThread : public QObject, public MThread
{
Q_OBJECT
+
+ friend void LogPrintLine(uint64_t, LogLevel_t, const char *, int,
+ const char *, int, const char *, ... );
public:
LoggerThread(QString filename, bool progress, bool quiet, QString table,
int facility);
@@ -169,7 +173,6 @@ class LoggerThread : public QObject, public MThread
void handleItem(LoggingItem *item);
void fillItem(LoggingItem *item);
private:
- bool logConsole(LoggingItem *item);
QWaitCondition *m_waitNotEmpty; ///< Condition variable for waiting
/// for the queue to not be empty
/// Protected by logQueueMutex
@@ -188,8 +191,11 @@ class LoggerThread : public QObject, public MThread
int m_facility; ///< Cached syslog facility (or -1 to disable)
pid_t m_pid; ///< Cached pid value
- nzmqt::ZMQContext *m_zmqContext; ///< ZeroMQ context to use in this logger
- nzmqt::ZMQSocket *m_zmqSocket; ///< ZeroMQ socket to talk to mythlogserver
+ nzmqt::ZMQContext *m_zmqContext; ///< ZeroMQ context to use
+ nzmqt::ZMQSocket *m_zmqSocket; ///< ZeroMQ socket to talk to
+ /// mythlogserver
+ protected:
+ bool logConsole(LoggingItem *item);
protected slots:
void messageReceived(const QList<QByteArray>&);
View
34 mythtv/libs/libmythbase/loggingserver.cpp
@@ -131,10 +131,12 @@ FileLogger::~FileLogger()
{
if( m_opened )
{
- LOG(VB_GENERAL, LOG_INFO, "Removed logging to the console");
+ LOG(VB_GENERAL, LOG_INFO, QString("Removed logging to %1")
+ .arg(m_handle));
}
- delete m_zmqSock;
+ m_zmqSock->setLinger(0);
+ m_zmqSock->close();
}
/// \brief Reopen the logfile after a SIGHUP. Log files only (no console).
@@ -234,7 +236,8 @@ SyslogLogger::~SyslogLogger()
LOG(VB_GENERAL, LOG_INFO, "Removing syslogging");
closelog();
- delete m_zmqSock;
+ m_zmqSock->setLinger(0);
+ m_zmqSock->close();
}
@@ -307,7 +310,8 @@ DatabaseLogger::~DatabaseLogger()
stopDatabaseAccess();
- delete m_zmqSock;
+ m_zmqSock->setLinger(0);
+ m_zmqSock->close();
}
/// \brief Stop logging to the database and wait for the thread to stop.
@@ -603,7 +607,7 @@ void LogServerThread::run(void)
logThreadFinished = false;
QMutexLocker locker(&logThreadStartedMutex);
- m_zmqContext = nzmqt::createDefaultContext(this);
+ m_zmqContext = nzmqt::createDefaultContext(NULL);
nzmqt::PollingZMQContext *ctx = static_cast<nzmqt::PollingZMQContext *>
(m_zmqContext);
ctx->start();
@@ -641,8 +645,24 @@ void LogServerThread::run(void)
logThreadFinished = true;
- delete m_zmqPubSock;
- delete m_zmqInSock;
+ m_zmqPubSock->setLinger(0);
+ m_zmqPubSock->close();
+ m_zmqInSock->setLinger(0);
+ m_zmqInSock->close();
+
+ LoggerList loggers;
+
+ {
+ QMutexLocker lock(&loggerMapMutex);
+ loggers = loggerMap.values();
+ }
+
+ while (!loggers.isEmpty())
+ {
+ LoggerBase *logger = loggers.takeFirst();
+ delete logger;
+ }
+
delete m_zmqContext;
RunEpilog();
View
7 mythtv/programs/mythlogserver/main.cpp
@@ -25,6 +25,8 @@ using namespace std;
namespace {
void cleanup()
{
+ logStop();
+ logServerStop();
delete gContext;
gContext = NULL;
}
@@ -52,7 +54,7 @@ static void qt_exit(int)
{
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
- QCoreApplication::exit(GENERIC_EXIT_OK);
+ qApp->exit(GENERIC_EXIT_OK);
}
int main(int argc, char *argv[])
@@ -107,8 +109,7 @@ int main(int argc, char *argv[])
return GENERIC_EXIT_NO_MYTHCONTEXT;
}
- while (true)
- usleep(100000);
+ qApp->exec();
return GENERIC_EXIT_OK;
}

0 comments on commit cf0d2d6

Please sign in to comment.
Something went wrong with that request. Please try again.