mirror of
https://github.com/mumble-voip/mumble.git
synced 2025-10-26 11:19:16 +00:00
Daemonized murmur
git-svn-id: https://mumble.svn.sourceforge.net/svnroot/mumble/trunk@496 05730e5d-ab1b-0410-a4ac-84af385074fa
This commit is contained in:
parent
df3109724d
commit
44e43ead41
@ -20,11 +20,15 @@ database=
|
||||
#dbHost=
|
||||
#dbPort=
|
||||
|
||||
# Murmur defaults to join the session D-Bus. If you wish to use another bus, please
|
||||
# Murmur defaults to not using D-Bus. If you wish to use dbus, please
|
||||
# specify so here.
|
||||
#
|
||||
#dbus=session
|
||||
|
||||
# Murmur default to logging to murmur.log. If you leave this blank,
|
||||
# murmur will log to the console (linux) or through message boxes (win32).
|
||||
#logfile=murmur.log
|
||||
|
||||
# Password to join server
|
||||
serverpassword=
|
||||
|
||||
|
||||
@ -66,11 +66,16 @@ ServerParams::ServerParams() {
|
||||
iDBPort = 0;
|
||||
qsDBDriver = "QSQLITE";
|
||||
qsDBus = "session";
|
||||
qsLogfile = "murmur.log";
|
||||
}
|
||||
|
||||
void ServerParams::read(QString fname) {
|
||||
if (fname.isEmpty())
|
||||
fname = "murmur.ini";
|
||||
else {
|
||||
if (! QFile(fname).exists())
|
||||
qFatal("Specified ini file %s could not be opened", qPrintable(fname));
|
||||
}
|
||||
QSettings qs(fname, QSettings::IniFormat);
|
||||
|
||||
qsPassword = qs.value("serverpassword", qsPassword).toString();
|
||||
@ -91,6 +96,8 @@ void ServerParams::read(QString fname) {
|
||||
iDBPort = qs.value("dbPort", iDBPort).toInt();
|
||||
|
||||
qsDBus = qs.value("dbus", qsDBus).toString();
|
||||
|
||||
qsLogfile = qs.value("logfile", qsLogfile).toString();
|
||||
}
|
||||
|
||||
BandwidthRecord::BandwidthRecord() {
|
||||
@ -145,7 +152,7 @@ void UDPThread::udpReady() {
|
||||
Peer p(senderAddr, senderPort);
|
||||
|
||||
Connection *source = qhPeerConnections.value(p);
|
||||
|
||||
|
||||
if (!source || (source != g_sServer->qmConnections.value(msg->sPlayerId))) {
|
||||
source = g_sServer->qmConnections.value(msg->sPlayerId);
|
||||
if (! source || ! (source->peerAddress() == senderAddr)) {
|
||||
@ -318,11 +325,9 @@ void Server::log(QString s, Connection *c) {
|
||||
iid = p->iId;
|
||||
name = p->qsName;
|
||||
}
|
||||
qWarning("[%s] <%d:%s(%d)> %s", QDateTime::currentDateTime().toString(Qt::ISODate).toAscii().constData(),
|
||||
id, name.toAscii().constData(), iid, s.toAscii().constData());
|
||||
qWarning("<%d:%s(%d)> %s", id, qPrintable(name), iid, qPrintable(s));
|
||||
} else {
|
||||
qWarning("[%s] %s", QDateTime::currentDateTime().toString(Qt::ISODate).toAscii().constData(),
|
||||
s.toAscii().constData());
|
||||
qWarning("%s", qPrintable(s));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -140,6 +140,8 @@ struct ServerParams {
|
||||
|
||||
QString qsDBus;
|
||||
|
||||
QString qsLogfile;
|
||||
|
||||
ServerParams();
|
||||
void read(QString fname = QString("murmur.ini"));
|
||||
};
|
||||
|
||||
@ -111,8 +111,6 @@ ServerDB::ServerDB() {
|
||||
if (! found) {
|
||||
QSqlError e = db.lastError();
|
||||
qFatal("ServerDB: Failed initialization: %s",qPrintable(e.text()));
|
||||
} else {
|
||||
qWarning("ServerDB: Opened successfully");
|
||||
}
|
||||
|
||||
QSqlQuery query;
|
||||
|
||||
@ -39,8 +39,39 @@
|
||||
#include "DBus.h"
|
||||
|
||||
extern Server *g_sServer;
|
||||
|
||||
MurmurDBus *dbus;
|
||||
QFile *logfile;
|
||||
|
||||
static void murmurMessageOutput(QtMsgType type, const char *msg)
|
||||
{
|
||||
|
||||
char c;
|
||||
switch (type) {
|
||||
case QtDebugMsg:
|
||||
c='D';
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
c='W';
|
||||
break;
|
||||
case QtFatalMsg:
|
||||
c='F';
|
||||
break;
|
||||
default:
|
||||
c='X';
|
||||
}
|
||||
QString m= QString::fromLatin1("<%1>%2 %3\n").arg(QChar::fromLatin1(c)).arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz")).arg(msg);
|
||||
|
||||
if (! logfile || ! logfile->isOpen()) {
|
||||
#ifdef Q_OS_UNIX
|
||||
fprintf(stderr, "%s", qPrintable(msg));
|
||||
#else
|
||||
::MessageBoxA(NULL, qPrintable(msg), "Murmur", MB_OK | MB_ICONWARNING);
|
||||
#endif
|
||||
} else {
|
||||
logfile->write(m.toUtf8());
|
||||
logfile->flush();
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
@ -55,7 +86,6 @@ int main(int argc, char **argv)
|
||||
exit(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
int res;
|
||||
|
||||
QCoreApplication a(argc, argv);
|
||||
@ -70,6 +100,10 @@ int main(int argc, char **argv)
|
||||
QString inifile;
|
||||
QString supw;
|
||||
|
||||
bool detach = true;
|
||||
|
||||
qInstallMsgHandler(murmurMessageOutput);
|
||||
|
||||
for(int i=1;i<argc;i++) {
|
||||
QString arg = QString(argv[i]).toLower();
|
||||
if ((arg == "-supw") && ( i+1 < argc )) {
|
||||
@ -78,13 +112,16 @@ int main(int argc, char **argv)
|
||||
} else if ((arg == "-ini") && ( i+1 < argc )) {
|
||||
i++;
|
||||
inifile=argv[i];
|
||||
} else if ((arg == "-fg")) {
|
||||
detach = false;
|
||||
} else if ((arg == "-h") || (arg == "--help")) {
|
||||
i++;
|
||||
qWarning("Usage: %s [-ini <inifile>] [-supw <password>]",argv[0]);
|
||||
qWarning(" -ini <inifile> Specify ini file to use.");
|
||||
qWarning(" -supw <pw> Set password for 'SuperUser' account.");
|
||||
qWarning("If no inifile is provided, murmur will search for one in ");
|
||||
qFatal("default locations.");
|
||||
qFatal("Usage: %s [-ini <inifile>] [-supw <password>]\n"
|
||||
" -ini <inifile> Specify ini file to use.\n"
|
||||
" -supw <pw> Set password for 'SuperUser' account.\n"
|
||||
" -fg Don't detach from console [Linux only].\n"
|
||||
"If no inifile is provided, murmur will search for one in \n"
|
||||
"default locations.",argv[0]);
|
||||
} else {
|
||||
qFatal("Unknown argument %s", argv[i]);
|
||||
}
|
||||
@ -99,8 +136,29 @@ int main(int argc, char **argv)
|
||||
qFatal("Superuser password set");
|
||||
}
|
||||
|
||||
if (! g_sp.qsLogfile.isEmpty()) {
|
||||
logfile = new QFile(g_sp.qsLogfile);
|
||||
if (! logfile->open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
|
||||
delete logfile;
|
||||
logfile = NULL;
|
||||
qWarning("Failed to open logfile %s. Will not detach.",qPrintable(g_sp.qsLogfile));
|
||||
detach = false;
|
||||
}
|
||||
} else {
|
||||
detach = false;
|
||||
}
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
if (detach) {
|
||||
if (fork() != 0) {
|
||||
_exit(0);
|
||||
}
|
||||
setsid();
|
||||
if (fork() != 0) {
|
||||
_exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
MurmurDBus::registerTypes();
|
||||
#endif
|
||||
dbus=new MurmurDBus(a);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
include(../mumble.pri)
|
||||
|
||||
TEMPLATE =app
|
||||
CONFIG += network console
|
||||
CONFIG += network
|
||||
CONFIG(static) {
|
||||
QMAKE_LFLAGS += -static
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user