mirror of
https://github.com/pi-hole/FTL.git
synced 2024-10-26 16:52:18 +02:00
Add an "/FTL-settings" shared memory block
It currently contains the version of shared memory that FTL is exposing. The current version of shared memory is 1. Whenever a change is made to structures stored in shared memory, or the layout of shared memory, the version should be incremented (like how the database version is incremented when the database changes). This version number will be used by the API to verify it is using the same version of shared memory as FTL. Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
This commit is contained in:
@@ -216,6 +216,10 @@ typedef struct {
|
||||
char **domains;
|
||||
} whitelistStruct;
|
||||
|
||||
typedef struct {
|
||||
int version;
|
||||
} ShmSettings;
|
||||
|
||||
// Prepare timers, used mainly for debugging purposes
|
||||
#define NUMTIMERS LAST_TIMER
|
||||
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
#include "FTL.h"
|
||||
#include "shmem.h"
|
||||
|
||||
/// The version of shared memory used
|
||||
#define SHARED_MEMORY_VERSION 1
|
||||
|
||||
/// The name of the shared memory. Use this when connecting to the shared memory.
|
||||
#define SHARED_LOCK_NAME "/FTL-lock"
|
||||
#define SHARED_STRINGS_NAME "/FTL-strings"
|
||||
@@ -20,6 +23,7 @@
|
||||
#define SHARED_QUERIES_NAME "/FTL-queries"
|
||||
#define SHARED_FORWARDED_NAME "/FTL-forwarded"
|
||||
#define SHARED_OVERTIME_NAME "/FTL-overTime"
|
||||
#define SHARED_SETTINGS_NAME "/FTL-settings"
|
||||
#define SHARED_OVERTIMECLIENT_PREFIX "/FTL-client-"
|
||||
|
||||
/// The pointer in shared memory to the shared string buffer
|
||||
@@ -31,6 +35,7 @@ static SharedMemory shm_clients = { 0 };
|
||||
static SharedMemory shm_queries = { 0 };
|
||||
static SharedMemory shm_forwarded = { 0 };
|
||||
static SharedMemory shm_overTime = { 0 };
|
||||
static SharedMemory shm_settings = { 0 };
|
||||
|
||||
static SharedMemory *shm_overTimeClients = NULL;
|
||||
static int overTimeClientCount = 0;
|
||||
@@ -264,6 +269,14 @@ bool init_shmem(void)
|
||||
overTime = (overTimeDataStruct*)shm_overTime.ptr;
|
||||
counters->overTime_MAX = pagesize;
|
||||
|
||||
/****************************** shared settings struct ******************************/
|
||||
// Try to create shared memory object
|
||||
shm_settings = create_shm(SHARED_SETTINGS_NAME, sizeof(ShmSettings));
|
||||
if(shm_settings.ptr == NULL)
|
||||
return false;
|
||||
ShmSettings *settings = (ShmSettings*)shm_settings.ptr;
|
||||
settings->version = SHARED_MEMORY_VERSION;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -280,6 +293,7 @@ void destroy_shmem(void)
|
||||
delete_shm(&shm_queries);
|
||||
delete_shm(&shm_forwarded);
|
||||
delete_shm(&shm_overTime);
|
||||
delete_shm(&shm_settings);
|
||||
|
||||
for(int i = 0; i < overTimeClientCount; i++) {
|
||||
delete_shm(&shm_overTimeClients[i]);
|
||||
|
||||
Reference in New Issue
Block a user