From 600343905a7b72ba2352a05e735a77f3417cf4ff Mon Sep 17 00:00:00 2001 From: Ingo Huerner Date: Thu, 15 Jan 2015 06:22:00 +0100 Subject: Update after GENIVI code review --- README | 15 +++- include/persistence_client_library.h | 4 +- include/persistence_client_library_key.h | 6 +- src/persistence_client_library.c | 58 +++----------- src/persistence_client_library_handle.c | 103 +++++++++++++++++++++---- src/persistence_client_library_pas_interface.c | 3 +- src/persistence_client_library_prct_access.h | 4 +- test/data/PAS_data.tar.gz | Bin 7018 -> 6316 bytes 8 files changed, 124 insertions(+), 69 deletions(-) diff --git a/README b/README index 15f252a..de3c6a1 100644 --- a/README +++ b/README @@ -47,6 +47,7 @@ Execute the following steps in order to build the component ** --enable-tests to enable the build of the tests ** --enable-pasinterface enable the PAS interface (disabled by default) ** -- with_database decide which storage backend to use +** --enable-appcheck, performs an application check if the using application is a valid/trusted one. *** Itzam/C is currently default backend *** It is recommended to use the key-value-store backend ("-- with_database=key-value-store") * make @@ -100,6 +101,18 @@ Precondition: * Make sure D-Bus system bus is available + +Data location and partitions +-------------- +Persistence expects its data under the two folders /Data/mnt-c and /Data/mnt-wt. +It is requested to have one persistence partition which will be mounted to the two folders stated above (one partition will be mounted to two different mointpoints). + +Example: +sudo mount -t fsType /dev/sdx /Data/mnt-wt +sudo mount -t fsType /dev/sdx /Data/mnt-c + + + Run tests: -------------- run persistency unit test "./persistence_client_library_test" @@ -163,5 +176,5 @@ How to create doxygen documentation ---------------------------- The doxygen package must be installed. -run "doxygen doc/pcl_doxyfile" and the html documentation will be generated in the doc folder. +Run "doxygen doc/pcl_doxyfile" and the html documentation will be generated in the doc folder. diff --git a/include/persistence_client_library.h b/include/persistence_client_library.h index 4a29909..5ab5b4b 100644 --- a/include/persistence_client_library.h +++ b/include/persistence_client_library.h @@ -19,8 +19,8 @@ * Library provides an API to access persistent data * \par change history * Date Author Version - * 25/06/13 Ingo Hürner 1.0.0 - Rework of Init functions - * 04/11/13 Ingo Hürner 1.3.0 - Added define for shutdown type none + * 25/06/13 Ingo Huerner 1.0.0 - Rework of Init functions + * 04/11/13 Ingo Huerner 1.3.0 - Added define for shutdown type none * 12/11/14 Guy Sagnes 1.4.0 - Add defines for accessing: * - node data, configurable default * - specific logical database (local, shared public) diff --git a/include/persistence_client_library_key.h b/include/persistence_client_library_key.h index 338e3e9..04f5a68 100644 --- a/include/persistence_client_library_key.h +++ b/include/persistence_client_library_key.h @@ -19,10 +19,10 @@ * Library provides an API to access persistent data * @par change history * Date Author Version - * 27/03/13 Ingo Hürner 4.0.0 - Add registration for callback notification - * 28/05/13 Ingo Hürner 5.0.0 - Add pclInitLibrary(), pcl DeInitLibrary() incl. shutdown notification + * 27/03/13 Ingo Huerner 4.0.0 - Add registration for callback notification + * 28/05/13 Ingo Huerner 5.0.0 - Add pclInitLibrary(), pcl DeInitLibrary() incl. shutdown notification * 05/06/13 Oliver Bach 6.0.0 - Rework of Init functions - * 04/11/13 Ingo Hürner 6.1.0 - Added functions to unregister notifications + * 04/11/13 Ingo Huerner 6.1.0 - Added functions to unregister notifications */ /** \ingroup GEN_PERS */ /** \defgroup PERS_KEYVALUE Client: Key-value access diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c index 867ad25..893c860 100644 --- a/src/persistence_client_library.c +++ b/src/persistence_client_library.c @@ -32,10 +32,6 @@ #include #endif -#if USE_XSTRACE_PERS - #include -#endif - #include #include #include @@ -154,10 +150,6 @@ static int private_pclInitLibrary(const char* appName, int shutdownMode) { int rval = 1; -#if USE_XSTRACE_PERS - xsm_send_user_event("%s - %d\n", __FUNCTION__, __LINE__); -#endif - gShutdownMode = shutdownMode; char blacklistPath[DbPathMaxLen] = {0}; @@ -172,31 +164,23 @@ static int private_pclInitLibrary(const char* appName, int shutdownMode) pthread_mutex_lock(&gDbusPendingRegMtx); // block until pending received // Assemble backup blacklist path - sprintf(blacklistPath, "%s%s/%s", CACHEPREFIX, appName, gBackupFilename); + snprintf(blacklistPath, DbPathMaxLen, "%s%s/%s", CACHEPREFIX, appName, gBackupFilename); if(readBlacklistConfigFile(blacklistPath) == -1) { DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("initLibrary - Err access blacklist:"), DLT_STRING(blacklistPath)); } -#if USE_XSTRACE_PERS - xsm_send_user_event("%s - %d\n", __FUNCTION__, __LINE__); -#endif if(setup_dbus_mainloop() == -1) { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("initLibrary - Failed to setup main loop")); pthread_mutex_unlock(&gDbusPendingRegMtx); return EPERS_DBUS_MAINLOOP; } -#if USE_XSTRACE_PERS - xsm_send_user_event("%s - %d\n", __FUNCTION__, __LINE__); -#endif - if(gShutdownMode != PCL_SHUTDOWN_TYPE_NONE) { - // register for lifecycle dbus messages - if(register_lifecycle(shutdownMode) == -1) + if(register_lifecycle(shutdownMode) == -1) // register for lifecycle dbus messages { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("initLibrary => Failed reg to LC dbus interface")); pthread_mutex_unlock(&gDbusPendingRegMtx); @@ -219,26 +203,18 @@ static int private_pclInitLibrary(const char* appName, int shutdownMode) DLT_LOG(gPclDLTContext, DLT_LOG_DEBUG, DLT_STRING("PAS interface not enabled, enable with \"./configure --enable-pasinterface\"")); #endif - // load custom plugins - if(load_custom_plugins(customAsyncInitClbk) < 0) + if(load_custom_plugins(customAsyncInitClbk) < 0) // load custom plugins { DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("Failed to load custom plugins")); } - // initialize keyHandle array init_key_handle_array(); pers_unlock_access(); - // assign application name - strncpy(gAppId, appName, MaxAppNameLen); + strncpy(gAppId, appName, MaxAppNameLen); // assign application name gAppId[MaxAppNameLen-1] = '\0'; - -#if USE_XSTRACE_PERS - xsm_send_user_event("%s - %d\n", __FUNCTION__, __LINE__); -#endif - return rval; } @@ -280,18 +256,14 @@ static int private_pclDeinitLibrary(void) { int rval = 1; -#if USE_XSTRACE_PERS - xsm_send_user_event("%s - %d\n", __FUNCTION__, __LINE__); -#endif - - int* retval; MainLoopData_u data; data.message.cmd = (uint32_t)CMD_QUIT; data.message.string[0] = '\0'; // no string parameter, set to 0 - // unregister for lifecycle dbus messages - if(gShutdownMode != PCL_SHUTDOWN_TYPE_NONE) + if(gShutdownMode != PCL_SHUTDOWN_TYPE_NONE) // unregister for lifecycle dbus messages + { rval = unregister_lifecycle(gShutdownMode); + } #if USE_PASINTERFACE == 1 rval = unregister_pers_admin_service(); @@ -305,13 +277,11 @@ static int private_pclDeinitLibrary(void) } #endif - process_prepare_shutdown(Shutdown_Full); // close all db's and fd's and block access + process_prepare_shutdown(Shutdown_Full); // close all db's and fd's and block access - // send quit command to dbus mainloop - deliverToMainloop_NM(&data); + deliverToMainloop_NM(&data); // send quit command to dbus mainloop - // wait until the dbus mainloop has ended - pthread_join(gMainLoopThread, (void**)&retval); + pthread_join(gMainLoopThread, (void**)&retval); // wait until the dbus mainloop has ended pthread_mutex_unlock(&gDbusPendingRegMtx); @@ -319,11 +289,6 @@ static int private_pclDeinitLibrary(void) pfcDeinitCache(); #endif - -#if USE_XSTRACE_PERS - xsm_send_user_event("%s - %d\n", __FUNCTION__, __LINE__); -#endif - return rval; } @@ -338,7 +303,8 @@ int pclLifecycleSet(int shutdown) if(shutdown == PCL_SHUTDOWN) { DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("lifecycleSet - PCL_SHUTDOWN -"), DLT_STRING(gAppId)); - process_prepare_shutdown(Shutdown_Partial); // close all db's and fd's and block access + process_prepare_shutdown(Shutdown_Partial); + gCancelCounter++; } else if(shutdown == PCL_SHUTDOWN_CANCEL) { diff --git a/src/persistence_client_library_handle.c b/src/persistence_client_library_handle.c index c136cb1..10fe283 100644 --- a/src/persistence_client_library_handle.c +++ b/src/persistence_client_library_handle.c @@ -177,7 +177,10 @@ void clear_key_handle_array(int idx) { if(pthread_mutex_lock(&gKeyHandleAccessMtx) == 0) { - memset(&gKeyHandleArray[idx], 0, sizeof(gKeyHandleArray[idx])); + if(idx < MaxPersHandle && idx > 0 ) + { + memset(&gKeyHandleArray[idx], 0, sizeof(gKeyHandleArray[idx])); + } pthread_mutex_unlock(&gKeyHandleAccessMtx); } } @@ -228,12 +231,30 @@ int get_file_permission(int idx) char* get_file_backup_path(int idx) { - return gFileHandleArray[idx].backupPath; + char* charPtr = NULL; + if(pthread_mutex_lock(&gFileHandleAccessMtx) == 0) + { + if(idx < MaxPersHandle && idx > 0 ) + { + charPtr = gFileHandleArray[idx].backupPath; + } + pthread_mutex_unlock(&gFileHandleAccessMtx); + } + return charPtr; } char* get_file_checksum_path(int idx) { - return gFileHandleArray[idx].csumPath; + char* charPtr = NULL; + if(pthread_mutex_lock(&gFileHandleAccessMtx) == 0) + { + if(idx < MaxPersHandle && idx > 0 ) + { + charPtr = gFileHandleArray[idx].csumPath; + } + pthread_mutex_unlock(&gFileHandleAccessMtx); + } + return charPtr; } @@ -241,15 +262,26 @@ void set_file_backup_status(int idx, int status) { if(pthread_mutex_lock(&gFileHandleAccessMtx) == 0) { - gFileHandleArray[idx].backupCreated = status; - + if(MaxPersHandle >= idx && idx > 0 ) + { + gFileHandleArray[idx].backupCreated = status; + } pthread_mutex_unlock(&gFileHandleAccessMtx); } } int get_file_backup_status(int idx) { - return gFileHandleArray[idx].backupCreated; + int backup = -1; + if(pthread_mutex_lock(&gFileHandleAccessMtx) == 0) + { + if(MaxPersHandle >= idx && idx > 0 ) + { + backup= gFileHandleArray[idx].backupCreated; + } + pthread_mutex_unlock(&gFileHandleAccessMtx); + } + return backup; } void set_file_cache_status(int idx, int status) @@ -349,21 +381,43 @@ int get_ossfile_permission(int idx) char* get_ossfile_backup_path(int idx) { - return gOssHandleArray[idx].backupPath; + char* charPtr = NULL; + if(pthread_mutex_lock(&gOssFileHandleAccessMtx) == 0) + { + + if(idx < MaxPersHandle && idx > 0 ) + { + charPtr = gOssHandleArray[idx].backupPath; + } + pthread_mutex_unlock(&gOssFileHandleAccessMtx); + } + return charPtr; } char* get_ossfile_file_path(int idx) { - return gOssHandleArray[idx].filePath; + char* charPtr = NULL; + if(pthread_mutex_lock(&gOssFileHandleAccessMtx) == 0) + { + + if(idx < MaxPersHandle && idx > 0 ) + { + charPtr = gOssHandleArray[idx].filePath; + } + pthread_mutex_unlock(&gOssFileHandleAccessMtx); + } + return charPtr; } void set_ossfile_file_path(int idx, char* file) { if(pthread_mutex_lock(&gOssFileHandleAccessMtx) == 0) { - gOssHandleArray[idx].filePath = file; - + if(idx < MaxPersHandle && idx > 0 ) + { + gOssHandleArray[idx].filePath = file; + } pthread_mutex_unlock(&gOssFileHandleAccessMtx); } } @@ -371,7 +425,16 @@ void set_ossfile_file_path(int idx, char* file) char* get_ossfile_checksum_path(int idx) { - return gOssHandleArray[idx].csumPath; + char* charPtr = NULL; + if(pthread_mutex_lock(&gOssFileHandleAccessMtx) == 0) + { + if(idx < MaxPersHandle && idx > 0 ) + { + charPtr = gOssHandleArray[idx].csumPath; + } + pthread_mutex_unlock(&gOssFileHandleAccessMtx); + } + return charPtr; } @@ -379,13 +442,25 @@ void set_ossfile_backup_status(int idx, int status) { if(pthread_mutex_lock(&gOssFileHandleAccessMtx) == 0) { - gOssHandleArray[idx].backupCreated = status; - + if(idx < MaxPersHandle && idx > 0 ) + { + gOssHandleArray[idx].backupCreated = status; + } pthread_mutex_unlock(&gOssFileHandleAccessMtx); } } int get_ossfile_backup_status(int idx) { - return gOssHandleArray[idx].backupCreated; + int rval = -1; + + if(pthread_mutex_lock(&gOssFileHandleAccessMtx) == 0) + { + if(idx < MaxPersHandle && idx > 0 ) + { + rval = gOssHandleArray[idx].backupCreated; + } + pthread_mutex_unlock(&gOssFileHandleAccessMtx); + } + return rval; } diff --git a/src/persistence_client_library_pas_interface.c b/src/persistence_client_library_pas_interface.c index 704045e..de197c4 100644 --- a/src/persistence_client_library_pas_interface.c +++ b/src/persistence_client_library_pas_interface.c @@ -49,6 +49,7 @@ int isAccessLocked(void) int check_pas_request(unsigned int request, unsigned int requestID) { int rval = 0; + switch(request) { case (PasMsg_Block|PasMsg_WriteBack): @@ -244,7 +245,7 @@ int register_pers_admin_service(void) if(-1 == deliverToMainloop(&data)) { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pegPas - failed write pipe"), DLT_INT(errno)); + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("regPas - failed write pipe"), DLT_INT(errno)); rval = -1; } else diff --git a/src/persistence_client_library_prct_access.h b/src/persistence_client_library_prct_access.h index 53669c5..1737497 100644 --- a/src/persistence_client_library_prct_access.h +++ b/src/persistence_client_library_prct_access.h @@ -53,9 +53,9 @@ int get_db_context(PersistenceInfo_s* dbContext, const char* resource_id, unsign /** - * @brief get the resource configuration table gvbd database by id + * @brief get the resource configuration table database by id * - * @return i Handle to the gvdb database table or negative value if no valid database has been found + * @return i Handle to the database table or negative value if no valid database has been found */ int get_resource_cfg_table_by_idx(int i); diff --git a/test/data/PAS_data.tar.gz b/test/data/PAS_data.tar.gz index 46c5eca..104a295 100644 Binary files a/test/data/PAS_data.tar.gz and b/test/data/PAS_data.tar.gz differ -- cgit v1.2.1