mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Servatrice: refactor signal handling and permit config reloading
This commit is contained in:
parent
9947af7be9
commit
6cf3db7e6b
12 changed files with 163 additions and 95 deletions
|
|
@ -1,17 +1,11 @@
|
|||
#include "server_logger.h"
|
||||
#include "settingscache.h"
|
||||
#include <QSocketNotifier>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QTextStream>
|
||||
#include <QDateTime>
|
||||
#include <iostream>
|
||||
#ifdef Q_OS_UNIX
|
||||
# include <sys/types.h>
|
||||
# include <sys/socket.h>
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
ServerLogger::ServerLogger(bool _logToConsole, QObject *parent)
|
||||
: QObject(parent), logToConsole(_logToConsole), flushRunning(false)
|
||||
|
|
@ -44,13 +38,6 @@ void ServerLogger::startLog(const QString &logFileName)
|
|||
logFile = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
::socketpair(AF_UNIX, SOCK_STREAM, 0, sigHupFD);
|
||||
|
||||
snHup = new QSocketNotifier(sigHupFD[1], QSocketNotifier::Read, this);
|
||||
connect(snHup, SIGNAL(activated(int)), this, SLOT(handleSigHup()));
|
||||
#endif
|
||||
} else
|
||||
logFile = 0;
|
||||
|
||||
|
|
@ -119,35 +106,13 @@ void ServerLogger::flushBuffer()
|
|||
}
|
||||
}
|
||||
|
||||
void ServerLogger::hupSignalHandler(int /*unused*/)
|
||||
void ServerLogger::rotateLogs()
|
||||
{
|
||||
#ifdef Q_OS_UNIX
|
||||
if (!logFile)
|
||||
return;
|
||||
|
||||
char a = 1;
|
||||
ssize_t writeValue = ::write(sigHupFD[0], &a, sizeof(a));
|
||||
Q_UNUSED(writeValue);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ServerLogger::handleSigHup()
|
||||
{
|
||||
#ifdef Q_OS_UNIX
|
||||
if (!logFile)
|
||||
return;
|
||||
|
||||
snHup->setEnabled(false);
|
||||
char tmp;
|
||||
ssize_t readValue = ::read(sigHupFD[1], &tmp, sizeof(tmp));
|
||||
Q_UNUSED(readValue);
|
||||
|
||||
logFile->close();
|
||||
logFile->open(QIODevice::Append);
|
||||
|
||||
snHup->setEnabled(true);
|
||||
#endif
|
||||
}
|
||||
|
||||
QFile *ServerLogger::logFile;
|
||||
int ServerLogger::sigHupFD[2];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue