Store server pid in file, location can be changed by. First try, needs some cleanup work. Might require additional link options on Linux (new dependency: boost::program_options).
This commit is contained in:
+66
-80
@@ -39,111 +39,97 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
ConfigFile::ConfigFile(int argc, char **argv) : noWriteAccess(0)
|
ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly)
|
||||||
{
|
{
|
||||||
|
|
||||||
myArgv0 = argv[0];
|
myArgv0 = argv0;
|
||||||
int i;
|
|
||||||
|
|
||||||
myQtToolsInterface = CreateQtToolsWrapper();
|
myQtToolsInterface = CreateQtToolsWrapper();
|
||||||
|
|
||||||
for (i=1; i<argc; i++) {
|
|
||||||
if(strcmp(argv[i], "--nowriteaccess") == 0) { noWriteAccess = 1; }
|
|
||||||
}
|
|
||||||
// !!!! Revisionsnummer der Configdefaults !!!!!
|
// !!!! Revisionsnummer der Configdefaults !!!!!
|
||||||
configRev = 52;
|
configRev = 52;
|
||||||
|
|
||||||
//standard defaults
|
//standard defaults
|
||||||
logOnOffDefault = "1";
|
logOnOffDefault = "1";
|
||||||
claNoWriteAccess = "0";
|
|
||||||
|
|
||||||
if(!noWriteAccess) {
|
// Pfad und Dateinamen setzen
|
||||||
// Pfad und Dateinamen setzen
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
const char *appDataPath = getenv("AppData");
|
const char *appDataPath = getenv("AppData");
|
||||||
if (appDataPath && appDataPath[0] != 0) {
|
if (appDataPath && appDataPath[0] != 0) {
|
||||||
configFileName = appDataPath;
|
configFileName = appDataPath;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const int MaxPathSize = 1024;
|
||||||
|
char curDir[MaxPathSize + 1];
|
||||||
|
curDir[0] = 0;
|
||||||
|
_getcwd(curDir, MaxPathSize);
|
||||||
|
curDir[MaxPathSize] = 0;
|
||||||
|
configFileName = curDir;
|
||||||
|
// Testen ob das Verzeichnis beschreibbar ist
|
||||||
|
ofstream tmpFile;
|
||||||
|
const char *tmpFileName = "pokerth_test.tmp";
|
||||||
|
tmpFile.open((configFileName + "\\" + tmpFileName).c_str());
|
||||||
|
if (tmpFile) {
|
||||||
|
// Erfolgreich, Verzeichnis beschreibbar.
|
||||||
|
// Datei wieder loeschen.
|
||||||
|
tmpFile.close();
|
||||||
|
remove((configFileName + "\\" + tmpFileName).c_str());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const int MaxPathSize = 1024;
|
// Fehlgeschlagen, Verzeichnis nicht beschreibbar
|
||||||
char curDir[MaxPathSize + 1];
|
|
||||||
curDir[0] = 0;
|
curDir[0] = 0;
|
||||||
_getcwd(curDir, MaxPathSize);
|
GetTempPathA(MaxPathSize, curDir);
|
||||||
curDir[MaxPathSize] = 0;
|
curDir[MaxPathSize] = 0;
|
||||||
configFileName = curDir;
|
configFileName = curDir;
|
||||||
// Testen ob das Verzeichnis beschreibbar ist
|
|
||||||
ofstream tmpFile;
|
|
||||||
const char *tmpFileName = "pokerth_test.tmp";
|
|
||||||
tmpFile.open((configFileName + "\\" + tmpFileName).c_str());
|
|
||||||
if (tmpFile) {
|
|
||||||
// Erfolgreich, Verzeichnis beschreibbar.
|
|
||||||
// Datei wieder loeschen.
|
|
||||||
tmpFile.close();
|
|
||||||
remove((configFileName + "\\" + tmpFileName).c_str());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Fehlgeschlagen, Verzeichnis nicht beschreibbar
|
|
||||||
curDir[0] = 0;
|
|
||||||
GetTempPathA(MaxPathSize, curDir);
|
|
||||||
curDir[MaxPathSize] = 0;
|
|
||||||
configFileName = curDir;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//define app-dir
|
}
|
||||||
configFileName += "\\pokerth\\";
|
//define app-dir
|
||||||
////define log-dir
|
configFileName += "\\pokerth\\";
|
||||||
logDir = configFileName;
|
////define log-dir
|
||||||
logDir += "log-files\\";
|
logDir = configFileName;
|
||||||
////define data-dir
|
logDir += "log-files\\";
|
||||||
dataDir = configFileName;
|
////define data-dir
|
||||||
dataDir += "data\\";
|
dataDir = configFileName;
|
||||||
////define cache-dir
|
dataDir += "data\\";
|
||||||
cacheDir = configFileName;
|
////define cache-dir
|
||||||
cacheDir += "cache\\";
|
cacheDir = configFileName;
|
||||||
//create directories on first start of app
|
cacheDir += "cache\\";
|
||||||
mkdir(configFileName.c_str());
|
|
||||||
mkdir(logDir.c_str());
|
//create directories on first start of app
|
||||||
mkdir(dataDir.c_str());
|
mkdir(configFileName.c_str());
|
||||||
mkdir(cacheDir.c_str());
|
mkdir(logDir.c_str());
|
||||||
|
mkdir(dataDir.c_str());
|
||||||
|
mkdir(cacheDir.c_str());
|
||||||
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
//define app-dir
|
//define app-dir
|
||||||
const char *homePath = getenv("HOME");
|
const char *homePath = getenv("HOME");
|
||||||
if(homePath) {
|
if(homePath) {
|
||||||
configFileName = homePath;
|
configFileName = homePath;
|
||||||
configFileName += "/.pokerth/";
|
configFileName += "/.pokerth/";
|
||||||
////define log-dir
|
////define log-dir
|
||||||
logDir = configFileName;
|
logDir = configFileName;
|
||||||
logDir += "log-files/";
|
logDir += "log-files/";
|
||||||
////define data-dir
|
////define data-dir
|
||||||
dataDir = configFileName;
|
dataDir = configFileName;
|
||||||
dataDir += "data/";
|
dataDir += "data/";
|
||||||
////define cache-dir
|
////define cache-dir
|
||||||
cacheDir = configFileName;
|
cacheDir = configFileName;
|
||||||
cacheDir += "cache/";
|
cacheDir += "cache/";
|
||||||
//create directories on first start of app
|
//create directories on first start of app
|
||||||
mkdir(configFileName.c_str(), MODUS) ;
|
mkdir(configFileName.c_str(), MODUS) ;
|
||||||
mkdir(logDir.c_str(), MODUS);
|
mkdir(logDir.c_str(), MODUS);
|
||||||
mkdir(dataDir.c_str(), MODUS);
|
mkdir(dataDir.c_str(), MODUS);
|
||||||
mkdir(cacheDir.c_str(), MODUS);
|
mkdir(cacheDir.c_str(), MODUS);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
else {
|
|
||||||
//no writeaccess
|
|
||||||
configFileName = "";
|
|
||||||
logDir = "";
|
|
||||||
dataDir = "";
|
|
||||||
logOnOffDefault = "0";
|
|
||||||
claNoWriteAccess = "1";
|
|
||||||
}
|
|
||||||
|
|
||||||
ostringstream tempIntToString;
|
ostringstream tempIntToString;
|
||||||
tempIntToString << configRev;
|
tempIntToString << configRev;
|
||||||
configList.push_back(ConfigInfo("ConfigRevision", CONFIG_TYPE_INT, tempIntToString.str()));
|
configList.push_back(ConfigInfo("ConfigRevision", CONFIG_TYPE_INT, tempIntToString.str()));
|
||||||
configList.push_back(ConfigInfo("AppDataDir", CONFIG_TYPE_STRING, myQtToolsInterface->getDataPathStdString(argv[0])));
|
configList.push_back(ConfigInfo("AppDataDir", CONFIG_TYPE_STRING, myQtToolsInterface->getDataPathStdString(myArgv0)));
|
||||||
configList.push_back(ConfigInfo("Language", CONFIG_TYPE_INT, myQtToolsInterface->getDefaultLanguage()));
|
configList.push_back(ConfigInfo("Language", CONFIG_TYPE_INT, myQtToolsInterface->getDefaultLanguage()));
|
||||||
configList.push_back(ConfigInfo("InternetServerAddressIRCChannelUpdateDone", CONFIG_TYPE_INT, "1")); //HACK
|
configList.push_back(ConfigInfo("InternetServerAddressIRCChannelUpdateDone", CONFIG_TYPE_INT, "1")); //HACK
|
||||||
configList.push_back(ConfigInfo("ShowLeftToolBox", CONFIG_TYPE_INT, "1"));
|
configList.push_back(ConfigInfo("ShowLeftToolBox", CONFIG_TYPE_INT, "1"));
|
||||||
@@ -241,7 +227,7 @@ ConfigFile::ConfigFile(int argc, char **argv) : noWriteAccess(0)
|
|||||||
configList.push_back(ConfigInfo("LogInterval", CONFIG_TYPE_INT, "0"));
|
configList.push_back(ConfigInfo("LogInterval", CONFIG_TYPE_INT, "0"));
|
||||||
configList.push_back(ConfigInfo("UserDataDir", CONFIG_TYPE_STRING, dataDir));
|
configList.push_back(ConfigInfo("UserDataDir", CONFIG_TYPE_STRING, dataDir));
|
||||||
configList.push_back(ConfigInfo("CacheDir", CONFIG_TYPE_STRING, cacheDir));
|
configList.push_back(ConfigInfo("CacheDir", CONFIG_TYPE_STRING, cacheDir));
|
||||||
configList.push_back(ConfigInfo("CLA_NoWriteAccess", CONFIG_TYPE_INT, claNoWriteAccess));
|
configList.push_back(ConfigInfo("CLA_NoWriteAccess", CONFIG_TYPE_INT, "0"));
|
||||||
configList.push_back(ConfigInfo("DisableBackToLobbyWarning", CONFIG_TYPE_INT, "0"));
|
configList.push_back(ConfigInfo("DisableBackToLobbyWarning", CONFIG_TYPE_INT, "0"));
|
||||||
|
|
||||||
//fill tempList firstTime
|
//fill tempList firstTime
|
||||||
@@ -272,7 +258,7 @@ ConfigFile::ConfigFile(int argc, char **argv) : noWriteAccess(0)
|
|||||||
if (tmpStr) tempAppDataPath = tmpStr;
|
if (tmpStr) tempAppDataPath = tmpStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tempRevision < configRev || tempAppDataPath != myQtToolsInterface->getDataPathStdString(argv[0]) ) { /*löschen()*/
|
if (tempRevision < configRev || tempAppDataPath != myQtToolsInterface->getDataPathStdString(myArgv0) ) { /*löschen()*/
|
||||||
myConfigState = OLD;
|
myConfigState = OLD;
|
||||||
updateConfig(myConfigState) ;
|
updateConfig(myConfigState) ;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class QtToolsInterface;
|
|||||||
|
|
||||||
class ConfigFile{
|
class ConfigFile{
|
||||||
public:
|
public:
|
||||||
ConfigFile(int, char **);
|
ConfigFile(char *argv0, bool readonly);
|
||||||
|
|
||||||
~ConfigFile();
|
~ConfigFile();
|
||||||
|
|
||||||
@@ -75,7 +75,6 @@ private:
|
|||||||
bool noWriteAccess;
|
bool noWriteAccess;
|
||||||
|
|
||||||
std::string logOnOffDefault;
|
std::string logOnOffDefault;
|
||||||
std::string claNoWriteAccess;
|
|
||||||
|
|
||||||
ConfigState myConfigState;
|
ConfigState myConfigState;
|
||||||
QtToolsInterface *myQtToolsInterface;
|
QtToolsInterface *myQtToolsInterface;
|
||||||
|
|||||||
+1
-1
@@ -80,7 +80,7 @@ int main( int argc, char **argv )
|
|||||||
QApplication a( argc, argv );
|
QApplication a( argc, argv );
|
||||||
|
|
||||||
//create defaultconfig
|
//create defaultconfig
|
||||||
ConfigFile *myConfig = new ConfigFile(argc, argv);
|
ConfigFile *myConfig = new ConfigFile(argv[0], false);
|
||||||
|
|
||||||
// set PlastiqueStyle even for mac-version to prevent artefacts on styled widgets
|
// set PlastiqueStyle even for mac-version to prevent artefacts on styled widgets
|
||||||
a.setStyle(new QPlastiqueStyle);
|
a.setStyle(new QPlastiqueStyle);
|
||||||
|
|||||||
+57
-2
@@ -24,8 +24,11 @@
|
|||||||
#include <qttoolsinterface.h>
|
#include <qttoolsinterface.h>
|
||||||
#include <gui/generic/serverguiwrapper.h>
|
#include <gui/generic/serverguiwrapper.h>
|
||||||
#include <net/socket_startup.h>
|
#include <net/socket_startup.h>
|
||||||
|
#include <net/netpacket.h>
|
||||||
#include <core/loghelper.h>
|
#include <core/loghelper.h>
|
||||||
#include <core/thread.h>
|
#include <core/thread.h>
|
||||||
|
#include <boost/program_options.hpp>
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
@@ -49,6 +52,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
namespace po = boost::program_options;
|
||||||
|
using namespace boost::filesystem;
|
||||||
|
|
||||||
volatile int g_pokerthTerminate = 0;
|
volatile int g_pokerthTerminate = 0;
|
||||||
|
|
||||||
@@ -59,7 +64,9 @@ TerminateHandler(int /*signal*/)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Hack
|
// TODO: Hack
|
||||||
#ifndef _WIN32
|
#ifdef _WIN32
|
||||||
|
#include <process.h>
|
||||||
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#ifndef daemon
|
#ifndef daemon
|
||||||
int daemon(int, int);
|
int daemon(int, int);
|
||||||
@@ -73,9 +80,42 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
// _CrtSetBreakAlloc(4772);
|
// _CrtSetBreakAlloc(4772);
|
||||||
|
|
||||||
|
bool readonlyConfig = false;
|
||||||
|
string pidFile;
|
||||||
|
{
|
||||||
|
// Check command line options.
|
||||||
|
po::options_description desc("Allowed options");
|
||||||
|
desc.add_options()
|
||||||
|
("help,h", "produce help message")
|
||||||
|
("version,v", "print version string")
|
||||||
|
("pid-file,p", po::value<string>(), "create pid-file in different location")
|
||||||
|
("readonly-config", "treat config file as read-only")
|
||||||
|
;
|
||||||
|
|
||||||
|
po::variables_map vm;
|
||||||
|
po::store(po::parse_command_line(argc, argv, desc), vm);
|
||||||
|
po::notify(vm);
|
||||||
|
|
||||||
|
if (vm.count("help"))
|
||||||
|
{
|
||||||
|
cout << desc << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (vm.count("version"))
|
||||||
|
{
|
||||||
|
cout << "PokerTH server version " << POKERTH_BETA_RELEASE_STRING << endl
|
||||||
|
<< "Network protocol version " << NET_VERSION_MAJOR << "." << NET_VERSION_MINOR << endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (vm.count("pid-file"))
|
||||||
|
pidFile = vm["pid-file"].as<string>();
|
||||||
|
if (vm.count("readonly-config"))
|
||||||
|
readonlyConfig = true;
|
||||||
|
}
|
||||||
|
|
||||||
auto_ptr<QtToolsInterface> myQtToolsInterface(CreateQtToolsWrapper());
|
auto_ptr<QtToolsInterface> myQtToolsInterface(CreateQtToolsWrapper());
|
||||||
//create defaultconfig
|
//create defaultconfig
|
||||||
ConfigFile *myConfig = new ConfigFile(argc, argv);
|
ConfigFile *myConfig = new ConfigFile(argv[0], readonlyConfig);
|
||||||
loghelper_init(myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("LogDir")));
|
loghelper_init(myQtToolsInterface->stringFromUtf8(myConfig->readConfigString("LogDir")));
|
||||||
|
|
||||||
// TODO: Hack
|
// TODO: Hack
|
||||||
@@ -91,6 +131,21 @@ main(int argc, char *argv[])
|
|||||||
LOG_MSG("Starting PokerTH dedicated server. Availability: IPv6 "
|
LOG_MSG("Starting PokerTH dedicated server. Availability: IPv6 "
|
||||||
<< socket_has_ipv6() << ", SCTP " << socket_has_sctp() << ", Dual Stack " << socket_has_dual_stack() << ".");
|
<< socket_has_ipv6() << ", SCTP " << socket_has_sctp() << ", Dual Stack " << socket_has_dual_stack() << ".");
|
||||||
|
|
||||||
|
// Store pid in file.
|
||||||
|
if (pidFile.empty())
|
||||||
|
{
|
||||||
|
path tmpPidPath(myConfig->readConfigString("LogDir"));
|
||||||
|
tmpPidPath /= "pokerth.pid";
|
||||||
|
pidFile = tmpPidPath.directory_string();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
ofstream pidStream(pidFile.c_str(), ios_base::out | ios_base::trunc);
|
||||||
|
if (!pidStream.fail())
|
||||||
|
pidStream << getpid();
|
||||||
|
else
|
||||||
|
LOG_ERROR("Could not create process id file \"" << pidFile << "\"!");
|
||||||
|
}
|
||||||
|
|
||||||
// Create pseudo Gui Wrapper for the server.
|
// Create pseudo Gui Wrapper for the server.
|
||||||
boost::shared_ptr<GuiInterface> myServerGuiInterface(new ServerGuiWrapper(myConfig, NULL, NULL, NULL));
|
boost::shared_ptr<GuiInterface> myServerGuiInterface(new ServerGuiWrapper(myConfig, NULL, NULL, NULL));
|
||||||
boost::shared_ptr<Session> session(new Session(myServerGuiInterface.get(), myConfig));
|
boost::shared_ptr<Session> session(new Session(myServerGuiInterface.get(), myConfig));
|
||||||
|
|||||||
Reference in New Issue
Block a user