Skip to content
Permalink
Browse files

Support logging to syslog in Murmur

Simply set the logfile path to "syslog" and Murmur will log to syslog.

This should be stable, it has approximately 4 user-months of testing.
  • Loading branch information...
main-- authored and mkrautz committed Jul 18, 2014
1 parent dc3b78c commit 30023c5b361fa17f59e38b1689e76a28a7e49dc7
Showing with 44 additions and 1 deletion.
  1. +3 −1 src/murmur/UnixMurmur.cpp
  2. +2 −0 src/murmur/UnixMurmur.h
  3. +38 −0 src/murmur/main.cpp
  4. +1 −0 src/murmur/murmur_pch.h
@@ -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");
@@ -66,6 +66,8 @@ class UnixMurmur : public QObject {
void handleSigHup();
void handleSigTerm();
public:
bool logToSyslog;

void setuid();
void initialcap();
void finalcap();
@@ -54,13 +54,40 @@ static bool detach = true;
static bool detach = false;
#endif

#ifdef Q_OS_UNIX
static UnixMurmur *unixMurmur = NULL;
#endif

Meta *meta = NULL;

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

0 comments on commit 30023c5

Please sign in to comment.
You can’t perform that action at this time.