From f518fa1c080ad29df609c3ac41390fde1c0d83e6 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Sat, 19 Jan 2019 10:57:36 -0800 Subject: [PATCH] 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 --- FTL.h | 4 ++++ shmem.c | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/FTL.h b/FTL.h index eda21af6..333e9d79 100644 --- a/FTL.h +++ b/FTL.h @@ -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 diff --git a/shmem.c b/shmem.c index 924dc0ca..3fa355b0 100644 --- a/shmem.c +++ b/shmem.c @@ -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]);