diff options
Diffstat (limited to 'src/murmur/UnixMurmur.cpp')
-rw-r--r-- | src/murmur/UnixMurmur.cpp | 81 |
1 files changed, 42 insertions, 39 deletions
diff --git a/src/murmur/UnixMurmur.cpp b/src/murmur/UnixMurmur.cpp index 2b2abd0ec..68159177e 100644 --- a/src/murmur/UnixMurmur.cpp +++ b/src/murmur/UnixMurmur.cpp @@ -5,8 +5,8 @@ #include "UnixMurmur.h" -#include "Meta.h" #include "EnvUtils.h" +#include "Meta.h" #include <QtCore/QAbstractEventDispatcher> #include <QtCore/QCoreApplication> @@ -18,9 +18,9 @@ #include <signal.h> #ifdef Q_OS_LINUX -# include <sys/capability.h> -# include <sys/prctl.h> -# include <sys/resource.h> +# include <sys/capability.h> +# include <sys/prctl.h> +# include <sys/resource.h> #endif #include <sys/socket.h> @@ -45,11 +45,13 @@ void LimitTest::run() { void LimitTest::testLimits(QCoreApplication &a) { QAbstractEventDispatcher *ed = QAbstractEventDispatcher::instance(); if (QLatin1String(ed->metaObject()->className()) != QLatin1String("QEventDispatcherGlib")) - qWarning("Not running with glib. While you may be able to open more descriptors, sockets above %d will not work", FD_SETSIZE); + qWarning( + "Not running with glib. While you may be able to open more descriptors, sockets above %d will not work", + FD_SETSIZE); qWarning("Running descriptor test."); int count; - QList<QFile *> ql; - for (count=0;count < 524288; ++count) { + QList< QFile * > ql; + for (count = 0; count < 524288; ++count) { QFile *qf = new QFile(a.applicationFilePath()); if (qf->open(QIODevice::ReadOnly)) ql.prepend(qf); @@ -58,13 +60,13 @@ void LimitTest::testLimits(QCoreApplication &a) { if ((count & 1023) == 0) qWarning("%d descriptors...", count); } - foreach(QFile *qf, ql) + foreach (QFile *qf, ql) delete qf; ql.clear(); qCritical("Managed to open %d descriptors", count); - qm = new QMutex(); - qw = new QWaitCondition(); + qm = new QMutex(); + qw = new QWaitCondition(); qstartw = new QWaitCondition(); int fdcount = count / 8; @@ -72,16 +74,16 @@ void LimitTest::testLimits(QCoreApplication &a) { if (fdcount > 1024) fdcount = 1024; - QList<LimitTest *> qtl; - for (count=0;count < fdcount; ++count) { + QList< LimitTest * > qtl; + for (count = 0; count < fdcount; ++count) { LimitTest *t = new LimitTest(); - t->tid = count; + t->tid = count; qtl << t; qm->lock(); t->start(); qstartw->wait(qm); qm->unlock(); - if (! t->isRunning()) + if (!t->isRunning()) break; if ((count & 511) == 0) qWarning("%d threads...", count); @@ -90,8 +92,8 @@ void LimitTest::testLimits(QCoreApplication &a) { qw->wakeAll(); qm->unlock(); - foreach(LimitTest *qt, qtl) { - if (! qt->wait(1000)) { + foreach (LimitTest *qt, qtl) { + if (!qt->wait(1000)) { qWarning("Thread %d failed to terminate...", qt->tid); qt->terminate(); } @@ -106,7 +108,7 @@ int UnixMurmur::iTermFd[2]; int UnixMurmur::iUsr1Fd[2]; UnixMurmur::UnixMurmur() { - bRoot = true; + bRoot = true; logToSyslog = false; if (geteuid() != 0 && getuid() != 0) { @@ -121,7 +123,7 @@ UnixMurmur::UnixMurmur() { if (::socketpair(AF_UNIX, SOCK_STREAM, 0, iUsr1Fd)) qFatal("Couldn't create USR1 socketpair"); - qsnHup = new QSocketNotifier(iHupFd[1], QSocketNotifier::Read, this); + qsnHup = new QSocketNotifier(iHupFd[1], QSocketNotifier::Read, this); qsnTerm = new QSocketNotifier(iTermFd[1], QSocketNotifier::Read, this); qsnUsr1 = new QSocketNotifier(iUsr1Fd[1], QSocketNotifier::Read, this); @@ -160,7 +162,7 @@ UnixMurmur::~UnixMurmur() { delete qsnTerm; delete qsnUsr1; - qsnHup = nullptr; + qsnHup = nullptr; qsnTerm = nullptr; qsnUsr1 = nullptr; @@ -173,19 +175,19 @@ UnixMurmur::~UnixMurmur() { } void UnixMurmur::hupSignalHandler(int) { - char a = 1; + char a = 1; ssize_t len = ::write(iHupFd[0], &a, sizeof(a)); Q_UNUSED(len); } void UnixMurmur::termSignalHandler(int) { - char a = 1; + char a = 1; ssize_t len = ::write(iTermFd[0], &a, sizeof(a)); Q_UNUSED(len); } void UnixMurmur::usr1SignalHandler(int) { - char a = 1; + char a = 1; ssize_t len = ::write(iUsr1Fd[0], &a, sizeof(a)); Q_UNUSED(len); } @@ -201,17 +203,17 @@ void UnixMurmur::handleSigHup() { if (logToSyslog) { qWarning("Caught SIGHUP, but logging to syslog"); - } else if (! qfLog) { + } else if (!qfLog) { qWarning("Caught SIGHUP, but logfile not in use"); - } else if (! qfLog->isOpen()) { + } else if (!qfLog->isOpen()) { qWarning("Caught SIGHUP, but logfile not in use -- interpreting as hint to quit"); QCoreApplication::instance()->quit(); } else { qWarning("Caught SIGHUP, will reopen %s", qPrintable(Meta::mp.qsLogfile)); QFile *newlog = new QFile(Meta::mp.qsLogfile); - bool result = newlog->open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text); - if (! result) { + bool result = newlog->open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text); + if (!result) { delete newlog; qCritical("Failed to reopen logfile for writing, keeping old log"); } else { @@ -252,7 +254,8 @@ void UnixMurmur::handleSigUsr1() { if (ok) { qWarning("UnixMurmur: Done reloading SSL settings."); } else { - qWarning("UnixMurmur: Failed to reload SSL settings. Server state is intact and fully operational. No configuration changes were made."); + qWarning("UnixMurmur: Failed to reload SSL settings. Server state is intact and fully operational. No " + "configuration changes were made."); } } @@ -263,7 +266,7 @@ void UnixMurmur::setuid() { if (Meta::mp.uiUid != 0) { #ifdef Q_OS_DARWIN qCritical("WARNING: You are launching murmurd as root on Mac OS X or Darwin. Murmur does not need " - "special privileges to set itself up on these systems, so this behavior is highly discouraged."); + "special privileges to set itself up on these systems, so this behavior is highly discouraged."); if (::setgid(Meta::mp.uiGid) != 0) qFatal("Failed to switch to gid %d", Meta::mp.uiGid); @@ -272,8 +275,7 @@ void UnixMurmur::setuid() { uid_t uid = getuid(), euid = geteuid(); gid_t gid = getgid(), egid = getegid(); - if (uid == Meta::mp.uiUid && euid == Meta::mp.uiUid - && gid == Meta::mp.uiGid && egid == Meta::mp.uiGid) { + if (uid == Meta::mp.uiUid && euid == Meta::mp.uiUid && gid == Meta::mp.uiGid && egid == Meta::mp.uiGid) { qCritical("Successfully switched to uid %d", Meta::mp.uiUid); } else qFatal("Couldn't switch uid/gid."); @@ -296,18 +298,19 @@ void UnixMurmur::setuid() { } #endif } else if (bRoot) { - qCritical("WARNING: You are running murmurd as root, without setting a uname in the ini file. This might be a security risk."); + qCritical("WARNING: You are running murmurd as root, without setting a uname in the ini file. This might be a " + "security risk."); } } void UnixMurmur::initialcap() { #ifdef Q_OS_LINUX - cap_value_t caps[] = {CAP_NET_ADMIN, CAP_SETUID, CAP_SETGID, CAP_CHOWN, CAP_SYS_RESOURCE, CAP_DAC_OVERRIDE }; + cap_value_t caps[] = { CAP_NET_ADMIN, CAP_SETUID, CAP_SETGID, CAP_CHOWN, CAP_SYS_RESOURCE, CAP_DAC_OVERRIDE }; - if (! bRoot) + if (!bRoot) return; - int ncap = sizeof(caps)/sizeof(cap_value_t); + int ncap = sizeof(caps) / sizeof(cap_value_t); if (geteuid() != 0) ncap--; @@ -328,10 +331,10 @@ void UnixMurmur::initialcap() { void UnixMurmur::finalcap() { #ifdef Q_OS_LINUX - cap_value_t caps[] = {CAP_SYS_RESOURCE}; + cap_value_t caps[] = { CAP_SYS_RESOURCE }; struct rlimit r; - if (! bRoot) + if (!bRoot) return; if (getrlimit(RLIMIT_RTPRIO, &r) != 0) { @@ -344,7 +347,7 @@ void UnixMurmur::finalcap() { } } - int ncap = sizeof(caps)/sizeof(cap_value_t); + int ncap = sizeof(caps) / sizeof(cap_value_t); cap_t c = cap_init(); cap_clear(c); @@ -359,7 +362,7 @@ void UnixMurmur::finalcap() { #endif } -const QString UnixMurmur::trySystemIniFiles(const QString& fname) { +const QString UnixMurmur::trySystemIniFiles(const QString &fname) { QString file = fname; if (!file.isEmpty()) return file; @@ -374,7 +377,7 @@ const QString UnixMurmur::trySystemIniFiles(const QString& fname) { inipaths << QLatin1String("/etc/mumble-server.ini"); inipaths << QLatin1String("/etc/murmur.ini"); - foreach(const QString &f, inipaths) { + foreach (const QString &f, inipaths) { QFileInfo fi(f); if (fi.exists() && fi.isReadable()) { file = fi.absoluteFilePath(); |