Appropriate linking some libraries
This commit is contained in:
parent
cbb0bd6864
commit
ed7cbd38e8
@ -19,7 +19,8 @@ add_library(TeaSpeak-FileServer STATIC
|
|||||||
|
|
||||||
target_link_libraries(TeaSpeak-FileServer PUBLIC TeaSpeak ${StringVariable_LIBRARIES_STATIC} stdc++fs
|
target_link_libraries(TeaSpeak-FileServer PUBLIC TeaSpeak ${StringVariable_LIBRARIES_STATIC} stdc++fs
|
||||||
libevent::core libevent::pthreads
|
libevent::core libevent::pthreads
|
||||||
DataPipes::core::static
|
# We're not linking this here, since we may later use DataPipes::shared linking
|
||||||
|
# DataPipes::core::static
|
||||||
openssl::ssl::shared
|
openssl::ssl::shared
|
||||||
openssl::crypto::shared
|
openssl::crypto::shared
|
||||||
)
|
)
|
||||||
@ -30,7 +31,8 @@ target_compile_options(TeaSpeak-FileServer PUBLIC "-Wswitch-enum")
|
|||||||
add_executable(TeaSpeak-FileServerTest test/main.cpp)
|
add_executable(TeaSpeak-FileServerTest test/main.cpp)
|
||||||
target_link_libraries(TeaSpeak-FileServerTest PUBLIC TeaSpeak-FileServer
|
target_link_libraries(TeaSpeak-FileServerTest PUBLIC TeaSpeak-FileServer
|
||||||
TeaMusic #Static (Must be in here, so we link against TeaMusic which uses C++11. That forbids GCC to use the newer glibc version)
|
TeaMusic #Static (Must be in here, so we link against TeaMusic which uses C++11. That forbids GCC to use the newer glibc version)
|
||||||
CXXTerminal::static #Static
|
CXXTerminal::static
|
||||||
|
DataPipes::core::static
|
||||||
stdc++fs
|
stdc++fs
|
||||||
)
|
)
|
||||||
target_compile_options(TeaSpeak-FileServerTest PUBLIC -static-libgcc -static-libstdc++)
|
target_compile_options(TeaSpeak-FileServerTest PUBLIC -static-libgcc -static-libstdc++)
|
||||||
|
@ -95,7 +95,6 @@ set(SERVER_SOURCE_FILES
|
|||||||
src/manager/LetterManager.cpp
|
src/manager/LetterManager.cpp
|
||||||
src/manager/PermissionNameManager.cpp
|
src/manager/PermissionNameManager.cpp
|
||||||
|
|
||||||
src/pinteraction/ApplicationInteraction.cpp
|
|
||||||
src/ServerManagerSnapshot.cpp
|
src/ServerManagerSnapshot.cpp
|
||||||
src/ServerManagerSnapshotDeploy.cpp
|
src/ServerManagerSnapshotDeploy.cpp
|
||||||
src/client/music/Song.cpp
|
src/client/music/Song.cpp
|
||||||
|
@ -1,110 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by wolverindev on 07.12.17.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "ApplicationInteraction.h"
|
|
||||||
#include <log/LogUtils.h>
|
|
||||||
#include <sys/shm.h>
|
|
||||||
#include <cstring>
|
|
||||||
#include <iostream>
|
|
||||||
#include <zconf.h>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
static key_t SHM_KEY = 0x1337015; //1337 TS
|
|
||||||
static size_t SHARED_SIZE = sizeof(interaction::DefaultMemoryInfo);
|
|
||||||
|
|
||||||
static int SHARED_MEMORY_ID = -1;
|
|
||||||
static void* SHARED_MEMORY_PTR = nullptr;
|
|
||||||
static size_t INSTANCE_ID = 0;
|
|
||||||
|
|
||||||
namespace interaction {
|
|
||||||
bool waitForAttach(std::string& error){
|
|
||||||
SHARED_MEMORY_ID = shmget(SHM_KEY, SHARED_SIZE, IPC_CREAT | 0776);
|
|
||||||
if(SHARED_MEMORY_ID < 0) {
|
|
||||||
error = string() + "Could not attach: " + strerror(errno);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
shmid_ds shmInfo{};
|
|
||||||
memset(&shmInfo, 0, sizeof(shmInfo));
|
|
||||||
if(shmctl(SHARED_MEMORY_ID, IPC_STAT, &shmInfo) < 0){
|
|
||||||
error = string() + "Could not collect info: " + strerror(errno);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
SHARED_MEMORY_PTR = shmat(SHARED_MEMORY_ID, nullptr, 0);
|
|
||||||
if(SHARED_MEMORY_PTR == (char*) - 1){
|
|
||||||
SHARED_MEMORY_PTR = nullptr;
|
|
||||||
error = "failed to attach";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
DefaultMemoryInfo* info = nullptr;
|
|
||||||
if(shmInfo.shm_nattch == 0){ //Im the first program!
|
|
||||||
debugMessage(LOG_GENERAL, "Created new memory struct");
|
|
||||||
*(DefaultMemoryInfo*) SHARED_MEMORY_PTR = DefaultMemoryInfo{};
|
|
||||||
info = (DefaultMemoryInfo*) SHARED_MEMORY_PTR;
|
|
||||||
|
|
||||||
/* initialize the mutex */
|
|
||||||
{
|
|
||||||
pthread_mutexattr_t attr{};
|
|
||||||
pthread_mutexattr_init(&attr);
|
|
||||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
|
|
||||||
pthread_mutexattr_setpshared(&attr, true);
|
|
||||||
pthread_mutex_init(&info->memoryLock, &attr);
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_lock(&info->memoryLock);
|
|
||||||
memset(info->infoUsed, 0, sizeof(info->infoUsed) / sizeof(info->infoUsed[0]));
|
|
||||||
} else {
|
|
||||||
info = memoryInfo();
|
|
||||||
pthread_mutex_lock(&info->memoryLock);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(info->instanceCount + 1 >= info->maxInstances){
|
|
||||||
pthread_mutex_unlock(&info->memoryLock);
|
|
||||||
error = "to many instances";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int index = 0; index < info->maxInstances; index++)
|
|
||||||
if(!info->infoUsed[index]){
|
|
||||||
info->instanceCount++;
|
|
||||||
INSTANCE_ID = static_cast<size_t>(index);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
info->info[INSTANCE_ID] = InstanceInfo{};
|
|
||||||
info->infoUsed[INSTANCE_ID] = true;
|
|
||||||
|
|
||||||
auto instanceInfo = ownInfo();
|
|
||||||
instanceInfo->pid = ::getpid();
|
|
||||||
pthread_mutex_unlock(&info->memoryLock);
|
|
||||||
debugMessage(LOG_GENERAL, "Got application instance id {}", INSTANCE_ID);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeMemoryHook(){
|
|
||||||
if(SHARED_MEMORY_PTR){
|
|
||||||
if(shmdt(SHARED_MEMORY_PTR) < 0)
|
|
||||||
cerr << strerror(errno) << endl;
|
|
||||||
SHARED_MEMORY_PTR = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
shmid_ds info{};
|
|
||||||
memset(&info, 0, sizeof(info));
|
|
||||||
if(shmctl(SHARED_MEMORY_ID, IPC_STAT, &info) < 0){
|
|
||||||
logMessage(LOG_INSTANCE, "Could not collect info: {}", errno);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(info.shm_nattch == 0){
|
|
||||||
shmctl(SHARED_MEMORY_ID, IPC_RMID, nullptr);
|
|
||||||
logMessage(LOG_INSTANCE, "Deleting shared memory");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DefaultMemoryInfo* memoryInfo(){ return static_cast<DefaultMemoryInfo *>(SHARED_MEMORY_PTR); }
|
|
||||||
InstanceInfo* ownInfo(){ return &memoryInfo()->info[INSTANCE_ID]; }
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <sched.h>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace interaction {
|
|
||||||
struct InstanceInfo {
|
|
||||||
pid_t pid = 0;
|
|
||||||
|
|
||||||
size_t virtualServers = 0;
|
|
||||||
size_t usedSlots = 0;
|
|
||||||
} __attribute__((packed));
|
|
||||||
|
|
||||||
template <size_t N>
|
|
||||||
struct MemoryInfo {
|
|
||||||
pthread_mutex_t memoryLock;
|
|
||||||
|
|
||||||
size_t instanceCount = 0;
|
|
||||||
size_t maxInstances = N;
|
|
||||||
bool infoUsed[N];
|
|
||||||
InstanceInfo info[N];
|
|
||||||
} __attribute__((packed));
|
|
||||||
|
|
||||||
typedef MemoryInfo<15> DefaultMemoryInfo;
|
|
||||||
|
|
||||||
|
|
||||||
struct RunningInstanceInfo {
|
|
||||||
std::string name;
|
|
||||||
pid_t pid;
|
|
||||||
|
|
||||||
int usedSlots;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<RunningInstanceInfo> listInstances();
|
|
||||||
|
|
||||||
bool waitForAttach(std::string& error);
|
|
||||||
|
|
||||||
void removeMemoryHook();
|
|
||||||
|
|
||||||
DefaultMemoryInfo* memoryInfo();
|
|
||||||
InstanceInfo* ownInfo();
|
|
||||||
}
|
|
2
shared
2
shared
@ -1 +1 @@
|
|||||||
Subproject commit 9b41ca5dcacd30f69228d71fcb9ed05be8b542d8
|
Subproject commit 32dc9423c21e087aeb5f8990e2e1c56c809cbffe
|
Loading…
x
Reference in New Issue
Block a user