mirror of
https://github.com/overte-org/overte.git
synced 2025-06-21 20:41:52 +02:00
handle unmapping of assignment file on SIGTERM, add created to static map
This commit is contained in:
parent
e48a269fe3
commit
6fe47b47a3
1 changed files with 40 additions and 14 deletions
|
@ -22,6 +22,7 @@
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <signal.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -48,6 +49,9 @@ const int NODE_COUNT_STAT_INTERVAL_MSECS = 5000;
|
||||||
QMutex assignmentQueueMutex;
|
QMutex assignmentQueueMutex;
|
||||||
std::deque<Assignment*> assignmentQueue;
|
std::deque<Assignment*> assignmentQueue;
|
||||||
|
|
||||||
|
uchar* staticAssignmentFileData;
|
||||||
|
QFile* staticAssignmentFile = NULL;
|
||||||
|
|
||||||
unsigned char* addNodeToBroadcastPacket(unsigned char* currentPosition, Node* nodeToAdd) {
|
unsigned char* addNodeToBroadcastPacket(unsigned char* currentPosition, Node* nodeToAdd) {
|
||||||
*currentPosition++ = nodeToAdd->getType();
|
*currentPosition++ = nodeToAdd->getType();
|
||||||
|
|
||||||
|
@ -109,12 +113,31 @@ static void mongooseUploadHandler(struct mg_connection *conn, const char *path)
|
||||||
::assignmentQueueMutex.unlock();
|
::assignmentQueueMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void signalHandler(int signal) {
|
||||||
|
qDebug() << "Caught SIGTERM. Unmapping config file and exiting.\n";
|
||||||
|
|
||||||
|
::staticAssignmentFile->unmap(::staticAssignmentFileData);
|
||||||
|
::staticAssignmentFile->close();
|
||||||
|
|
||||||
|
delete ::staticAssignmentFile;
|
||||||
|
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, const char* argv[]) {
|
int main(int argc, const char* argv[]) {
|
||||||
|
|
||||||
QCoreApplication domainServer(argc, (char**) argv);
|
QCoreApplication domainServer(argc, (char**) argv);
|
||||||
|
|
||||||
qInstallMessageHandler(Logging::verboseMessageHandler);
|
qInstallMessageHandler(Logging::verboseMessageHandler);
|
||||||
|
|
||||||
|
struct sigaction sigIntHandler;
|
||||||
|
|
||||||
|
sigIntHandler.sa_handler = signalHandler;
|
||||||
|
sigemptyset(&sigIntHandler.sa_mask);
|
||||||
|
sigIntHandler.sa_flags = 0;
|
||||||
|
|
||||||
|
sigaction(SIGINT, &sigIntHandler, NULL);
|
||||||
|
|
||||||
const char CUSTOM_PORT_OPTION[] = "-p";
|
const char CUSTOM_PORT_OPTION[] = "-p";
|
||||||
const char* customPortString = getCmdOption(argc, argv, CUSTOM_PORT_OPTION);
|
const char* customPortString = getCmdOption(argc, argv, CUSTOM_PORT_OPTION);
|
||||||
unsigned short domainServerPort = customPortString ? atoi(customPortString) : DOMAIN_LISTEN_PORT;
|
unsigned short domainServerPort = customPortString ? atoi(customPortString) : DOMAIN_LISTEN_PORT;
|
||||||
|
@ -140,13 +163,12 @@ int main(int argc, const char* argv[]) {
|
||||||
|
|
||||||
timeval lastStatSendTime = {};
|
timeval lastStatSendTime = {};
|
||||||
|
|
||||||
const QString STATIC_ASSIGNMENT_FILENAME = QString("%1/config.ds").arg(QCoreApplication::applicationDirPath());
|
|
||||||
|
|
||||||
const int MAX_STATIC_ASSIGNMENT_FILE_ASSIGNMENTS = 1000;
|
const int MAX_STATIC_ASSIGNMENT_FILE_ASSIGNMENTS = 1000;
|
||||||
|
|
||||||
QFile staticAssignmentFile(STATIC_ASSIGNMENT_FILENAME);
|
const QString STATIC_ASSIGNMENT_FILENAME = QString("%1/config.ds").arg(QCoreApplication::applicationDirPath());
|
||||||
|
staticAssignmentFile = new QFile(STATIC_ASSIGNMENT_FILENAME);
|
||||||
|
|
||||||
if (!staticAssignmentFile.exists()) {
|
if (!::staticAssignmentFile->exists()) {
|
||||||
|
|
||||||
const uint NUM_FRESH_STATIC_ASSIGNMENTS = 3;
|
const uint NUM_FRESH_STATIC_ASSIGNMENTS = 3;
|
||||||
|
|
||||||
|
@ -175,21 +197,21 @@ int main(int argc, const char* argv[]) {
|
||||||
|
|
||||||
freshStaticAssignmentList[2] = voxelServerAssignment;
|
freshStaticAssignmentList[2] = voxelServerAssignment;
|
||||||
|
|
||||||
staticAssignmentFile.open(QIODevice::WriteOnly);
|
::staticAssignmentFile->open(QIODevice::WriteOnly);
|
||||||
|
|
||||||
staticAssignmentFile.write((char*) &NUM_FRESH_STATIC_ASSIGNMENTS,
|
::staticAssignmentFile->write((char*) &NUM_FRESH_STATIC_ASSIGNMENTS,
|
||||||
sizeof(uint16_t));
|
sizeof(uint16_t));
|
||||||
staticAssignmentFile.write((char*) &freshStaticAssignmentList, sizeof(freshStaticAssignmentList));
|
::staticAssignmentFile->write((char*) &freshStaticAssignmentList, sizeof(freshStaticAssignmentList));
|
||||||
staticAssignmentFile.resize(MAX_STATIC_ASSIGNMENT_FILE_ASSIGNMENTS * sizeof(Assignment));
|
::staticAssignmentFile->resize(MAX_STATIC_ASSIGNMENT_FILE_ASSIGNMENTS * sizeof(Assignment));
|
||||||
staticAssignmentFile.close();
|
::staticAssignmentFile->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
staticAssignmentFile.open(QIODevice::ReadWrite);
|
::staticAssignmentFile->open(QIODevice::ReadWrite);
|
||||||
|
|
||||||
uchar* staticAssignmentFileData = staticAssignmentFile.map(0, staticAssignmentFile.size());
|
::staticAssignmentFileData = ::staticAssignmentFile->map(0, ::staticAssignmentFile->size());
|
||||||
|
|
||||||
uint16_t* numAssignmentsInStaticFile = (uint16_t*) staticAssignmentFileData;
|
uint16_t* numAssignmentsInStaticFile = (uint16_t*) ::staticAssignmentFileData;
|
||||||
Assignment* staticFileAssignments = (Assignment*) (staticAssignmentFileData + sizeof(*numAssignmentsInStaticFile));
|
Assignment* staticFileAssignments = (Assignment*) (::staticAssignmentFileData + sizeof(*numAssignmentsInStaticFile));
|
||||||
|
|
||||||
// construct a local socket to send with our created assignments to the global AS
|
// construct a local socket to send with our created assignments to the global AS
|
||||||
sockaddr_in localSocket = {};
|
sockaddr_in localSocket = {};
|
||||||
|
@ -407,6 +429,9 @@ int main(int argc, const char* argv[]) {
|
||||||
::assignmentQueueMutex.lock();
|
::assignmentQueueMutex.lock();
|
||||||
::assignmentQueue.push_back(createAssignment);
|
::assignmentQueue.push_back(createAssignment);
|
||||||
::assignmentQueueMutex.unlock();
|
::assignmentQueueMutex.unlock();
|
||||||
|
|
||||||
|
// also add this assignment to the static map of assignments so it exists next time the DS starts up
|
||||||
|
staticFileAssignments[(*numAssignmentsInStaticFile)++] = *createAssignment;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,6 +447,7 @@ int main(int argc, const char* argv[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
::staticAssignmentFile->unmap(::staticAssignmentFileData);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue