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:
Mcat12
2019-01-19 10:57:36 -08:00
parent 4d97dd8dd4
commit f518fa1c08
2 changed files with 18 additions and 0 deletions
+4
View File
@@ -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
+14
View File
@@ -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]);