diff options
-rw-r--r-- | src/murmur/UnixMurmur.cpp | 4 | ||||
-rw-r--r-- | src/murmur/UnixMurmur.h | 2 | ||||
-rw-r--r-- | src/murmur/main.cpp | 38 | ||||
-rw-r--r-- | src/murmur/murmur_pch.h | 1 |
4 files changed, 44 insertions, 1 deletions
diff --git a/src/murmur/UnixMurmur.cpp b/src/murmur/UnixMurmur.cpp index 799f0cce8..a42b26813 100644 --- a/src/murmur/UnixMurmur.cpp +++ b/src/murmur/UnixMurmur.cpp @@ -182,7 +182,9 @@ void UnixMurmur::handleSigHup() { ssize_t len = ::read(iHupFd[1], &tmp, sizeof(tmp)); Q_UNUSED(len); - if (! qfLog) { + if (logToSyslog) { + qWarning("Caught SIGHUP, but logging to syslog"); + } else if (! qfLog) { qWarning("Caught SIGHUP, but logfile not in use"); } else if (! qfLog->isOpen()) { qWarning("Caught SIGHUP, but logfile not in use -- interpreting as hint to quit"); diff --git a/src/murmur/UnixMurmur.h b/src/murmur/UnixMurmur.h index 6d685d797..6fde13bac 100644 --- a/src/murmur/UnixMurmur.h +++ b/src/murmur/UnixMurmur.h @@ -66,6 +66,8 @@ class UnixMurmur : public QObject { void handleSigHup(); void handleSigTerm(); public: + bool logToSyslog; + void setuid(); void initialcap(); void finalcap(); diff --git a/src/murmur/main.cpp b/src/murmur/main.cpp index e33053d65..37c03a9a0 100644 --- a/src/murmur/main.cpp +++ b/src/murmur/main.cpp @@ -54,6 +54,10 @@ static bool detach = true; static bool detach = false; #endif +#ifdef Q_OS_UNIX +static UnixMurmur *unixMurmur = NULL; +#endif + Meta *meta = NULL; static LogEmitter le; @@ -61,6 +65,29 @@ static LogEmitter le; static QStringList qlErrors; static void murmurMessageOutputQString(QtMsgType type, const QString &msg) { +#ifdef Q_OS_UNIX + if (unixMurmur->logToSyslog) { + int level; + switch (type) { + case QtDebugMsg: + level = LOG_DEBUG; + break; + case QtWarningMsg: + level = LOG_WARNING; + break; + case QtCriticalMsg: + level = LOG_CRIT; + break; + case QtFatalMsg: + default: + level = LOG_ALERT; + break; + } + syslog(level, qPrintable(msg)); + return; + } +#endif + char c; switch (type) { case QtDebugMsg: @@ -175,6 +202,7 @@ int main(int argc, char **argv) { #endif QCoreApplication a(argc, argv); UnixMurmur unixhandler; + unixMurmur = &unixhandler; unixhandler.initialcap(); #endif a.setApplicationName("Murmur"); @@ -310,7 +338,12 @@ int main(int argc, char **argv) { // need to open log file early so log dir can be root owned: // http://article.gmane.org/gmane.comp.security.oss.general/4404 +#ifdef Q_OS_UNIX + unixhandler.logToSyslog = Meta::mp.qsLogfile == "syslog"; + if (detach && ! Meta::mp.qsLogfile.isEmpty() && !unixhandler.logToSyslog) { +#else if (detach && ! Meta::mp.qsLogfile.isEmpty()) { +#endif qfLog = new QFile(Meta::mp.qsLogfile); if (! qfLog->open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) { delete qfLog; @@ -330,6 +363,11 @@ int main(int argc, char **argv) { } #endif } +#ifdef Q_OS_UNIX + } else if (detach && unixhandler.logToSyslog) { + openlog("murmurd", LOG_PID, LOG_DAEMON); + syslog(LOG_DEBUG, "murmurd syslog adapter up and running"); +#endif } else { detach = false; } diff --git a/src/murmur/murmur_pch.h b/src/murmur/murmur_pch.h index d15fc1b50..c721af45f 100644 --- a/src/murmur/murmur_pch.h +++ b/src/murmur/murmur_pch.h @@ -58,6 +58,7 @@ extern "C" { #include <sys/socket.h> #include <sys/time.h> #include <sys/resource.h> +#include <syslog.h> #ifdef Q_OS_LINUX #include <linux/types.h> // needed to work around evil magic stuff in capability.h #include <sys/capability.h> |