summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Huerner <ingo_huerner@mentor.com>2017-02-10 09:41:13 +0100
committerIngo Huerner <ingo_huerner@mentor.com>2017-02-10 09:41:13 +0100
commit0817d5a68726e3afc63a6696062027c467af419f (patch)
tree7d2d4ae68c12571d60082ddded3d3bc8c20b51c1
parentb433f9686017ac0e9009957034100759b7f0aa6d (diff)
downloadpersistence-client-library-0817d5a68726e3afc63a6696062027c467af419f.tar.gz
Fixed a array out of bounds access (results in mutex deadlock).
Improved mutex handling. Removed valgrind warning GENIVI JIRA issue PCL-3. Delete remaining semaphores and shared memory in case of app crash.
-rw-r--r--Makefile.am6
-rw-r--r--config/pclCustomLibConfigFileWrongDefault.cfg.in1
-rw-r--r--configure.ac1
-rw-r--r--src/persistence_client_library.c267
-rw-r--r--src/persistence_client_library_data_organization.h2
-rw-r--r--src/persistence_client_library_db_access.c26
-rw-r--r--src/persistence_client_library_dbus_service.c31
-rw-r--r--src/persistence_client_library_dbus_service.h24
-rw-r--r--src/persistence_client_library_file.c228
-rw-r--r--src/persistence_client_library_handle.c8
-rw-r--r--src/persistence_client_library_handle.h4
-rw-r--r--src/persistence_client_library_key.c135
-rw-r--r--src/persistence_client_library_lc_interface.c28
-rw-r--r--src/persistence_client_library_pas_interface.c28
-rw-r--r--test/data/PAS_data.tar.gzbin6843 -> 6843 bytes
-rw-r--r--test/persistence_client_library_test.c29
-rw-r--r--test/persistence_client_library_test_file.c729
-rw-r--r--tools/Makefile.am2
18 files changed, 1205 insertions, 344 deletions
diff --git a/Makefile.am b/Makefile.am
index c4fb757..7e1f631 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -11,7 +11,8 @@ endif
# Write the config file for customer plugins to the config destination
sysconf_DATA = config/pclCustomLibConfigFile.cfg \
- config/pclCustomLibConfigFileEmpty.cfg
+ config/pclCustomLibConfigFileEmpty.cfg \
+ config/pclCustomLibConfigFileWrongDefault.cfg
# Add config file to distribution
EXTRA_DIST = $(sysconf_DATA)
@@ -21,4 +22,5 @@ pkgconfig_DATA=persistence_client_library.pc
MAINTAINERCLEANFILES = \
Makefile.in aclocal.m4 compile config.guess config.h.in config.sub \
- configure depcomp install-sh ltmain.sh persistence_client_library.pc config/pclCustomLibConfigFile.cfg config/pclCustomLibConfigFileEmpty.cfg config.h.in~ Makefile missing
+ configure depcomp install-sh ltmain.sh persistence_client_library.pc config/pclCustomLibConfigFile.cfg \
+ config/pclCustomLibConfigFileEmpty.cfg config/pclCustomLibConfigFileWrongDefault.cfg config.h.in~ Makefile missing
diff --git a/config/pclCustomLibConfigFileWrongDefault.cfg.in b/config/pclCustomLibConfigFileWrongDefault.cfg.in
new file mode 100644
index 0000000..0e2cafd
--- /dev/null
+++ b/config/pclCustomLibConfigFileWrongDefault.cfg.in
@@ -0,0 +1 @@
+default @prefix@/lib/libcustom3perscustom.so init sync
diff --git a/configure.ac b/configure.ac
index 14d058b..7747d0f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -207,6 +207,7 @@ AC_CONFIG_FILES([Makefile
persistence_client_library.pc
config/pclCustomLibConfigFile.cfg
config/pclCustomLibConfigFileEmpty.cfg
+ config/pclCustomLibConfigFileWrongDefault.cfg
src/Makefile
tools/Makefile
test/Makefile])
diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c
index 022e2a4..7266376 100644
--- a/src/persistence_client_library.c
+++ b/src/persistence_client_library.c
@@ -38,6 +38,8 @@
#include <dbus/dbus.h>
#include <pthread.h>
#include <dlt.h>
+#include <dirent.h>
+#include <ctype.h>
/// debug log and trace (DLT) setup
@@ -120,29 +122,115 @@ int doAppcheck(void)
#endif
+#define FILE_DIR_NOT_SELF_OR_PARENT(s) ((s)[0]!='.'&&(((s)[1]!='.'||(s)[2]!='\0')||(s)[1]=='\0'))
+
+
+char* makeShmName(const char* path)
+{
+ size_t pathLen = strlen(path);
+ char* result = (char*) malloc(pathLen + 1); //free happens at lifecycle shutdown
+ int i =0;
+
+ if(result != NULL)
+ {
+ for(i = 0; i < pathLen; i++)
+ {
+ if(!isalnum(path[i]))
+ {
+ result[i] = '_';
+ }
+ else
+ {
+ result[i] = path[i];
+ }
+ }
+ result[i + 1] = '\0';
+ }
+ else
+ {
+ result = NULL;
+ }
+ return result;
+}
+
+
+
+void checkLocalArtefacts(const char* thePath, const char* appName)
+{
+ struct dirent *dirent = NULL;
+
+ if(thePath != NULL && appName != NULL)
+ {
+ char* name = makeShmName(appName);
+
+ if(name != NULL)
+ {
+ DIR *dir = opendir(thePath);
+ if(NULL != dir)
+ {
+ for(dirent = readdir(dir); NULL != dirent; dirent = readdir(dir))
+ {
+ if(FILE_DIR_NOT_SELF_OR_PARENT(dirent->d_name))
+ {
+ if(strstr(dirent->d_name, name))
+ {
+ size_t len = strlen(thePath) + strlen(dirent->d_name)+1;
+ char* fileName = malloc(len);
+
+ if(fileName != NULL)
+ {
+ snprintf(fileName, len, "%s%s", thePath, dirent->d_name);
+ remove(fileName);
+
+ DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclInitLibrary => remove sem + shmem:"), DLT_STRING(fileName));
+ free(fileName);
+ }
+ }
+ }
+ }
+ closedir(dir);
+ }
+ free(name);
+ }
+ }
+}
+
+
+
int pclInitLibrary(const char* appName, int shutdownMode)
{
int rval = 1;
- pthread_mutex_lock(&gInitMutex);
- if(gPclInitCounter == 0)
+ int lock = pthread_mutex_lock(&gInitMutex);
+ if(lock == 0)
{
- DLT_REGISTER_CONTEXT(gPclDLTContext,"PCL","Ctx for PCL Logging");
+ if(gPclInitCounter == 0)
+ {
+ DLT_REGISTER_CONTEXT(gPclDLTContext,"PCL","Ctx for PCL Logging");
- DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary => App:"), DLT_STRING(appName),
- DLT_STRING("- init counter: "), DLT_UINT(gPclInitCounter) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary => App:"), DLT_STRING(appName),
+ DLT_STRING("- init counter: "), DLT_UINT(gPclInitCounter) );
- rval = private_pclInitLibrary(appName, shutdownMode);
+ // do check if there are remaining shared memory and semaphores for local app
+ checkLocalArtefacts("/dev/shm/", appName);
+ //checkGroupArtefacts("/dev/shm", "group_");
+
+ rval = private_pclInitLibrary(appName, shutdownMode);
+ }
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary - App:"), DLT_STRING(gAppId),
+ DLT_STRING("- ONLY INCREMENT init counter: "), DLT_UINT(gPclInitCounter) );
+ }
+
+ gPclInitCounter++; // increment after private init, otherwise atomic access is too early
+ pthread_mutex_unlock(&gInitMutex);
}
else
{
- DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary - App:"), DLT_STRING(gAppId),
- DLT_STRING("- ONLY INCREMENT init counter: "), DLT_UINT(gPclInitCounter) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary - mutex lock failed:"), DLT_INT(lock));
}
- gPclInitCounter++; // increment after private init, otherwise atomic access is too early
- pthread_mutex_unlock(&gInitMutex);
-
return rval;
}
@@ -150,74 +238,82 @@ static int private_pclInitLibrary(const char* appName, int shutdownMode)
{
int rval = 1;
char blacklistPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0};
+ int lock = pthread_mutex_lock(&gDbusPendingRegMtx); // block until pending received
- gShutdownMode = shutdownMode;
+ if(lock == 0)
+ {
+ gShutdownMode = shutdownMode;
#if USE_APPCHECK
- doInitAppcheck(appName); // check if we have a trusted application
+ doInitAppcheck(appName); // check if we have a trusted application
#endif
#if USE_FILECACHE
- DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Using the filecache!!!"));
- pfcInitCache(appName);
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Using the filecache!!!"));
+ pfcInitCache(appName);
#endif
- pthread_mutex_lock(&gDbusPendingRegMtx); // block until pending received
-
- // Assemble backup blacklist path
- snprintf(blacklistPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, "%s%s/%s", CACHEPREFIX, appName, gBackupFilename);
+ // Assemble backup blacklist path
+ snprintf(blacklistPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, "%s%s/%s", CACHEPREFIX, appName, gBackupFilename);
- if(readBlacklistConfigFile(blacklistPath) == -1)
- {
- DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("initLibrary - Err access blacklist:"), DLT_STRING(blacklistPath));
- }
+ if(readBlacklistConfigFile(blacklistPath) == -1)
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("initLibrary - Err access blacklist:"), DLT_STRING(blacklistPath));
+ }
- 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(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(gShutdownMode != PCL_SHUTDOWN_TYPE_NONE)
- {
- 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);
- return EPERS_REGISTER_LIFECYCLE;
- }
- }
+ if(gShutdownMode != PCL_SHUTDOWN_TYPE_NONE)
+ {
+ 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);
+ return EPERS_REGISTER_LIFECYCLE;
+ }
+ }
#if USE_PASINTERFACE
- DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("PAS interface is enabled!!"));
- if(register_pers_admin_service() == -1)
- {
- DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("initLibrary - Failed reg to PAS dbus interface"));
- pthread_mutex_unlock(&gDbusPendingRegMtx);
- return EPERS_REGISTER_ADMIN;
- }
- else
- {
- DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("initLibrary - Successfully established IPC protocol for PCL."));
- }
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("PAS interface is enabled!!"));
+ if(register_pers_admin_service() == -1)
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("initLibrary - Failed reg to PAS dbus interface"));
+ pthread_mutex_unlock(&gDbusPendingRegMtx);
+ return EPERS_REGISTER_ADMIN;
+ }
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("initLibrary - Successfully established IPC protocol for PCL."));
+ }
#else
- DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("PAS interface not enabled, enable with \"./configure --enable-pasinterface\""));
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("PAS interface not enabled, enable with \"./configure --enable-pasinterface\""));
#endif
- if((rval = load_custom_plugins(customAsyncInitClbk)) < 0) // load custom plugins
- {
- DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("Failed to load custom plugins"));
- pthread_mutex_unlock(&gDbusPendingRegMtx);
- return rval;
- }
+ if((rval = load_custom_plugins(customAsyncInitClbk)) < 0) // load custom plugins
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("Failed to load custom plugins"));
+ pthread_mutex_unlock(&gDbusPendingRegMtx);
+ return rval;
+ }
- init_key_handle_array();
+ init_key_handle_array();
- pers_unlock_access();
+ pers_unlock_access();
- strncpy(gAppId, appName, PERS_RCT_MAX_LENGTH_RESPONSIBLE); // assign application name
- gAppId[PERS_RCT_MAX_LENGTH_RESPONSIBLE-1] = '\0';
+ strncpy(gAppId, appName, PERS_RCT_MAX_LENGTH_RESPONSIBLE); // assign application name
+ gAppId[PERS_RCT_MAX_LENGTH_RESPONSIBLE-1] = '\0';
+
+ pthread_mutex_unlock(&gDbusPendingRegMtx);
+ }
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("private_pclInitLibrary - mutex lock failed:"), DLT_INT(lock));
+ }
return rval;
}
@@ -228,31 +324,34 @@ int pclDeinitLibrary(void)
{
int rval = 1;
- pthread_mutex_lock(&gInitMutex);
+ int lock = pthread_mutex_lock(&gInitMutex);
- if(gPclInitCounter == 1)
+ if(lock == 0)
{
- DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclDeinitLibrary - DEINIT client lib - "), DLT_STRING(gAppId),
- DLT_STRING("- init counter: "), DLT_UINT(gPclInitCounter));
- rval = private_pclDeinitLibrary();
+ if(gPclInitCounter == 1)
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclDeinitLibrary - DEINIT client lib - "), DLT_STRING(gAppId),
+ DLT_STRING("- init counter: "), DLT_UINT(gPclInitCounter));
+ rval = private_pclDeinitLibrary();
- gPclInitCounter--; // decrement init counter
- DLT_UNREGISTER_CONTEXT(gPclDLTContext);
- }
- else if(gPclInitCounter > 1)
- {
- DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclDeinitLibrary - DEINIT client lib - "), DLT_STRING(gAppId),
- DLT_STRING("- ONLY DECREMENT init counter: "), DLT_UINT(gPclInitCounter));
- gPclInitCounter--; // decrement init counter
- }
- else
- {
- DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclDeinitLibrary - DEINIT client lib - "), DLT_STRING(gAppId),
- DLT_STRING("- NOT INITIALIZED: "));
- rval = EPERS_NOT_INITIALIZED;
- }
+ gPclInitCounter--; // decrement init counter
+ DLT_UNREGISTER_CONTEXT(gPclDLTContext);
+ }
+ else if(gPclInitCounter > 1)
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclDeinitLibrary - DEINIT client lib - "), DLT_STRING(gAppId),
+ DLT_STRING("- ONLY DECREMENT init counter: "), DLT_UINT(gPclInitCounter));
+ gPclInitCounter--; // decrement init counter
+ }
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclDeinitLibrary - DEINIT client lib - "), DLT_STRING(gAppId),
+ DLT_STRING("- NOT INITIALIZED: "));
+ rval = EPERS_NOT_INITIALIZED;
+ }
- pthread_mutex_unlock(&gInitMutex);
+ pthread_mutex_unlock(&gInitMutex);
+ }
return rval;
}
@@ -263,8 +362,10 @@ static int private_pclDeinitLibrary(void)
int* retval;
MainLoopData_u data;
- data.message.cmd = (uint32_t)CMD_QUIT;
- data.message.string[0] = '\0'; // no string parameter, set to 0
+
+ memset(&data, 0, sizeof(MainLoopData_u));
+ data.cmd = (uint32_t)CMD_QUIT;
+ data.string[0] = '\0'; // no string parameter, set to 0
if(gShutdownMode != PCL_SHUTDOWN_TYPE_NONE) // unregister for lifecycle dbus messages
{
diff --git a/src/persistence_client_library_data_organization.h b/src/persistence_client_library_data_organization.h
index acb2c35..211fb3a 100644
--- a/src/persistence_client_library_data_organization.h
+++ b/src/persistence_client_library_data_organization.h
@@ -165,7 +165,7 @@ enum _PersistenceConstantDef
/// persistence administration service msg return status
PasErrorStatus_FAIL = 0x8000,
/// max number of parallel open persistence handles
- MaxPersHandle = 255,
+ MaxPersHandle = 512,
/// length of the config key responsible name
MaxConfKeyLengthResp = 32,
/// length of the config key custom name
diff --git a/src/persistence_client_library_db_access.c b/src/persistence_client_library_db_access.c
index 9b31400..df0ba38 100644
--- a/src/persistence_client_library_db_access.c
+++ b/src/persistence_client_library_db_access.c
@@ -705,13 +705,14 @@ int persistence_notify_on_change(const char* resource_id, const char* dbKey, uns
key_value_s* searchItem = NULL;
unsigned int hashKey = pclCrc32(0, (unsigned char*)dbKey, strlen(dbKey));
- data.message.cmd = (uint32_t)CMD_REG_NOTIFY_SIGNAL;
- data.message.params[0] = ldbid;
- data.message.params[1] = user_no;
- data.message.params[2] = seat_no;
- data.message.params[3] = regPolicy;
+ memset(&data, 0, sizeof(MainLoopData_u));
+ data.cmd = (uint32_t)CMD_REG_NOTIFY_SIGNAL;
+ data.params[0] = ldbid;
+ data.params[1] = user_no;
+ data.params[2] = seat_no;
+ data.params[3] = regPolicy;
- snprintf(data.message.string, PERS_DB_MAX_LENGTH_KEY_NAME, "%s", resource_id);
+ snprintf(data.string, PERS_DB_MAX_LENGTH_KEY_NAME, "%s", resource_id);
// check if the tree has already been created
if(gNotificationTree == NULL)
@@ -789,13 +790,14 @@ int pers_send_Notification_Signal(const char* key, PersistenceDbContext_s* conte
{
MainLoopData_u data;
- data.message.cmd = (uint32_t)CMD_SEND_NOTIFY_SIGNAL;
- data.message.params[0] = context->ldbid;
- data.message.params[1] = context->user_no;
- data.message.params[2] = context->seat_no;
- data.message.params[3] = reason;
+ memset(&data, 0, sizeof(MainLoopData_u));
+ data.cmd = (uint32_t)CMD_SEND_NOTIFY_SIGNAL;
+ data.params[0] = context->ldbid;
+ data.params[1] = context->user_no;
+ data.params[2] = context->seat_no;
+ data.params[3] = reason;
- snprintf(data.message.string, PERS_DB_MAX_LENGTH_KEY_NAME, "%s", key);
+ snprintf(data.string, PERS_DB_MAX_LENGTH_KEY_NAME, "%s", key);
if(-1 == deliverToMainloop(&data) )
{
diff --git a/src/persistence_client_library_dbus_service.c b/src/persistence_client_library_dbus_service.c
index b9bcfdf..68fe56e 100644
--- a/src/persistence_client_library_dbus_service.c
+++ b/src/persistence_client_library_dbus_service.c
@@ -496,38 +496,38 @@ int dispatchInternalCommand(DBusConnection* conn, MainLoopData_u* readData, int*
int rval = 1;
//DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("mainLoop - receive cmd:"), DLT_INT(readData.message.cmd));
- switch (readData->message.cmd)
+ switch (readData->cmd)
{
case CMD_PAS_BLOCK_AND_WRITE_BACK:
- process_block_and_write_data_back((unsigned int)readData->message.params[1] /*requestID*/, (unsigned int)readData->message.params[0] /*status*/);
- process_send_pas_request(conn, (unsigned int)readData->message.params[1] /*request*/, (int)readData->message.params[0] /*status*/);
+ process_block_and_write_data_back((unsigned int)readData->params[1] /*requestID*/, (unsigned int)readData->params[0] /*status*/);
+ process_send_pas_request(conn, (unsigned int)readData->params[1] /*request*/, (int)readData->params[0] /*status*/);
break;
case CMD_LC_PREPARE_SHUTDOWN:
process_prepare_shutdown(Shutdown_Full);
- process_send_lifecycle_request(conn, (unsigned int)readData->message.params[1] /*requestID*/, (unsigned int)readData->message.params[0] /*status*/);
+ process_send_lifecycle_request(conn, (unsigned int)readData->params[1] /*requestID*/, (unsigned int)readData->params[0] /*status*/);
break;
case CMD_SEND_NOTIFY_SIGNAL:
- process_send_notification_signal(conn, (unsigned int)readData->message.params[0] /*ldbid*/, (unsigned int)readData->message.params[1], /*user*/
- (unsigned int)readData->message.params[2] /*seat*/, (unsigned int)readData->message.params[3], /*reason*/
- readData->message.string);
+ process_send_notification_signal(conn, (unsigned int)readData->params[0] /*ldbid*/, (unsigned int)readData->params[1], /*user*/
+ (unsigned int)readData->params[2] /*seat*/, (unsigned int)readData->params[3], /*reason*/
+ readData->string);
break;
case CMD_REG_NOTIFY_SIGNAL:
- process_reg_notification_signal(conn, (unsigned int)readData->message.params[0] /*ldbid*/, (unsigned int)readData->message.params[1], /*user*/
- (unsigned int)readData->message.params[2] /*seat*/, (unsigned int)readData->message.params[3], /*,policy*/
- readData->message.string);
+ process_reg_notification_signal(conn, (unsigned int)readData->params[0] /*ldbid*/, (unsigned int)readData->params[1], /*user*/
+ (unsigned int)readData->params[2] /*seat*/, (unsigned int)readData->params[3], /*,policy*/
+ readData->string);
break;
case CMD_SEND_PAS_REGISTER:
- process_send_pas_register(conn, (int)readData->message.params[0] /*regType*/, (int)readData->message.params[1] /*notifyFlag*/);
+ process_send_pas_register(conn, (int)readData->params[0] /*regType*/, (int)readData->params[1] /*notifyFlag*/);
break;
case CMD_SEND_LC_REGISTER:
- process_send_lifecycle_register(conn, (int)readData->message.params[0] /*regType*/, (int)readData->message.params[1] /*mode*/);
+ process_send_lifecycle_register(conn, (int)readData->params[0] /*regType*/, (int)readData->params[1] /*mode*/);
break;
case CMD_QUIT:
rval = 0;
*quit = TRUE;
break;
default:
- DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop - cmd not handled"), DLT_UINT32(readData->message.cmd) );
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop - cmd not handled"), DLT_UINT32(readData->cmd) );
break;
}
@@ -585,8 +585,9 @@ void* mainLoop(void* userData)
if (0!=(gPollInfo.fds[i].revents & POLLIN)) // dispatch internal command
{
MainLoopData_u readData;
+
bContinue = TRUE;
- while ((-1==(ret = (int)read((int)(gPollInfo.fds[i].fd), readData.payload, (size_t)sizeof(struct message_))))&&(EINTR == errno));
+ while ((-1==(ret = (int)read((int)(gPollInfo.fds[i].fd), (void*)&readData, (size_t)sizeof(MainLoopData_u))))&&(EINTR == errno));
if(ret < 0)
{
DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop - read() failed"), DLT_STRING(strerror(errno)) );
@@ -676,7 +677,7 @@ int deliverToMainloop_NM(MainLoopData_u* payload)
{
int rval = 0;
- if(-1 == write(gPipeFd[1], payload->payload, sizeof(struct message_)))
+ if(-1 == write(gPipeFd[1], payload, sizeof(MainLoopData_u)))
{
DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("toMainloop => failed write pipe"), DLT_INT(errno));
rval = -1;
diff --git a/src/persistence_client_library_dbus_service.h b/src/persistence_client_library_dbus_service.h
index 7b6544b..365d11b 100644
--- a/src/persistence_client_library_dbus_service.h
+++ b/src/persistence_client_library_dbus_service.h
@@ -51,20 +51,16 @@ typedef enum ECmd
/// command data union definition
-typedef union MainLoopData_u_{
-
- /// message structure
- struct message_ {
- /// dbus mainloop command
- uint32_t cmd;
- /// unsigned int parameters
- uint32_t params[4];
- /// string parameter
- char string[PERS_DB_MAX_LENGTH_KEY_NAME];
- }message;
-
- /// the message payload
- char payload[sizeof(struct message_)];
+typedef struct MainLoopData_u_{
+
+ /// dbus mainloop command
+ uint32_t cmd;
+ /// unsigned int parameters
+ uint32_t params[4];
+ /// string parameter
+ char string[PERS_DB_MAX_LENGTH_KEY_NAME];
+
+
} MainLoopData_u;
/// dbus pending mutex => visibility "hidden" to prevent the use outside the library
diff --git a/src/persistence_client_library_file.c b/src/persistence_client_library_file.c
index 4291d87..f8e9304 100644
--- a/src/persistence_client_library_file.c
+++ b/src/persistence_client_library_file.c
@@ -51,7 +51,7 @@ static const int gCPathPrefixSize = sizeof(CACHEPREFIX)-1;
// size of write through string
static const int gWTPathPrefixSize = sizeof(WTPREFIX)-1;
-static pthread_mutex_t gFileAccessMtx = PTHREAD_MUTEX_INITIALIZER;
+pthread_mutex_t gFileAccessMtx = PTHREAD_MUTEX_INITIALIZER;
// local function prototype
static int pclFileGetDefaultData(int handle, const char* resource_id, int policy);
@@ -95,7 +95,8 @@ int pclFileClose(int fd)
if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0)
{
- if(pthread_mutex_lock(&gFileAccessMtx) == 0)
+ int lock = pthread_mutex_lock(&gFileAccessMtx);
+ if(lock == 0)
{
#if USE_APPCHECK
if(doAppcheck() == 1)
@@ -103,7 +104,6 @@ int pclFileClose(int fd)
#endif
int permission = get_file_permission(fd);
-
if(permission != -1) // permission is here also used for range check
{
// check if a backup and checksum file needs to be deleted
@@ -120,9 +120,9 @@ int pclFileClose(int fd)
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileClose - csum remove failed!"), DLT_STRING(strerror(errno)) );
}
-
}
- __sync_fetch_and_sub(&gOpenFdArray[fd], FileClosed); // set closed flag
+ if(fd < MaxPersHandle)
+ __sync_fetch_and_sub(&gOpenFdArray[fd], FileClosed); // set closed flag
// remove form file tree;
if(remove_file_handle_data(fd) != 1)
@@ -158,12 +158,18 @@ int pclFileClose(int fd)
#endif
pthread_mutex_unlock(&gFileAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileClose - mutex lock failed:"), DLT_INT(lock));
+ }
}
else
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileClose - not initialized"));
}
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- pclFileClose - fd:"), DLT_INT(fd));
+
return rval;
}
@@ -173,9 +179,12 @@ int pclFileGetSize(int fd)
{
int size = EPERS_NOT_INITIALIZED;
+ DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileGetSize fd: "), DLT_INT(fd));
+
if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0)
{
- if(pthread_mutex_lock(&gFileAccessMtx) == 0)
+ int lock = pthread_mutex_lock(&gFileAccessMtx);
+ if(lock == 0)
{
struct stat buf;
@@ -203,11 +212,18 @@ int pclFileGetSize(int fd)
#endif
pthread_mutex_unlock(&gFileAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileGetSize - mutex lock failed:"), DLT_INT(lock));
+ }
}
else
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileGetSize - not initialized"));
}
+
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- pclFileGetSize fd: "), DLT_INT(fd));
+
return size;
}
@@ -228,7 +244,8 @@ void* pclFileMapData(void* addr, long size, long offset, int fd)
if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0)
{
- if(pthread_mutex_lock(&gFileAccessMtx) == 0)
+ int lock = pthread_mutex_lock(&gFileAccessMtx);
+ if(lock == 0)
{
if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked
{
@@ -240,6 +257,10 @@ void* pclFileMapData(void* addr, long size, long offset, int fd)
}
pthread_mutex_unlock(&gFileAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileMapData - mutex lock failed:"), DLT_INT(lock));
+ }
}
else
{
@@ -247,6 +268,8 @@ void* pclFileMapData(void* addr, long size, long offset, int fd)
}
#endif
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- pclFileMapData fd: "), DLT_INT(fd));
+
return ptr;
}
@@ -291,6 +314,7 @@ int pclFileOpenRegular(PersistenceInfo_s* dbContext, const char* resource_id, ch
if((handle = pclVerifyConsistency(dbPath, backupPath, csumPath, flags)) == -1)
{
DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("fileOpen - file inconsist, recov N O T possible!"));
+ close(handle);
return -1;
}
}
@@ -334,45 +358,61 @@ int pclFileOpenRegular(PersistenceInfo_s* dbContext, const char* resource_id, ch
cacheStatus = 1;
}
}
-#endif
- // file does not exist, create it and get default data
- if(handle == -1 && errno == ENOENT)
+#endif
+ if(handle < MaxPersHandle)
{
- if((handle = pclCreateFile(dbPath, cacheStatus)) == -1)
+ // file does not exist, create it and get default data
+ if(handle == -1 && errno == ENOENT)
{
- DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("fileOpen - failed create file: "), DLT_STRING(dbPath));
- }
- else
- {
- if(pclFileGetDefaultData(handle, resource_id, dbContext->configKey.policy) == -1) // try to get default data
+ handle = pclCreateFile(dbPath, cacheStatus);
+
+ if(handle == -1)
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("fileOpen - failed create file: "), DLT_STRING(dbPath));
+ }
+ else if(handle >= MaxPersHandle) // number of max handles exceeded
{
- DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("fileOpen - no def data avail: "), DLT_STRING(resource_id));
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("fileOpen - failed create file: "), DLT_STRING(dbPath));
+ close(handle);
+ handle = EPERS_MAXHANDLE;
+ }
+ else
+ {
+ if(pclFileGetDefaultData(handle, resource_id, dbContext->configKey.policy) == -1) // try to get default data
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("fileOpen - no def data avail: "), DLT_STRING(resource_id));
+ }
+ set_file_cache_status(handle, cacheStatus);
}
}
- set_file_cache_status(handle, cacheStatus);
- }
- if(dbContext->configKey.permission != PersistencePermission_ReadOnly)
- {
- if(set_file_handle_data(handle, dbContext->configKey.permission, backupPath, csumPath, NULL) != -1)
+ if(dbContext->configKey.permission != PersistencePermission_ReadOnly)
{
- set_file_backup_status(handle, wantBackup);
- __sync_fetch_and_add(&gOpenFdArray[handle], FileOpen); // set open flag
+ if(set_file_handle_data(handle, dbContext->configKey.permission, backupPath, csumPath, NULL) != -1)
+ {
+ set_file_backup_status(handle, wantBackup);
+ __sync_fetch_and_add(&gOpenFdArray[handle], FileOpen); // set open flag
+ }
+ else
+ {
+ close(handle);
+ handle = EPERS_MAXHANDLE;
+ }
}
else
{
- close(handle);
- handle = EPERS_MAXHANDLE;
+ if(set_file_handle_data(handle, dbContext->configKey.permission, backupPath, csumPath, NULL) == -1)
+ {
+ close(handle);
+ handle = EPERS_MAXHANDLE;
+ }
}
}
else
{
- if(set_file_handle_data(handle, dbContext->configKey.permission, backupPath, csumPath, NULL) == -1)
- {
- close(handle);
- handle = EPERS_MAXHANDLE;
- }
+ close(handle);
+ handle = EPERS_MAXHANDLE;
}
}
else // requested resource is not in the RCT, so create resource as local/cached.
@@ -380,27 +420,38 @@ int pclFileOpenRegular(PersistenceInfo_s* dbContext, const char* resource_id, ch
// assemble file string for local cached location
snprintf(dbPath, PERS_ORG_MAX_LENGTH_PATH_FILENAME, getLocalCacheFilePath(), gAppId, user_no, seat_no, resource_id);
handle = pclCreateFile(dbPath, 1);
- set_file_cache_status(handle, 1);
- if(handle != -1)
+ if(handle < MaxPersHandle)
{
- if(set_file_handle_data(handle, PersistencePermission_ReadWrite, backupPath, csumPath, NULL) != -1)
- {
- set_file_backup_status(handle, 1);
- __sync_fetch_and_add(&gOpenFdArray[handle], FileOpen); // set open flag
- }
- else
+ set_file_cache_status(handle, 1);
+
+ if(handle != -1)
{
-#if USE_FILECACHE
- pfcCloseFile(handle);
-#else
- close(handle);
-#endif
- handle = EPERS_MAXHANDLE;
+ if(set_file_handle_data(handle, PersistencePermission_ReadWrite, backupPath, csumPath, NULL) != -1)
+ {
+ set_file_backup_status(handle, 1);
+ __sync_fetch_and_add(&gOpenFdArray[handle], FileOpen); // set open flag
+ }
+ else
+ {
+ #if USE_FILECACHE
+ pfcCloseFile(handle);
+ #else
+ close(handle);
+ #endif
+ handle = EPERS_MAXHANDLE;
+ }
}
}
+ else
+ {
+ close(handle);
+ handle = EPERS_MAXHANDLE;
+ }
}
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- pclFileOpenRegular - res:"), DLT_STRING(resource_id));
+
return handle;
}
@@ -441,13 +492,15 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n
if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0)
{
- if(pthread_mutex_lock(&gFileAccessMtx) == 0)
+ int lock = pthread_mutex_lock(&gFileAccessMtx);
+
+ if(lock == 0)
{
PersistenceInfo_s dbContext;
int shared_DB = 0;
- char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key
- char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location
+ char dbKey[PERS_DB_MAX_LENGTH_KEY_NAME] = {0}; // database key
+ char dbPath[PERS_ORG_MAX_LENGTH_PATH_FILENAME] = {0}; // database location
//DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileOpen: "), DLT_INT(ldbid), DLT_STRING(resource_id) );
@@ -464,7 +517,15 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n
if(user_no == (unsigned int)PCL_USER_DEFAULTDATA)
{
handle = pclFileOpenDefaultData(&dbContext, resource_id);
+ if(handle >= MaxPersHandle)
+ {
+ close(handle);
+ pthread_mutex_unlock(&gFileAccessMtx);
+ return EPERS_MAXHANDLE;
+ }
+
set_file_user_id(handle, (int)PCL_USER_DEFAULTDATA);
+
// as default data will be opened, use read/write permission and we don't need backup and csum path so use an empty string.
set_file_handle_data(handle, PersistencePermission_ReadWrite, "", "", NULL);
}
@@ -477,13 +538,21 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n
{
handle = EPERS_RESOURCE_NO_FILE; // resource is not marked as file in RCT
}
+
pthread_mutex_unlock(&gFileAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileOpen - mutex lock failed:"), DLT_INT(lock));
+ }
} // initialized
else
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileOpen - not initialized"));
}
+
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- pclFileOpen - handle:"), DLT_INT(handle), DLT_STRING(" res:"), DLT_STRING(resource_id));
+
return handle;
}
@@ -497,9 +566,9 @@ int pclFileReadData(int fd, void * buffer, int buffer_size)
if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0)
{
- if(pthread_mutex_lock(&gFileAccessMtx) == 0)
+ int lock = pthread_mutex_lock(&gFileAccessMtx);
+ if(lock == 0)
{
-
#if USE_FILECACHE
if(get_file_cache_status(fd) == 1 && get_file_user_id(fd) != (int)PCL_USER_DEFAULTDATA)
{
@@ -514,11 +583,17 @@ int pclFileReadData(int fd, void * buffer, int buffer_size)
#endif
pthread_mutex_unlock(&gFileAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileReadData - mutex lock failed:"), DLT_INT(lock));
+ }
}
else
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileReadData - not initialized"));
}
+
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- pclFileReadData - fd:"), DLT_INT(fd));
return readSize;
}
@@ -532,7 +607,8 @@ int pclFileRemove(unsigned int ldbid, const char* resource_id, unsigned int user
if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0)
{
- if(pthread_mutex_lock(&gFileAccessMtx) == 0)
+ int lock = pthread_mutex_lock(&gFileAccessMtx);
+ if(lock == 0)
{
if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked
{
@@ -570,11 +646,17 @@ int pclFileRemove(unsigned int ldbid, const char* resource_id, unsigned int user
}
pthread_mutex_unlock(&gFileAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileRemove - mutex lock failed:"), DLT_INT(lock));
+ }
}
else
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileRemove - not initialized"));
}
+
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- pclFileRemove - ldbid"), DLT_UINT(ldbid), DLT_STRING(" res:"), DLT_STRING(resource_id));
return rval;
}
@@ -588,7 +670,8 @@ int pclFileSeek(int fd, long int offset, int whence)
if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0)
{
- if(pthread_mutex_lock(&gFileAccessMtx) == 0)
+ int lock = pthread_mutex_lock(&gFileAccessMtx);
+ if(lock == 0)
{
if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked
{
@@ -611,12 +694,18 @@ int pclFileSeek(int fd, long int offset, int whence)
}
pthread_mutex_unlock(&gFileAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileSeek - mutex lock failed:"), DLT_INT(lock));
+ }
}
else
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileSeek - not initialized"));
}
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- pclFileSeek - fd"), DLT_INT(fd));
+
return rval;
}
@@ -630,7 +719,8 @@ int pclFileUnmapData(void* address, long size)
if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0)
{
- if(pthread_mutex_lock(&gFileAccessMtx) == 0)
+ int lock = pthread_mutex_lock(&gFileAccessMtx);
+ if(lock == 0)
{
if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked
{
@@ -642,12 +732,18 @@ int pclFileUnmapData(void* address, long size)
}
pthread_mutex_unlock(&gFileAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileUnmapData - mutex lock failed:"), DLT_INT(lock));
+ }
}
else
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileUnmapData - not initialized"));
}
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- pclFileUnmapData"));
+
return rval;
}
@@ -661,7 +757,8 @@ int pclFileWriteData(int fd, const void * buffer, int buffer_size)
if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0)
{
- if(pthread_mutex_lock(&gFileAccessMtx) == 0)
+ int lock = pthread_mutex_lock(&gFileAccessMtx);
+ if(lock == 0)
{
if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked
{
@@ -681,7 +778,6 @@ int pclFileWriteData(int fd, const void * buffer, int buffer_size)
set_file_backup_status(fd, 1);
}
-
#if USE_FILECACHE
if(get_file_cache_status(fd) == 1 && get_file_user_id(fd) != (int)PCL_USER_DEFAULTDATA)
{
@@ -720,12 +816,18 @@ int pclFileWriteData(int fd, const void * buffer, int buffer_size)
}
pthread_mutex_unlock(&gFileAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileWriteData - mutex lock failed:"), DLT_INT(lock));
+ }
}
else
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileWriteData - not initialized"));
}
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- pclFileWriteData fd:"), DLT_INT(fd));
+
return size;
}
@@ -738,7 +840,8 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int
if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0)
{
- if(pthread_mutex_lock(&gFileAccessMtx) == 0)
+ int lock = pthread_mutex_lock(&gFileAccessMtx);
+ if(lock == 0)
{
int shared_DB = 0;
PersistenceInfo_s dbContext;
@@ -773,6 +876,7 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int
if((handle = pclVerifyConsistency(dbPath, backupPath, csumPath, flags)) == -1)
{
DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("fileCreatePath - file inconsistent, recovery NOT possible!"));
+ pthread_mutex_unlock(&gFileAccessMtx);
return -1;
}
// we don't need the file handle here
@@ -876,6 +980,10 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int
}
pthread_mutex_unlock(&gFileAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileCreatePath - mutex lock failed:"), DLT_INT(lock));
+ }
}
else
{
@@ -895,7 +1003,8 @@ int pclFileReleasePath(int pathHandle)
if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0)
{
- if(pthread_mutex_lock(&gFileAccessMtx) == 0)
+ int lock = pthread_mutex_lock(&gFileAccessMtx);
+ if(lock == 0)
{
int permission = get_ossfile_permission(pathHandle);
if(permission != -1) // permission is here also used for range check
@@ -936,12 +1045,15 @@ int pclFileReleasePath(int pathHandle)
}
pthread_mutex_unlock(&gFileAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclFileReleasePath - mutex lock failed:"), DLT_INT(lock));
+ }
}
else
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclFileReleasePath - not initialized"));
}
-
return rval;
}
diff --git a/src/persistence_client_library_handle.c b/src/persistence_client_library_handle.c
index 31624bf..34e16bf 100644
--- a/src/persistence_client_library_handle.c
+++ b/src/persistence_client_library_handle.c
@@ -44,9 +44,9 @@ static jsw_rbtree_t *gOssFileHandleTree = NULL;
// open file descriptor handle array
-int gOpenFdArray[MaxPersHandle] = { [0 ...MaxPersHandle-1] = 0 };
+char gOpenFdArray[MaxPersHandle] = { [0 ...MaxPersHandle-1] = 0 };
// handle array
-int gOpenHandleArray[MaxPersHandle] = { [0 ...MaxPersHandle-1] = 0 };
+char gOpenHandleArray[MaxPersHandle] = { [0 ...MaxPersHandle-1] = 0 };
// handle index
static int gHandleIdx = 1;
@@ -262,6 +262,7 @@ int remove_file_handle_data(int idx)
{
item->key = idx;
rval = jsw_rberase(gFileHandleTree, item);
+ free(item);
}
}
@@ -308,8 +309,6 @@ int set_file_handle_data(int idx, PersistencePermission_e permission, const char
//debugFileItem("set_file_handle_data => insert", item);
jsw_rbinsert(gFileHandleTree, item);
-
-
}
else
{
@@ -1015,6 +1014,7 @@ int remove_ossfile_handle_data(int idx)
{
item->key = idx;
rval = jsw_rberase(gOssFileHandleTree, item);
+ free(item);
}
}
diff --git a/src/persistence_client_library_handle.h b/src/persistence_client_library_handle.h
index 881a8df..b3c4481 100644
--- a/src/persistence_client_library_handle.h
+++ b/src/persistence_client_library_handle.h
@@ -56,10 +56,10 @@ typedef struct _PersistenceFileHandle_s
} PersistenceFileHandle_s;
/// open file descriptor handle array
-extern int gOpenFdArray[MaxPersHandle];
+extern char gOpenFdArray[MaxPersHandle];
/// handle array
-extern int gOpenHandleArray[MaxPersHandle];
+extern char gOpenHandleArray[MaxPersHandle];
//----------------------------------------------------------------
//----------------------------------------------------------------
diff --git a/src/persistence_client_library_key.c b/src/persistence_client_library_key.c
index 750200f..2d5c2c4 100644
--- a/src/persistence_client_library_key.c
+++ b/src/persistence_client_library_key.c
@@ -56,7 +56,8 @@ int pclKeyHandleOpen(unsigned int ldbid, const char* resource_id, unsigned int u
if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0)
{
- if(pthread_mutex_lock(&gKeyAPIHandleAccessMtx) == 0)
+ int lock = pthread_mutex_lock(&gKeyAPIHandleAccessMtx);
+ if(lock == 0)
{
#if USE_APPCHECK
@@ -99,12 +100,18 @@ int pclKeyHandleOpen(unsigned int ldbid, const char* resource_id, unsigned int u
#endif
pthread_mutex_unlock(&gKeyAPIHandleAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("keyHandleOpen - mutex lock failed:"), DLT_INT(lock));
+ }
}
else
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("keyHandleOpen - not initialized"));
}
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- keyHandleOpen - ldbid:"), DLT_UINT(ldbid), DLT_STRING(" res:"), DLT_STRING(resource_id));
+
return handle;
}
@@ -118,7 +125,9 @@ int pclKeyHandleClose(int key_handle)
if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0)
{
- if(pthread_mutex_lock(&gKeyAPIHandleAccessMtx) == 0)
+ int lock = pthread_mutex_lock(&gKeyAPIHandleAccessMtx);
+
+ if(lock == 0)
{
#if USE_APPCHECK
if(doAppcheck() == 1)
@@ -153,12 +162,18 @@ int pclKeyHandleClose(int key_handle)
#endif
pthread_mutex_unlock(&gKeyAPIHandleAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleClose - mutex lock failed:"), DLT_INT(lock));
+ }
}
else
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclKeyHandleClose - not initialized"));
}
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- pclKeyHandleClose - key_handle:"), DLT_INT(key_handle));
+
return rval;
}
@@ -172,7 +187,8 @@ int pclKeyHandleGetSize(int key_handle)
if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0)
{
- if(pthread_mutex_lock(&gKeyAPIHandleAccessMtx) == 0)
+ int lock = pthread_mutex_lock(&gKeyAPIHandleAccessMtx);
+ if( lock == 0)
{
#if USE_APPCHECK
if(doAppcheck() == 1)
@@ -205,12 +221,18 @@ int pclKeyHandleGetSize(int key_handle)
#endif
pthread_mutex_unlock(&gKeyAPIHandleAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleGetSize - mutex lock failed:"), DLT_INT(lock));
+ }
}
else
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclKeyHandleGetSize - not initialized"));
}
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- pclKeyHandleGetSize - key_handle:"), DLT_INT(key_handle));
+
return size;
}
@@ -224,7 +246,8 @@ int pclKeyHandleReadData(int key_handle, unsigned char* buffer, int buffer_size)
if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0)
{
- if(pthread_mutex_lock(&gKeyAPIHandleAccessMtx) == 0)
+ int lock = pthread_mutex_lock(&gKeyAPIHandleAccessMtx);
+ if(lock == 0)
{
#if USE_APPCHECK
if(doAppcheck() == 1)
@@ -258,12 +281,18 @@ int pclKeyHandleReadData(int key_handle, unsigned char* buffer, int buffer_size)
#endif
pthread_mutex_unlock(&gKeyAPIHandleAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleReadData - mutex lock failed:"), DLT_INT(lock));
+ }
}
else
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclKeyHandleReadData - not initialized"));
}
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- pclKeyHandleReadData - key_handle:"), DLT_INT(key_handle));
+
return size;
}
@@ -272,10 +301,11 @@ int pclKeyHandleReadData(int key_handle, unsigned char* buffer, int buffer_size)
int pclKeyHandleRegisterNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback)
{
int rval = EPERS_COMMON;
-
+ int lock = 0;
DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleRegisterNotifyOnChange - key_handle:"), DLT_INT(key_handle));
- if(pthread_mutex_lock(&gKeyAPIHandleAccessMtx) == 0)
+ lock = pthread_mutex_lock(&gKeyAPIHandleAccessMtx);
+ if(lock == 0)
{
//DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleRegisterNotifyOnChange: "),
// DLT_INT(gKeyHandleArray[key_handle].info.context.ldbid), DLT_STRING(gKeyHandleArray[key_handle].resourceID) );
@@ -290,21 +320,36 @@ int pclKeyHandleRegisterNotifyOnChange(int key_handle, pclChangeNotifyCallback_t
}
pthread_mutex_unlock(&gKeyAPIHandleAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleReadData - mutex lock failed:"), DLT_INT(lock));
+ }
+
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- pclKeyHandleRegisterNotifyOnChange - key_handle:"), DLT_INT(key_handle));
+
return rval;
}
int pclKeyHandleUnRegisterNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback)
{
int rval = EPERS_NOT_INITIALIZED;
+ int lock = 0;
DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyHandleUnRegisterNotifyOnChange - key_handle:"), DLT_INT(key_handle));
- if(pthread_mutex_lock(&gKeyAPIHandleAccessMtx) == 0)
+ lock = pthread_mutex_lock(&gKeyAPIHandleAccessMtx);
+ if(lock == 0)
{
rval = handleRegNotifyOnChange(key_handle, callback, Notify_unregister);
pthread_mutex_unlock(&gKeyAPIHandleAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleUnRegisterNotifyOnChange - mutex lock failed:"), DLT_INT(lock));
+ }
+
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- pclKeyHandleUnRegisterNotifyOnChange - key_handle:"), DLT_INT(key_handle));
return rval;
}
@@ -343,6 +388,9 @@ int handleRegNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback,
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("handleRegNotifyOnChange - not initialized"));
}
+
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- handleRegNotifyOnChange - key_handle:"), DLT_INT(key_handle));
+
return rval;
}
@@ -356,7 +404,8 @@ int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size
if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0)
{
- if(pthread_mutex_lock(&gKeyAPIHandleAccessMtx) == 0)
+ int lock = pthread_mutex_lock(&gKeyAPIHandleAccessMtx);
+ if(lock == 0)
{
#if USE_APPCHECK
if(doAppcheck() == 1)
@@ -389,12 +438,18 @@ int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size
#endif
pthread_mutex_unlock(&gKeyAPIHandleAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyHandleWriteData - mutex lock failed:"), DLT_INT(lock));
+ }
}
else
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclKeyHandleWriteData - not initialized"));
}
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- pclKeyHandleWriteData - key_handle:"), DLT_INT(key_handle));
+
return size;
}
@@ -416,7 +471,8 @@ int pclKeyDelete(unsigned int ldbid, const char* resource_id, unsigned int user_
if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0)
{
- if(pthread_mutex_lock(&gKeyAPIAccessMtx) == 0)
+ int lock = pthread_mutex_lock(&gKeyAPIAccessMtx);
+ if(lock == 0)
{
#if USE_APPCHECK
if(doAppcheck() == 1)
@@ -461,12 +517,18 @@ int pclKeyDelete(unsigned int ldbid, const char* resource_id, unsigned int user_
#endif
pthread_mutex_unlock(&gKeyAPIAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyDelete - mutex lock failed:"), DLT_INT(lock));
+ }
}
else
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclKeyDelete - not initialized"));
}
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- pclKeyDelete - ldbid:"), DLT_UINT(ldbid), DLT_STRING(" res: "),DLT_STRING(resource_id));
+
return rval;
}
@@ -480,7 +542,8 @@ int pclKeyGetSize(unsigned int ldbid, const char* resource_id, unsigned int user
if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0)
{
- if(pthread_mutex_lock(&gKeyAPIAccessMtx) == 0)
+ int lock = pthread_mutex_lock(&gKeyAPIAccessMtx);
+ if(lock == 0)
{
#if USE_APPCHECK
if(doAppcheck() == 1)
@@ -522,12 +585,18 @@ int pclKeyGetSize(unsigned int ldbid, const char* resource_id, unsigned int user
#endif
pthread_mutex_unlock(&gKeyAPIAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyGetSize - mutex lock failed:"), DLT_INT(lock));
+ }
}
else
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclKeyGetSize - not initialized"));
}
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- pclKeyGetSize - ldbid:"), DLT_UINT(ldbid), DLT_STRING(" res: "),DLT_STRING(resource_id));
+
return data_size;
}
@@ -542,7 +611,8 @@ int pclKeyReadData(unsigned int ldbid, const char* resource_id, unsigned int use
if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0)
{
- if(pthread_mutex_lock(&gKeyAPIAccessMtx) == 0)
+ int lock = pthread_mutex_lock(&gKeyAPIAccessMtx);
+ if(lock == 0)
{
#if USE_APPCHECK
if(doAppcheck() == 1)
@@ -592,12 +662,18 @@ int pclKeyReadData(unsigned int ldbid, const char* resource_id, unsigned int use
#endif
pthread_mutex_unlock(&gKeyAPIAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyGetSize - mutex lock failed:"), DLT_INT(lock));
+ }
}
else
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("keyReadData - not initialized"));
}
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- pclKeyReadData - ldbid:"), DLT_UINT(ldbid), DLT_STRING(" res: "),DLT_STRING(resource_id));
+
return data_size;
}
@@ -612,9 +688,9 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us
if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0)
{
- if(pthread_mutex_lock(&gKeyAPIAccessMtx) == 0)
+ int lock = pthread_mutex_lock(&gKeyAPIAccessMtx);
+ if(lock == 0)
{
-
#if USE_APPCHECK
if(doAppcheck() == 1)
{
@@ -686,11 +762,18 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us
#endif
pthread_mutex_unlock(&gKeyAPIAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyWriteData - mutex lock failed:"), DLT_INT(lock));
+ }
}
else
{
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclKeyWriteData - not initialized"));
}
+
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- pclKeyWriteData - ldbid:"), DLT_UINT(ldbid), DLT_STRING(" res: "),DLT_STRING(resource_id));
+
return data_size;
}
@@ -699,15 +782,22 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us
int pclKeyUnRegisterNotifyOnChange( unsigned int ldbid, const char * resource_id, unsigned int user_no, unsigned int seat_no, pclChangeNotifyCallback_t callback)
{
int rval = EPERS_NOT_INITIALIZED;
-
+ int lock = 0;
DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyUnRegisterNotifyOnChange - ldbid:"), DLT_UINT(ldbid), DLT_STRING(" res: "),DLT_STRING(resource_id));
- if(pthread_mutex_lock(&gKeyAPIAccessMtx) == 0)
+ lock = pthread_mutex_lock(&gKeyAPIAccessMtx);
+ if(lock == 0)
{
rval = regNotifyOnChange(ldbid, resource_id, user_no, seat_no, callback, Notify_unregister);
pthread_mutex_unlock(&gKeyAPIAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyUnRegisterNotifyOnChange - mutex lock failed:"), DLT_INT(lock));
+ }
+
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- pclKeyUnRegisterNotifyOnChange - ldbid:"), DLT_UINT(ldbid), DLT_STRING(" res: "),DLT_STRING(resource_id));
return rval;
}
@@ -716,10 +806,12 @@ int pclKeyUnRegisterNotifyOnChange( unsigned int ldbid, const char * resource_
int pclKeyRegisterNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int user_no, unsigned int seat_no, pclChangeNotifyCallback_t callback)
{
int rval = EPERS_COMMON;
+ int lock = 0;
DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclKeyRegisterNotifyOnChange - ldbid:"), DLT_UINT(ldbid), DLT_STRING(" res: "), DLT_STRING(resource_id) );
- if(pthread_mutex_lock(&gKeyAPIAccessMtx) == 0)
+ lock = pthread_mutex_lock(&gKeyAPIAccessMtx);
+ if(lock == 0)
{
if((gChangeNotifyCallback == callback) || (gChangeNotifyCallback == NULL))
{
@@ -727,11 +819,18 @@ int pclKeyRegisterNotifyOnChange(unsigned int ldbid, const char* resource_id, un
}
else
{
- DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("keyRegNotifyOnChange - Only one cBack is allowed for ch noti."));
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyRegisterNotifyOnChange - Only one cBack is allowed for ch noti."));
rval = EPERS_NOTIFY_NOT_ALLOWED;
}
pthread_mutex_unlock(&gKeyAPIAccessMtx);
}
+ else
+ {
+ DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclKeyRegisterNotifyOnChange - mutex lock failed:"), DLT_INT(lock));
+ }
+
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("<- pclKeyRegisterNotifyOnChange - ldbid:"), DLT_UINT(ldbid), DLT_STRING(" res: "), DLT_STRING(resource_id) );
+
return rval;
}
@@ -796,5 +895,7 @@ int regNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int
DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("regNotifyOnChange - not initialized"));
}
+ //DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("regNotifyOnChange - ldbid:"), DLT_UINT(ldbid), DLT_STRING(" res: "), DLT_STRING(resource_id) );
+
return rval;
}
diff --git a/src/persistence_client_library_lc_interface.c b/src/persistence_client_library_lc_interface.c
index 06fae6a..af9ddfa 100644
--- a/src/persistence_client_library_lc_interface.c
+++ b/src/persistence_client_library_lc_interface.c
@@ -34,10 +34,12 @@ int check_lc_request(unsigned int request, unsigned int requestID)
case NsmShutdownNormal:
{
MainLoopData_u data;
- data.message.cmd = (uint32_t)CMD_LC_PREPARE_SHUTDOWN;
- data.message.params[0] = request;
- data.message.params[1] = requestID;
- data.message.string[0] = '\0'; // no string parameter, set to 0
+
+ memset(&data, 0, sizeof(MainLoopData_u));
+ data.cmd = (uint32_t)CMD_LC_PREPARE_SHUTDOWN;
+ data.params[0] = request;
+ data.params[1] = requestID;
+ data.string[0] = '\0'; // no string parameter, set to 0
if(-1 == deliverToMainloop_NM(&data) )
{
@@ -144,10 +146,11 @@ int register_lifecycle(int shutdownMode)
{
MainLoopData_u data;
- data.message.cmd = (uint32_t)CMD_SEND_LC_REGISTER;
- data.message.params[0] = 1;
- data.message.params[1] = (uint32_t)shutdownMode;
- data.message.string[0] = '\0'; // no string parameter, set to 0
+ memset(&data, 0, sizeof(MainLoopData_u));
+ data.cmd = (uint32_t)CMD_SEND_LC_REGISTER;
+ data.params[0] = 1;
+ data.params[1] = (uint32_t)shutdownMode;
+ data.string[0] = '\0'; // no string parameter, set to 0
return deliverToMainloop(&data);
}
@@ -158,10 +161,11 @@ int unregister_lifecycle(int shutdownMode)
{
MainLoopData_u data;
- data.message.cmd = (uint32_t)CMD_SEND_LC_REGISTER;
- data.message.params[0] = 0;
- data.message.params[1] = (uint32_t)shutdownMode;
- data.message.string[0] = '\0'; // no string parameter, set to 0
+ memset(&data, 0, sizeof(MainLoopData_u));
+ data.cmd = (uint32_t)CMD_SEND_LC_REGISTER;
+ data.params[0] = 0;
+ data.params[1] = (uint32_t)shutdownMode;
+ data.string[0] = '\0'; // no string parameter, set to 0
return deliverToMainloop(&data);
}
diff --git a/src/persistence_client_library_pas_interface.c b/src/persistence_client_library_pas_interface.c
index a24d7cf..2e41bc7 100644
--- a/src/persistence_client_library_pas_interface.c
+++ b/src/persistence_client_library_pas_interface.c
@@ -58,10 +58,11 @@ int check_pas_request(unsigned int request, unsigned int requestID)
{
MainLoopData_u data;
- data.message.cmd = (uint32_t)CMD_PAS_BLOCK_AND_WRITE_BACK;
- data.message.params[0] = request;
- data.message.params[1] = requestID;
- data.message.string[0] = '\0'; // no string parameter, set to 0
+ memset(&data, 0, sizeof(MainLoopData_u));
+ data.cmd = (uint32_t)CMD_PAS_BLOCK_AND_WRITE_BACK;
+ data.params[0] = request;
+ data.params[1] = requestID;
+ data.string[0] = '\0'; // no string parameter, set to 0
DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("chkPasReq - case PasMsg_Block o. PasMsg_WriteBack"));
if(-1 == deliverToMainloop_NM(&data))
@@ -182,10 +183,11 @@ int register_pers_admin_service(void)
MainLoopData_u data;
- data.message.cmd = (uint32_t)CMD_SEND_PAS_REGISTER;
- data.message.params[0] = 1;
- data.message.params[1] = (PasMsg_Block | PasMsg_WriteBack | PasMsg_Unblock);
- data.message.string[0] = '\0'; // no string parameter, set to 0
+ memset(&data, 0, sizeof(MainLoopData_u));
+ data.cmd = (uint32_t)CMD_SEND_PAS_REGISTER;
+ data.params[0] = 1;
+ data.params[1] = (PasMsg_Block | PasMsg_WriteBack | PasMsg_Unblock);
+ data.string[0] = '\0'; // no string parameter, set to 0
if(-1 == deliverToMainloop(&data))
{
@@ -207,10 +209,12 @@ int unregister_pers_admin_service(void)
int rval = 0;
MainLoopData_u data;
- data.message.cmd = (uint32_t)CMD_SEND_PAS_REGISTER;
- data.message.params[0] = 0;
- data.message.params[1] = (PasMsg_Block | PasMsg_WriteBack | PasMsg_Unblock);
- data.message.string[0] = '\0'; // no string parameter, set to 0
+
+ memset(&data, 0, sizeof(MainLoopData_u));
+ data.cmd = (uint32_t)CMD_SEND_PAS_REGISTER;
+ data.params[0] = 0;
+ data.params[1] = (PasMsg_Block | PasMsg_WriteBack | PasMsg_Unblock);
+ data.string[0] = '\0'; // no string parameter, set to 0
if(-1 == deliverToMainloop(&data))
{
diff --git a/test/data/PAS_data.tar.gz b/test/data/PAS_data.tar.gz
index 99e863b..16a291b 100644
--- a/test/data/PAS_data.tar.gz
+++ b/test/data/PAS_data.tar.gz
Binary files differ
diff --git a/test/persistence_client_library_test.c b/test/persistence_client_library_test.c
index 146e41a..ebcf54b 100644
--- a/test/persistence_client_library_test.c
+++ b/test/persistence_client_library_test.c
@@ -742,11 +742,14 @@ END_TEST
START_TEST(test_InitDeinit)
{
- int i = 0, rval = -1, handle = 0;
int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
+ int i = 0, rval = -1, handle = 0;
+
+
DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("PCL_TEST test_InitDeinit"));
+
for(i=0; i<5; i++)
{
// initialize and deinitialize 1. time
@@ -1591,7 +1594,6 @@ static Suite * persistencyClientLib_suite()
tcase_add_test(tc_MultiThreadedWrite, test_MultiThreadedWrite);
tcase_set_timeout(tc_MultiThreadedWrite, 20);
-
suite_add_tcase(s, tc_persSetData);
tcase_add_checked_fixture(tc_persSetData, data_setup, data_teardown);
@@ -1641,24 +1643,27 @@ static Suite * persistencyClientLib_suite()
suite_add_tcase(s, tc_InvalidPluginfConf);
- suite_add_tcase(s, tc_InitDeinit);
-
- //suite_add_tcase(s, tc_NoPluginFunc);
-
- // suite_add_tcase(s, tc_SharedData);
- // tcase_add_checked_fixture(tc_SharedData, data_setup, data_teardown);
-
suite_add_tcase(s, tc_MultiThreadedRead);
tcase_add_checked_fixture(tc_MultiThreadedRead, data_setup, data_teardown);
suite_add_tcase(s, tc_MultiThreadedWrite);
tcase_add_checked_fixture(tc_MultiThreadedWrite, data_setup, data_teardown);
+ suite_add_tcase(s, tc_NoRct);
+ tcase_add_checked_fixture(tc_NoRct, data_setup_norct, data_teardown);
+
+ suite_add_tcase(s, tc_InitDeinit);
+
+ //suite_add_tcase(s, tc_NoPluginFunc);
+
+ //suite_add_tcase(s, tc_SharedData);
+ //tcase_add_checked_fixture(tc_SharedData, data_setup, data_teardown);
+
+
#if USE_APPCHECK
suite_add_tcase(s, tc_ValidApplication);
#else
- suite_add_tcase(s, tc_NoRct);
- tcase_add_checked_fixture(tc_NoRct, data_setup_norct, data_teardown);
+
#endif
#if 0
@@ -1685,7 +1690,7 @@ int main(int argc, char *argv[])
gTheAppId[MaxAppNameLen-1] = '\0';
/// debug log and trace (DLT) setup
- DLT_REGISTER_APP("PCLT", "PCL test");
+ DLT_REGISTER_APP("PCLTk", "PCL test");
DLT_REGISTER_CONTEXT(gPcltDLTContext, "PCLt", "Context for PCL testing");
diff --git a/test/persistence_client_library_test_file.c b/test/persistence_client_library_test_file.c
index 3e3fffd..5d96696 100644
--- a/test/persistence_client_library_test_file.c
+++ b/test/persistence_client_library_test_file.c
@@ -28,6 +28,7 @@
#include <dlt.h>
#include <dlt_common.h>
#include <pthread.h>
+#include <string.h>
#include <check.h>
@@ -40,8 +41,8 @@
#define READ_SIZE 1024
#define MaxAppNameLen 256
-#define NUM_THREADS 100
-#define NUM_OF_WRITES 350
+#define NUM_THREADS 10
+#define NUM_OF_WRITES 500
#define NAME_LEN 24
typedef struct s_threadData
@@ -477,81 +478,146 @@ END_TEST
*/
START_TEST(test_DataHandle)
{
- int handle1 = 0, handle2 = 0;
- int handleArray[4] = {0};
- int ret = 0;
+ int handleArray[1024] = {0};
unsigned char buffer[READ_SIZE] = {0};
+ {
+ int ret = 0;
+ int handle1 = 0, handle2 = 0;
+
+ // test multiple handles
+ handleArray[0] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_01.db", 1, 1);
+ fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_01.db");
+
+ handleArray[1] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_02.db", 1, 1);
+ fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_02.db");
+
+ handleArray[2] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_03.db", 1, 1);
+ fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_03.db");
+
+ handleArray[3] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_04.db", 1, 1);
+ fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_04.db");
+
+ memset(buffer, 0, READ_SIZE);
+ ret = pclFileReadData(handleArray[0], buffer, READ_SIZE);
+ fail_unless(ret >= 0, "Failed to read handle idx \"0\"!!");
+ fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_01.db",
+ strlen("/user/1/seat/1/media/mediaDB_write_01.db"))
+ == 0, "Buffer not correctly read => mediaDB_write_01.db");
- // test multiple handles
- handleArray[0] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_01.db", 1, 1);
- fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_01.db");
+ memset(buffer, 0, READ_SIZE);
+ ret = pclFileReadData(handleArray[1], buffer, READ_SIZE);
+ fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_02.db",
+ strlen("/user/1/seat/1/media/mediaDB_write_02.db"))
+ == 0, "Buffer not correctly read => mediaDB_write_02.db");
- handleArray[1] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_02.db", 1, 1);
- fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_02.db");
+ memset(buffer, 0, READ_SIZE);
+ ret = pclFileReadData(handleArray[2], buffer, READ_SIZE);
+ fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_03.db",
+ strlen("/user/1/seat/1/media/mediaDB_write_03.db"))
+ == 0, "Buffer not correctly read => mediaDB_write_03.db");
- handleArray[2] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_03.db", 1, 1);
- fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_03.db");
+ memset(buffer, 0, READ_SIZE);
+ (void)pclFileReadData(handleArray[3], buffer, READ_SIZE);
+ fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_04.db",
+ strlen("/user/1/seat/1/media/mediaDB_write_04.db"))
+ == 0, "Buffer not correctly read => mediaDB_write_04.db");
- handleArray[3] = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB_write_04.db", 1, 1);
- fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB_write_04.db");
+ ret = pclKeyHandleClose(handleArray[0]);
+ fail_unless(ret != -1, "Failed to close handle idx \"0\"!!");
- memset(buffer, 0, READ_SIZE);
- ret = pclFileReadData(handleArray[0], buffer, READ_SIZE);
- fail_unless(ret >= 0, "Failed to read handle idx \"0\"!!");
- fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_01.db",
- strlen("/user/1/seat/1/media/mediaDB_write_01.db"))
- == 0, "Buffer not correctly read => mediaDB_write_01.db");
+ ret = pclKeyHandleClose(handleArray[1]);
+ fail_unless(ret != -1, "Failed to close handle idx \"1\"!!");
- memset(buffer, 0, READ_SIZE);
- ret = pclFileReadData(handleArray[1], buffer, READ_SIZE);
- fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_02.db",
- strlen("/user/1/seat/1/media/mediaDB_write_02.db"))
- == 0, "Buffer not correctly read => mediaDB_write_02.db");
+ ret = pclKeyHandleClose(handleArray[2]);
+ fail_unless(ret != -1, "Failed to close handle idx \"2\"!!");
- memset(buffer, 0, READ_SIZE);
- ret = pclFileReadData(handleArray[2], buffer, READ_SIZE);
- fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_03.db",
- strlen("/user/1/seat/1/media/mediaDB_write_03.db"))
- == 0, "Buffer not correctly read => mediaDB_write_03.db");
+ ret = pclKeyHandleClose(handleArray[3]);
+ fail_unless(ret != -1, "Failed to close handle idx \"3\"!!");
- memset(buffer, 0, READ_SIZE);
- (void)pclFileReadData(handleArray[3], buffer, READ_SIZE);
- fail_unless(strncmp((char*)buffer, "/user/1/seat/1/media/mediaDB_write_04.db",
- strlen("/user/1/seat/1/media/mediaDB_write_04.db"))
- == 0, "Buffer not correctly read => mediaDB_write_04.db");
+ // test key handles
+ handle2 = pclKeyHandleOpen(PCL_LDBID_LOCAL, "statusHandle/open_document", 3, 2);
+ fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document");
- ret = pclKeyHandleClose(handleArray[0]);
- fail_unless(ret != -1, "Failed to close handle idx \"0\"!!");
+ ret = pclKeyHandleClose(handle2);
+ fail_unless(ret != -1, "Failed to close handle!!");
- ret = pclKeyHandleClose(handleArray[1]);
- fail_unless(ret != -1, "Failed to close handle idx \"1\"!!");
+ ret = pclKeyHandleClose(1024);
+ fail_unless(ret == EPERS_MAXHANDLE, "Max handle!!");
- ret = pclKeyHandleClose(handleArray[2]);
- fail_unless(ret != -1, "Failed to close handle idx \"2\"!!");
- ret = pclKeyHandleClose(handleArray[3]);
- fail_unless(ret != -1, "Failed to close handle idx \"3\"!!");
+ // test file handles
+ handle1 = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB.db", 1, 1);
+ fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB.db");
- // test key handles
- handle2 = pclKeyHandleOpen(PCL_LDBID_LOCAL, "statusHandle/open_document", 3, 2);
- fail_unless(handle2 >= 0, "Failed to open handle /statusHandle/open_document");
+ ret = pclFileClose(handle1);
+ fail_unless(handle1 != -1, "Could not closefile ==> /media/mediaDB.db");
- ret = pclKeyHandleClose(handle2);
- fail_unless(ret != -1, "Failed to close handle!!");
+ ret = pclFileClose(1024);
+ fail_unless(ret == EPERS_MAXHANDLE, "1. Could close file, but should not!!");
+ }
+
+ {
+ char writeBuffer[256] = {0};
+ char fileNameBuf[1024] = {0};
+ int i = 0, size = 0;
+
+ memset(handleArray, -1, 1024);
- ret = pclKeyHandleClose(1024);
- fail_unless(ret == EPERS_MAXHANDLE, "Max handle!!");
+ for(i=0; i<1024; i++)
+ {
+ memset(fileNameBuf,0,1024);
+ snprintf(fileNameBuf, 1024, "media/threeAnotherFileTestData.db_%d", i);
+ //printf("\n\nOpen - %d\n", i);
+ handleArray[i] = pclFileOpen(PCL_LDBID_LOCAL, fileNameBuf, 4, 12);
+ }
+ // now write data
+ for(i=0; i<1024; i++)
+ {
+ if(handleArray[i] >=0 )
+ {
+ memset(writeBuffer,0,256);
+ snprintf(writeBuffer, 256, "START_TEST(test_DataHandle)_media/some_test_data_to_show_read and write is working_%d", i);
- // test file handles
- handle1 = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDB.db", 1, 1);
- fail_unless(handle1 != -1, "Could not open file ==> /media/mediaDB.db");
+ pclFileSeek(handleArray[i], 0, SEEK_SET);
+ size = pclFileWriteData(handleArray[i], writeBuffer, (int)strlen(writeBuffer));
+ fail_unless(size == (int)strlen(writeBuffer), "Wrong size written - %d", i);
+ }
- ret = pclFileClose(handle1);
- fail_unless(handle1 != -1, "Could not closefile ==> /media/mediaDB.db");
+ }
+
+ // now read data
+ for(i=0; i<1024; i++)
+ {
+ if(handleArray[i] >=0 )
+ {
+ memset(buffer, 0, READ_SIZE);
+ memset(writeBuffer,0, 256);
+ snprintf(writeBuffer, 256, "START_TEST(test_DataHandle)_media/some_test_data_to_show_read and write is working_%d", i);
+ pclFileSeek(handleArray[i], 0, SEEK_SET);
+ size = pclFileReadData(handleArray[i], buffer, READ_SIZE);
+#if 0
+ if(strncmp((const char*)buffer, (const char*)writeBuffer, 256) != 0)
+ {
+ printf("ERROR Read: \"%s\" - \"%s\"\n", buffer, writeBuffer);
+ }
+ else
+ {
+ printf("ERROR Read: \"%s\" - \"%s\"\n", buffer, writeBuffer);
+ }
+#endif
+ fail_unless(strncmp((const char*)buffer, (const char*)writeBuffer, 256) == 0);
+ }
+ }
+
+ // now close data
+ for(i=0; i<1024; i++)
+ {
+ if(handleArray[i] >=0 )
+ (void)pclFileClose(handleArray[i]);
+ }
+ }
- ret = pclFileClose(1024);
- fail_unless(ret == EPERS_MAXHANDLE, "1. Could close file, but should not!!");
}
END_TEST
@@ -793,47 +859,74 @@ void* fileWriteThread(void* userData)
{
t_threadData* threadData = (t_threadData*)userData;
- static int i = 0;
+ int i = 0;
size_t bufferSize = strlen(gWriteBuffer);
size_t bufferSize2 = strlen(gWriteBuffer2);
unsigned char* readbuffer = malloc(bufferSize);
unsigned char* readbuffer2 = malloc(bufferSize2);
+ unsigned char* keyBuffer = malloc(1024);
- if(readbuffer != NULL && readbuffer2 != NULL)
+ if(readbuffer != NULL && readbuffer2 != NULL && keyBuffer != NULL)
{
+ //printf("\"%s\"\n", threadData->threadName);
pthread_barrier_wait(&gBarrierOne);
usleep(5000);
+ printf("\"%s\" r u n \n", threadData->threadName);
for(i=0; i<NUM_OF_WRITES; i++)
{
- int wsize = 0, rsize = 0;
+ int wsize = 0, rsize = 0, ret = 0;
int wsize2 = 0, rsize2 = 0;
- memset(readbuffer, 0, bufferSize);
-
wsize = pclFileWriteData(threadData->fd1, gWriteBuffer, (int)bufferSize);
ck_assert_int_ge(wsize, 0);
pclFileSeek(threadData->fd1, 0, SEEK_SET);
- rsize = pclFileReadData(threadData->fd1, readbuffer, (int)bufferSize);
- ck_assert_int_eq(rsize, (int)bufferSize);
-
- usleep( (useconds_t)(50 * i * threadData->index)); // do some "random" sleep
+ ret = pclKeyWriteData(PCL_LDBID_LOCAL, "status/open_document", 3, 2, (unsigned char*)"WT_ /var/opt/user_manual_climateControl.pdf", strlen("WT_ /var/opt/user_manual_climateControl.pdf"));
+ fail_unless(ret == strlen("WT_ /var/opt/user_manual_climateControl.pdf"), "Wrong write size");
- memset(readbuffer2, 0, bufferSize2);
+ usleep( (useconds_t)(100 * i * threadData->index)); // do some "random" sleep
wsize2 = pclFileWriteData(threadData->fd2, gWriteBuffer2, (int)bufferSize2);
ck_assert_int_ge(wsize2, 0);
pclFileSeek(threadData->fd2, 0, SEEK_SET);
+
+ memset(readbuffer, 0, bufferSize);
+ rsize = pclFileReadData(threadData->fd1, readbuffer, (int)bufferSize);
+ ck_assert_int_eq(rsize, (int)bufferSize);
+
+ memset(keyBuffer, 0, 1024);
+ ret = pclKeyReadData(PCL_LDBID_LOCAL, "pos/last_position", 1, 1, keyBuffer, 1024);
+ ck_assert_str_eq( (char*)keyBuffer, "CACHE_ +48 10' 38.95, +8 44' 39.06");
+ ck_assert_int_eq( ret, (int)strlen("CACHE_ +48 10' 38.95, +8 44' 39.06") );
+
+ memset(readbuffer2, 0, bufferSize2);
rsize2 = pclFileReadData(threadData->fd2, readbuffer2, (int)bufferSize2);
ck_assert_int_eq(rsize2, (int)bufferSize2);
+
+ memset(keyBuffer, 0, 1024);
+ ret = pclKeyReadData(0x20, "address/home_address", 4, 0, keyBuffer, READ_SIZE);
+ ck_assert_str_eq( (char*)keyBuffer, "WT_ 55327 Heimatstadt, Wohnstrasse 31");
+ ck_assert_int_eq(ret, (int)strlen("WT_ 55327 Heimatstadt, Wohnstrasse 31"));
+
+ usleep(75000);
+
+ printf("\"%s\" %d\n", threadData->threadName, i);
}
- free(readbuffer);
- free(readbuffer2);
+ printf("\"%s\" e n d \n", threadData->threadName);
+
+ if(keyBuffer != 0)
+ free(keyBuffer);
+
+ if(readbuffer != 0)
+ free(readbuffer);
+
+ if(readbuffer2 != 0)
+ free(readbuffer2);
}
return NULL;
@@ -844,6 +937,11 @@ START_TEST(test_MultFileReadWrite)
{
int fd1 = -1;
int fd2 = -1;
+ int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
+
+
+ (void)pclInitLibrary(gTheAppId, shutdownReg);
+
fd1 = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDBWrite.db", 1, 1);
fd2 = pclFileOpen(PCL_LDBID_LOCAL, "media/mediaDBWrite.db", 2, 1);
@@ -895,6 +993,9 @@ START_TEST(test_MultFileReadWrite)
{
printf("Could not open file ==> /media/mediaDBWrite.db\n");
}
+
+
+ pclDeinitLibrary();
}
END_TEST
@@ -949,44 +1050,467 @@ static Suite * persistencyClientLib_suite()
TCase * tc_MultiFileReadWrite = tcase_create("MultFileReadWrite");
tcase_add_test(tc_MultiFileReadWrite, test_MultFileReadWrite);
- tcase_set_timeout(tc_MultiFileReadWrite, 20);
-
+ tcase_set_timeout(tc_MultiFileReadWrite, 200000);
- suite_add_tcase(s, tc_WriteConfDefault);
- tcase_add_checked_fixture(tc_WriteConfDefault, data_setup, data_teardown);
+#if 1
suite_add_tcase(s, tc_persDataFile);
tcase_add_checked_fixture(tc_persDataFile, data_setup, data_teardown);
+ suite_add_tcase(s, tc_WriteConfDefault);
+ tcase_add_checked_fixture(tc_WriteConfDefault, data_setup, data_teardown);
+
suite_add_tcase(s, tc_persDataFileBackupCreation);
- tcase_add_checked_fixture(tc_persDataFileBackupCreation, data_setupBackup, data_teardown);
+ tcase_add_checked_fixture(tc_persDataFileBackupCreation, data_setupBackup, data_teardown);
+
+ suite_add_tcase(s, tc_persDataFileRecovery);
+ tcase_add_checked_fixture(tc_persDataFileRecovery, data_setupRecovery, data_teardown);
+
+ suite_add_tcase(s, tc_GetPath);
+ tcase_add_checked_fixture(tc_GetPath, data_setup, data_teardown);
+
+ suite_add_tcase(s, tc_VerifyROnly);
+ tcase_add_checked_fixture(tc_VerifyROnly, data_setup, data_teardown);
- suite_add_tcase(s, tc_persDataFileRecovery);
- tcase_add_checked_fixture(tc_persDataFileRecovery, data_setupRecovery, data_teardown);
+ suite_add_tcase(s, tc_DataFileConfDefault);
+ tcase_add_checked_fixture(tc_DataFileConfDefault, data_setup, data_teardown);
- suite_add_tcase(s, tc_GetPath);
- tcase_add_checked_fixture(tc_GetPath, data_setup, data_teardown);
+ suite_add_tcase(s, tc_FileTest);
+ tcase_add_checked_fixture(tc_FileTest, data_setup_browser, data_teardown);
- suite_add_tcase(s, tc_VerifyROnly);
- tcase_add_checked_fixture(tc_VerifyROnly, data_setup, data_teardown);
+ suite_add_tcase(s, tc_InitDeinit);
- suite_add_tcase(s, tc_DataFileConfDefault);
- tcase_add_checked_fixture(tc_DataFileConfDefault, data_setup, data_teardown);
+ suite_add_tcase(s, tc_DataHandle);
+ tcase_add_checked_fixture(tc_DataHandle, data_setup, data_teardown);
- suite_add_tcase(s, tc_FileTest);
- tcase_add_checked_fixture(tc_FileTest, data_setup_browser, data_teardown);
- suite_add_tcase(s, tc_InitDeinit);
+#else
+
+
+ //suite_add_tcase(s, tc_MultiFileReadWrite);
+ //tcase_add_checked_fixture(tc_MultiFileReadWrite, data_setup, data_teardown);
+#endif
- suite_add_tcase(s, tc_DataHandle);
- tcase_add_checked_fixture(tc_DataHandle, data_setup, data_teardown);
- suite_add_tcase(s, tc_MultiFileReadWrite);
- tcase_add_checked_fixture(tc_MultiFileReadWrite, data_setup, data_teardown);
return s;
}
+#define NUM_OF_OPEN_FILES 200
+
+void* WriteOneThread(void* userData)
+{
+ int fd1 = -1, fd2 = -1, i = 0, j = 0;
+ int size1 = 0, size2 = 0;
+ int ret = 0;
+ unsigned char keyBuffer[1024] = {0};
+ int fda[NUM_OF_OPEN_FILES] = {0};
+ char fileBuffer[1024] = {0};
+ char writeBuffer[128] = {0};
+
+ int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
+
+ (void)pclInitLibrary(gTheAppId, shutdownReg);
+
+ printf("Thread: %s\n", (const char*)userData);
+
+ size_t bufferSize = strlen(gWriteBuffer);
+ size_t bufferSize2 = strlen(gWriteBuffer2);
+
+ unsigned char* readbuffer = malloc(bufferSize);
+ unsigned char* readbuffer2 = malloc(bufferSize2);
+
+
+ fd1 = pclFileOpen(PCL_LDBID_LOCAL, "media/oneSomeFileTestData.db", 1, 1);
+ printf("fd1: %d\n", fd1);
+
+ fd2 = pclFileOpen(PCL_LDBID_LOCAL, "media/oneAnotherFileTestData.db", 2, 1);
+ printf("fd2: %d\n", fd2);
+
+ for(i=0; i<NUM_OF_OPEN_FILES; i++)
+ {
+ memset(fileBuffer,0,1024);
+ snprintf(fileBuffer, 1024, "media/oneAnotherFileTestData.db_%d", i);
+ printf("One open: %d\n", i);
+ fda[i] = pclFileOpen(PCL_LDBID_LOCAL, fileBuffer, 4, 4);
+ if(fda[i] < 0)
+ {
+ printf("ERROR Invlaid handle: \n");
+ exit(0);
+ }
+ usleep(120000);
+ }
+
+ for(i=0; i< 20000; i++)
+ {
+ printf("loop One: %d\n", i);
+
+ memset(readbuffer, 0, bufferSize);
+ memset(readbuffer2, 0, bufferSize2);
+ memset(keyBuffer, 0, 1024);
+
+ if(i%2)
+ {
+ size1 = pclFileWriteData(fd1, gWriteBuffer2, (int)strlen(gWriteBuffer2));
+ size2 = pclFileWriteData(fd2, gWriteBuffer, (int)strlen(gWriteBuffer));
+
+ size2 = pclFileReadData(fd1, readbuffer2, (int)bufferSize2);
+ size2 = pclFileReadData(fd2, readbuffer, (int)bufferSize);
+
+ printf("Wb\n");
+ for(j=0; j< NUM_OF_OPEN_FILES; j++)
+ {
+ memset(readbuffer, 0, bufferSize);
+ memset(writeBuffer,0,128);
+ snprintf(writeBuffer, 128, "%s_media/oneAnotherFileTestData.db_%d", (const char*)userData, j);
+ pclFileSeek(fda[j], 0, SEEK_SET);
+ size2 = pclFileReadData(fda[j], readbuffer, (int)bufferSize);
+ if(strncmp((const char*)readbuffer, (const char*)writeBuffer, 128) != 0)
+ {
+ printf("ERROR Read: \"%s\" - \"%s\"\n", readbuffer, writeBuffer);
+ pclDeinitLibrary();
+ exit(0);
+ }
+ }
+ }
+ else
+ {
+ size1 = pclFileWriteData(fd1, gWriteBuffer, (int)strlen(gWriteBuffer));
+ size2 = pclFileWriteData(fd2, gWriteBuffer2, (int)strlen(gWriteBuffer2));
+
+ ret = pclKeyReadData(0x20, "address/home_address", 4, 0, keyBuffer, READ_SIZE);
+ if( ret < 0)
+ printf("Failed\n");
+
+ size2 = pclFileReadData(fd1, readbuffer, (int)bufferSize);
+ size2 = pclFileReadData(fd2, readbuffer2, (int)bufferSize2);
+
+ printf("Wa\n");
+ for(j=0; j< NUM_OF_OPEN_FILES; j++)
+ {
+ memset(writeBuffer,0,128);
+ snprintf(writeBuffer, 128, "%s_media/oneAnotherFileTestData.db_%d", (const char*)userData, j);
+ pclFileSeek(fda[j], 0, SEEK_SET);
+ size2 = pclFileWriteData(fda[j], writeBuffer, (int)strlen(writeBuffer));
+ }
+ }
+
+ if(size2 < 0 || size1 < 0)
+ printf("Failed file\n");
+
+ ret = pclKeyWriteData(PCL_LDBID_LOCAL, "status/open_document", 3, 2,
+ (unsigned char*)"WT_ /var/opt/user_manual_climateControl.pdf", strlen("WT_ /var/opt/user_manual_climateControl.pdf"));
+
+ ret = pclKeyReadData(PCL_LDBID_LOCAL, "pos/last_position", 1, 1, keyBuffer, 1024);
+ if( ret < 0)
+ printf("Failed\n");
+
+ if(i%10 == 0)
+ {
+ pclFileSeek(fd1, 0, SEEK_SET);
+ pclFileSeek(fd2, 0, SEEK_SET);
+ }
+
+ memset(keyBuffer, 0, 1024);
+ ret = pclKeyReadData(0x20, "address/home_address", 4, 0, keyBuffer, READ_SIZE);
+ if( ret < 0)
+ printf("Failed\n");
+
+ printf("T1\n");
+
+ usleep(17500);
+ }
+
+ for(i=0; i<NUM_OF_OPEN_FILES; i++)
+ {
+ (void)pclFileClose(fda[i]);
+ }
+
+
+ (void)pclFileClose(fd1);
+ (void)pclFileClose(fd2);
+
+ pclDeinitLibrary();
+
+ return NULL;
+}
+
+void* WriteThreeThread(void* userData)
+{
+ int fd1 = -1, fd2 = -1, i = 0, j = 0;
+ int size1 = 0, size2 = 0;
+ int ret = 0;
+ unsigned char keyBuffer[1024] = {0};
+ int fda[NUM_OF_OPEN_FILES] = {0};
+ char fileBuffer[1024] = {0};
+ char writeBuffer[128] = {0};
+
+ int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
+
+ (void)pclInitLibrary(gTheAppId, shutdownReg);
+
+ printf("Thread: %s\n", (const char*)userData);
+
+ size_t bufferSize = strlen(gWriteBuffer);
+ size_t bufferSize2 = strlen(gWriteBuffer2);
+
+ unsigned char* readbuffer = malloc(bufferSize);
+ unsigned char* readbuffer2 = malloc(bufferSize2);
+
+
+ fd1 = pclFileOpen(PCL_LDBID_LOCAL, "media/oneSomeFileTestData.db", 1, 1);
+ printf("fd1: %d\n", fd1);
+
+ fd2 = pclFileOpen(PCL_LDBID_LOCAL, "media/oneAnotherFileTestData.db", 2, 1);
+ printf("fd2: %d\n", fd2);
+
+ for(i=0; i<NUM_OF_OPEN_FILES; i++)
+ {
+ memset(fileBuffer,0,1024);
+ snprintf(fileBuffer, 1024, "media/threeAnotherFileTestData.db_%d", i);
+ printf("Three open: %d\n", i);
+ fda[i] = pclFileOpen(PCL_LDBID_LOCAL, fileBuffer, 5, 5);
+ if(fda[i] < 0)
+ {
+ printf("ERROR Invlaid handle: \n");
+ pclDeinitLibrary();
+ exit(0);
+ }
+ usleep(120000);
+ }
+
+ for(i=0; i< 20000; i++)
+ {
+ printf("loop Three: %d\n", i);
+
+ memset(readbuffer, 0, bufferSize);
+ memset(readbuffer2, 0, bufferSize2);
+ memset(keyBuffer, 0, 1024);
+
+ if(i%2)
+ {
+ size1 = pclFileWriteData(fd1, gWriteBuffer2, (int)strlen(gWriteBuffer2));
+ size2 = pclFileWriteData(fd2, gWriteBuffer, (int)strlen(gWriteBuffer));
+
+ size2 = pclFileReadData(fd1, readbuffer2, (int)bufferSize2);
+ size2 = pclFileReadData(fd2, readbuffer, (int)bufferSize);
+
+ printf("Wb\n");
+ for(j=0; j< NUM_OF_OPEN_FILES; j++)
+ {
+ memset(readbuffer, 0, bufferSize);
+ memset(writeBuffer,0,128);
+ snprintf(writeBuffer, 128, "%s_media/oneAnotherFileTestData.db_%d", (const char*)userData, j);
+ pclFileSeek(fda[j], 0, SEEK_SET);
+ size2 = pclFileReadData(fda[j], readbuffer, (int)bufferSize);
+ if(strncmp((const char*)readbuffer, (const char*)writeBuffer, 128) != 0)
+ {
+ printf("ERROR Read: \"%s\" - \"%s\"\n", readbuffer, writeBuffer);
+ exit(0);
+ }
+ }
+ }
+ else
+ {
+ size1 = pclFileWriteData(fd1, gWriteBuffer, (int)strlen(gWriteBuffer));
+ size2 = pclFileWriteData(fd2, gWriteBuffer2, (int)strlen(gWriteBuffer2));
+
+ ret = pclKeyReadData(0x20, "address/home_address", 4, 0, keyBuffer, READ_SIZE);
+ if( ret < 0)
+ printf("Failed\n");
+
+
+ size2 = pclFileReadData(fd1, readbuffer, (int)bufferSize);
+ size2 = pclFileReadData(fd2, readbuffer2, (int)bufferSize2);
+
+ printf("Wa\n");
+ for(j=0; j< NUM_OF_OPEN_FILES; j++)
+ {
+ memset(writeBuffer,0,128);
+ snprintf(writeBuffer, 128, "%s_media/oneAnotherFileTestData.db_%d", (const char*)userData, j);
+ pclFileSeek(fda[j], 0, SEEK_SET);
+ size2 = pclFileWriteData(fda[j], writeBuffer, (int)strlen(writeBuffer));
+ }
+ }
+
+ if(size2 < 0 || size1 < 0)
+ printf("Failed file\n");
+
+ ret = pclKeyWriteData(PCL_LDBID_LOCAL, "status/open_document", 3, 2,
+ (unsigned char*)"WT_ /var/opt/user_manual_climateControl.pdf", strlen("WT_ /var/opt/user_manual_climateControl.pdf"));
+
+ ret = pclKeyReadData(PCL_LDBID_LOCAL, "pos/last_position", 1, 1, keyBuffer, 1024);
+ if( ret < 0)
+ printf("Failed\n");
+
+ if(i%10 == 0)
+ {
+ //printf(" * One seek *\n");
+ pclFileSeek(fd1, 0, SEEK_SET);
+ pclFileSeek(fd2, 0, SEEK_SET);
+ }
+
+ memset(keyBuffer, 0, 1024);
+ ret = pclKeyReadData(0x20, "address/home_address", 4, 0, keyBuffer, READ_SIZE);
+ if( ret < 0)
+ printf("Failed\n");
+
+ printf("T3\n");
+
+ usleep(17500);
+ }
+
+ for(i=0; i<NUM_OF_OPEN_FILES; i++)
+ {
+ (void)pclFileClose(fda[i]);
+ }
+
+
+ (void)pclFileClose(fd1);
+ (void)pclFileClose(fd2);
+
+ pclDeinitLibrary();
+
+ return NULL;
+}
+
+
+
+void* WriteTwoThread(void* userData)
+{
+ int fd1 = -1, fd2 = -1, i = 0;
+ int size1 = 0, size2 = 0;
+ int ret = 0;
+ unsigned char keyBuffer[1024] = {0};
+
+ int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL;
+
+ (void)pclInitLibrary(gTheAppId, shutdownReg);
+
+ printf("Thread: %s\n", (const char*)userData);
+
+ size_t bufferSize = strlen(gWriteBuffer);
+ size_t bufferSize2 = strlen(gWriteBuffer2);
+
+ unsigned char* readbuffer = malloc(bufferSize);
+ unsigned char* readbuffer2 = malloc(bufferSize2);
+
+
+ fd1 = pclFileOpen(PCL_LDBID_LOCAL, "media/oneSomeFileTestData.db", 1, 1);
+ printf("Two fd1: %d\n", fd1);
+
+ fd2 = pclFileOpen(PCL_LDBID_LOCAL, "media/oneAnotherFileTestData.db", 2, 1);
+ printf("Two fd2: %d\n", fd2);
+
+
+ for(i=0; i< 20000; i++)
+ {
+ memset(readbuffer, 0, bufferSize);
+ memset(readbuffer2, 0, bufferSize2);
+ memset(keyBuffer, 0, 1024);
+
+ printf("loop Two: %d\n", i);
+ if(i%2)
+ {
+ size1 = pclFileWriteData(fd1, gWriteBuffer, (int)strlen(gWriteBuffer));
+ size2 = pclFileWriteData(fd2, gWriteBuffer2, (int)strlen(gWriteBuffer2));
+
+
+ ret = pclKeyReadData(0x20, "address/home_address", 4, 0, keyBuffer, READ_SIZE);
+ if( ret < 0)
+ printf("Failed\n");
+
+ size2 = pclFileReadData(fd1, readbuffer, (int)bufferSize);
+ size2 = pclFileReadData(fd2, readbuffer2, (int)bufferSize2);
+ }
+ else
+ {
+ printf("Two write1\n");
+ size1 = pclFileWriteData(fd1, gWriteBuffer2, (int)strlen(gWriteBuffer2));
+ printf("Two write2\n");
+ size2 = pclFileWriteData(fd2, gWriteBuffer, (int)strlen(gWriteBuffer));
+
+ printf("Two read key\n");
+ ret = pclKeyReadData(0x20, "address/home_address", 4, 0, keyBuffer, READ_SIZE);
+ if( ret < 0)
+ printf("Failed\n");
+
+ size2 = pclFileReadData(fd1, readbuffer2, (int)bufferSize2);
+ size2 = pclFileReadData(fd2, readbuffer, (int)bufferSize);
+ }
+
+ if(size2 < 0 || size1 < 0)
+ printf("Failed file\n");
+
+ ret = pclKeyWriteData(PCL_LDBID_LOCAL, "status/open_document", 3, 2,
+ (unsigned char*)"WT_ /var/opt/user_manual_climateControl.pdf", strlen("WT_ /var/opt/user_manual_climateControl.pdf"));
+
+
+ memset(keyBuffer, 0, 1024);
+ ret = pclKeyReadData(PCL_LDBID_LOCAL, "pos/last_position", 1, 1, keyBuffer, 1024);
+ if( ret < 0)
+ printf("Failed\n");
+
+ //printf("Two - write - %d -- %d - %d \n", i, size1, size2);
+
+ if(i%10 == 0)
+ {
+ //printf(" * Two seek *\n");
+ pclFileSeek(fd1, 0, SEEK_SET);
+ pclFileSeek(fd2, 0, SEEK_SET);
+ }
+
+ printf("T2\n");
+
+ usleep(17500);
+ }
+
+ (void)pclFileClose(fd1);
+ (void)pclFileClose(fd2);
+
+ pclDeinitLibrary();
+
+ return NULL;
+}
+
+
+
+void doEndlessWrite()
+{
+ int* retval;
+ pthread_t one, two, three;
+
+
+ if(pthread_create(&one, NULL, WriteOneThread, "One") != -1)
+ {
+ (void)pthread_setname_np(one, "One");
+ }
+
+ if(pthread_create(&two, NULL, WriteTwoThread, "Two") != -1)
+ {
+ (void)pthread_setname_np(two, "Two");
+ }
+
+ if(pthread_create(&three, NULL, WriteThreeThread, "Three") != -1)
+ {
+ (void)pthread_setname_np(three, "Three");
+ }
+
+ pthread_join(one, (void**)&retval); // wait until thread has ended
+ printf("Thread One joined\n");
+
+ pthread_join(two, (void**)&retval); // wait until thread has ended
+ printf("Thread Two joined\n");
+
+ pthread_join(three, (void**)&retval); // wait until thread has ended
+ printf("Thread One2 joined\n");
+
+ printf("End Test\n");
+
+}
+
+
+
int main(int argc, char *argv[])
{
@@ -999,7 +1523,7 @@ int main(int argc, char *argv[])
gTheAppId[MaxAppNameLen-1] = '\0';
/// debug log and trace (DLT) setup
- DLT_REGISTER_APP("PCLT", "PCL tests");
+ DLT_REGISTER_APP("PCLTf", "PCL tests");
DLT_REGISTER_CONTEXT(gPcltDLTContext, "PCLt", "Context for PCL testing");
@@ -1007,19 +1531,26 @@ int main(int argc, char *argv[])
data_setupBlacklist();
- Suite * s = persistencyClientLib_suite();
- SRunner * sr = srunner_create(s);
- srunner_set_fork_status(sr, CK_NOFORK);
+ if(argc == 1)
+ {
+ Suite * s = persistencyClientLib_suite();
+ SRunner * sr = srunner_create(s);
+ srunner_set_fork_status(sr, CK_NOFORK);
- srunner_set_xml(sr, "/tmp/persistenceClientLibraryTestFile.xml");
- srunner_set_log(sr, "/tmp/persistenceClientLibraryTestFile.log");
+ srunner_set_xml(sr, "/tmp/persistenceClientLibraryTestFile.xml");
+ srunner_set_log(sr, "/tmp/persistenceClientLibraryTestFile.log");
- srunner_run_all(sr, CK_VERBOSE /*CK_NORMAL CK_VERBOSE CK_SUBUNIT*/);
+ srunner_run_all(sr, CK_VERBOSE /*CK_NORMAL CK_VERBOSE CK_SUBUNIT*/);
- nr_failed = srunner_ntests_failed(sr);
- srunner_ntests_run(sr);
- srunner_free(sr);
+ nr_failed = srunner_ntests_failed(sr);
+ srunner_ntests_run(sr);
+ srunner_free(sr);
+ }
+ else
+ {
+ doEndlessWrite();
+ }
DLT_LOG(gPcltDLTContext, DLT_LOG_INFO, DLT_STRING("End of PCL test"));
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 64ab797..8ce1ead 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -15,5 +15,5 @@ persistence_client_tool_LDADD = $(DEPS_LIBS) \
$(top_builddir)/src/libpersistence_client_library.la
persistence_db_viewer_SOURCES = persistence_db_viewer.c
-persistence_db_viewer_LDADD = $(DEPS_LIBS)
+persistence_db_viewer_LDADD = $(DEPS_LIBS) -lpers_common