From 4b6b9888c570a6a6357c36e52a3eea5f16584341 Mon Sep 17 00:00:00 2001 From: Alexey Shilov Date: Thu, 13 Jan 2011 16:42:53 +0200 Subject: [PATCH] Fixes: NB#217376 - Applauncherd writes log messages, but not to syslog RevBy: Jussi Lind --- src/launcherlib/CMakeLists.txt | 2 +- src/launcherlib/booster.cpp | 1 + src/launcherlib/daemon.cpp | 1 + src/launcherlib/logger.cpp | 137 ++---------------------------- src/launcherlib/logger.h | 9 -- src/launcherlib/main.cpp | 4 +- src/launcherlib/socketmanager.cpp | 1 + 7 files changed, 13 insertions(+), 142 deletions(-) diff --git a/src/launcherlib/CMakeLists.txt b/src/launcherlib/CMakeLists.txt index 261e005..c88bfa4 100644 --- a/src/launcherlib/CMakeLists.txt +++ b/src/launcherlib/CMakeLists.txt @@ -23,7 +23,7 @@ endif(WRT_FOUND) # Set libraries to be linked. Shared libraries to be preloaded are not linked in anymore, # but dlopen():ed and listed in src/launcher/preload.h instead. -link_libraries(${LIBDL} ${QT_QTCORE_LIBRARY}) +link_libraries(${LIBDL} ) # Set executable add_library(applauncherd MODULE ${SRC} ${MOC_SRC}) diff --git a/src/launcherlib/booster.cpp b/src/launcherlib/booster.cpp index f1d06d7..b44dbd9 100644 --- a/src/launcherlib/booster.cpp +++ b/src/launcherlib/booster.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #ifdef HAVE_CREDS #include diff --git a/src/launcherlib/daemon.cpp b/src/launcherlib/daemon.cpp index 2d836cd..53b9da6 100644 --- a/src/launcherlib/daemon.cpp +++ b/src/launcherlib/daemon.cpp @@ -37,6 +37,7 @@ #include #include #include +#include Daemon * Daemon::m_instance = NULL; int Daemon::m_lockFd = -1; diff --git a/src/launcherlib/logger.cpp b/src/launcherlib/logger.cpp index 6f5fd7c..ef84baf 100644 --- a/src/launcherlib/logger.cpp +++ b/src/launcherlib/logger.cpp @@ -21,88 +21,17 @@ #include #include #include -#include -#include -#include +#include +#include -namespace -{ - const QString logDirectory("/var/log"); - const QString logFileName(logDirectory + QDir::separator() + PROG_NAME_LAUNCHER + ".log"); - const QString oldLogFileName(logFileName + ".old"); - const QString dateFormat("yyyy-MM-dd hh:mm:ss.zzz"); -} bool Logger::m_isOpened = false; -bool Logger::m_useSyslog = false; bool Logger::m_echoMode = false; -QTextStream Logger::m_logStream; -QFile Logger::m_logFile; - void Logger::openLog(const char * progName) { - if (!Logger::m_isOpened) - { - // Check if it's possible to write under /var/log - // Should make it possible to get the logs in the enviroments - // with and without syslog. - QDir logDir; - if (logDir.exists(logDirectory)) - { - // Directory exists, is it possible to create a file in it? - m_logFile.setFileName(oldLogFileName); - if (m_logFile.open(QIODevice::WriteOnly)) - { - m_logFile.close(); - m_logFile.remove(); - } - else - { - // It is not possible to write to file. Use syslog - m_useSyslog = true; - } - } - else - { - // Directory does not exist. Is it possible to create it? - if (logDir.mkdir(logDirectory) == false) - { - // Not possible to create directory. Use syslog. - m_useSyslog = true; - } - } - - // Initialize the logging interface - if (m_useSyslog == false) - { - // Remove the oldest log file - m_logFile.setFileName(oldLogFileName); - m_logFile.remove(); - - // Copy latest log file to .log.old - m_logFile.setFileName(logFileName); - m_logFile.rename(oldLogFileName); - - // Open current log file - m_logFile.setFileName(logFileName); - if (m_logFile.open(QIODevice::WriteOnly)) - { - Logger::m_logStream.setDevice(&m_logFile); - } - else - { - m_useSyslog = true; - } - } - - if (m_useSyslog) - { - openlog(progName, LOG_PID, LOG_DAEMON); - } - - Logger::m_isOpened = true; - } + openlog(progName, LOG_PID, LOG_DAEMON); + Logger::m_isOpened = true; } void Logger::closeLog() @@ -110,16 +39,7 @@ void Logger::closeLog() if (Logger::m_isOpened) { // Close syslog - if (m_useSyslog) - { - closelog(); - } - // Close log file - else - { - m_logFile.close(); - } - + closelog(); Logger::m_isOpened = false; } } @@ -136,53 +56,10 @@ void Logger::writeLog(const int priority, const char * format, va_list ap) } // Print to syslog - if (m_useSyslog) - { - vsyslog(priority, format, ap); - } - // Print to file - else - { - // Print message to a QString - QString msg; - msg.vsprintf(format, ap); - - // Print date and time to the stream - m_logStream << - QDateTime::currentDateTime().toString(dateFormat); - - // Print type prefix to the stream - switch (priority) - { - case LOG_DEBUG: - m_logStream << " [DEBUG] "; - break; - - case LOG_ERR: - m_logStream << " [ERROR] "; - break; - - case LOG_WARNING: - m_logStream << " [WARNING] "; - break; - - case LOG_INFO: - m_logStream << " [INFO] "; - break; - - default: - m_logStream << " [N/A] "; - break; - } - - // Print message to the stream - m_logStream << msg << "\n"; - m_logStream.flush(); - } + vsyslog(priority, format, ap); } } - void Logger::logDebug(const char * format, ...) { #ifndef DEBUG_LOGGING_DISABLED @@ -191,7 +68,7 @@ void Logger::logDebug(const char * format, ...) writeLog(LOG_DEBUG, format, ap); va_end(ap); #else - Q_UNUSED(format); + (void)format; #endif } diff --git a/src/launcherlib/logger.h b/src/launcherlib/logger.h index e37278f..a075ab7 100644 --- a/src/launcherlib/logger.h +++ b/src/launcherlib/logger.h @@ -20,8 +20,6 @@ #ifndef LOGGER_H #define LOGGER_H -#include -#include #include /*! @@ -104,13 +102,6 @@ private: static void writeLog(const int priority, const char * format, va_list ap); //! True if the log is open static bool m_isOpened; - //! Log file which is used if the syslog is not available - //static QFile m_logFile; - static QFile m_logFile; - //! Text stream for log file - static QTextStream m_logStream; - //! True if the syslog is available - static bool m_useSyslog; //! Echo everything to stdout if true static bool m_echoMode; }; diff --git a/src/launcherlib/main.cpp b/src/launcherlib/main.cpp index 234d98e..b8a0799 100644 --- a/src/launcherlib/main.cpp +++ b/src/launcherlib/main.cpp @@ -26,7 +26,7 @@ #include #include -#include +#define DECL_EXPORT extern "C" __attribute__ ((__visibility__("default"))) //! Signal handler to reap zombie processes void reapZombies(int) @@ -43,7 +43,7 @@ void exitLauncher(int) } //! Main function -Q_DECL_EXPORT int main(int argc, char * argv[]) +DECL_EXPORT int main(int argc, char * argv[]) { // Open the log diff --git a/src/launcherlib/socketmanager.cpp b/src/launcherlib/socketmanager.cpp index 2b2aebd..8812a88 100644 --- a/src/launcherlib/socketmanager.cpp +++ b/src/launcherlib/socketmanager.cpp @@ -24,6 +24,7 @@ #include #include #include +#include void SocketManager::initSocket(const string & socketId) {