diff --git a/file/CMakeLists.txt b/file/CMakeLists.txt index 870bb8e..0ce7dff 100644 --- a/file/CMakeLists.txt +++ b/file/CMakeLists.txt @@ -19,7 +19,8 @@ add_library(TeaSpeak-FileServer STATIC target_link_libraries(TeaSpeak-FileServer PUBLIC TeaSpeak ${StringVariable_LIBRARIES_STATIC} stdc++fs 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::crypto::shared ) @@ -30,7 +31,8 @@ target_compile_options(TeaSpeak-FileServer PUBLIC "-Wswitch-enum") add_executable(TeaSpeak-FileServerTest test/main.cpp) 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) - CXXTerminal::static #Static + CXXTerminal::static + DataPipes::core::static stdc++fs ) target_compile_options(TeaSpeak-FileServerTest PUBLIC -static-libgcc -static-libstdc++) diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index ed287dd..f506abb 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -95,7 +95,6 @@ set(SERVER_SOURCE_FILES src/manager/LetterManager.cpp src/manager/PermissionNameManager.cpp - src/pinteraction/ApplicationInteraction.cpp src/ServerManagerSnapshot.cpp src/ServerManagerSnapshotDeploy.cpp src/client/music/Song.cpp diff --git a/server/src/pinteraction/ApplicationInteraction.cpp b/server/src/pinteraction/ApplicationInteraction.cpp deleted file mode 100644 index 269a199..0000000 --- a/server/src/pinteraction/ApplicationInteraction.cpp +++ /dev/null @@ -1,110 +0,0 @@ -// -// Created by wolverindev on 07.12.17. -// - -#include "ApplicationInteraction.h" -#include -#include -#include -#include -#include - -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(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(SHARED_MEMORY_PTR); } - InstanceInfo* ownInfo(){ return &memoryInfo()->info[INSTANCE_ID]; } -} \ No newline at end of file diff --git a/server/src/pinteraction/ApplicationInteraction.h b/server/src/pinteraction/ApplicationInteraction.h deleted file mode 100644 index d42a9fe..0000000 --- a/server/src/pinteraction/ApplicationInteraction.h +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace interaction { - struct InstanceInfo { - pid_t pid = 0; - - size_t virtualServers = 0; - size_t usedSlots = 0; - } __attribute__((packed)); - - template - 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 listInstances(); - - bool waitForAttach(std::string& error); - - void removeMemoryHook(); - - DefaultMemoryInfo* memoryInfo(); - InstanceInfo* ownInfo(); -} \ No newline at end of file diff --git a/shared b/shared index 9b41ca5..32dc942 160000 --- a/shared +++ b/shared @@ -1 +1 @@ -Subproject commit 9b41ca5dcacd30f69228d71fcb9ed05be8b542d8 +Subproject commit 32dc9423c21e087aeb5f8990e2e1c56c809cbffe